Files
step3/tests/dashboard_metric_ui_test.gd
T

80 lines
2.7 KiB
GDScript

extends SceneTree
var failures := 0
func _initialize() -> void:
call_deferred("_run")
func _run() -> void:
var dashboard_service = root.get_node("DashboardService")
var prior_data: Dictionary = dashboard_service.data
dashboard_service.data = _dashboard_data()
var dashboard = load("res://scripts/ui/dashboard_screen.gd").new()
dashboard.size = Vector2(1280, 900)
root.add_child(dashboard)
await process_frame
dashboard._render()
await process_frame
_assert(dashboard.system_list.get_child_count() == 14, "dashboard should render all 14 Step 3 systems")
_assert(dashboard.mastery_rows.size() == 14, "dashboard should render one mastery action row per system")
var first_mastery_row: BoxContainer = dashboard.mastery_rows[0]
_assert(not first_mastery_row.vertical, "desktop mastery rows should remain horizontal")
dashboard.size = Vector2(640, 900)
dashboard._update_responsive()
_assert(first_mastery_row.vertical, "narrow mastery rows should stack to avoid clipping")
_assert(dashboard.rating_toggle.button_pressed, "rating should be the default trend mode")
_assert(dashboard.trend_chart.mode == "rating", "chart should initially render rating history")
dashboard._set_trend_mode("accuracy")
_assert(dashboard.trend_chart.mode == "accuracy", "correct percentage toggle should switch the chart series")
_assert(dashboard.trend_chart.points.size() == 30, "chart should retain all 30 calendar points")
dashboard.queue_free()
dashboard_service.data = prior_data
await process_frame
quit(1 if failures > 0 else 0)
func _dashboard_data() -> Dictionary:
var systems: Array = []
for index in range(14):
systems.append({
"system": "System %02d" % index,
"correct": 1 if index == 0 else 0,
"total": 1 if index == 0 else 0,
"accuracy": 100 if index == 0 else 0,
"masteryScore": 82 if index == 0 else 0,
"masteryState": "strong" if index == 0 else "unseen",
"distinctQuestions": 15 if index == 0 else 0,
"difficulty4PlusSuccessful": 4 if index == 0 else 0,
"pendingReviews": 0,
"refreshDue": false,
"recommendedAction": {"type": "practice", "label": "Challenge this system", "questionCount": 10, "difficultyMin": 4, "difficultyMax": 5}
})
var trend: Array = []
for index in range(30):
trend.append({
"dateUtc": "2026-07-%02dT00:00:00Z" % (index + 1),
"correct": 1 if index % 2 == 0 else 0,
"total": 1 if index % 2 == 0 else 0,
"accuracy": 100 if index % 2 == 0 else 0,
"questionBankRating": 1000 + index
})
return {
"questionBankRating": 1029,
"ratedQuestionCount": 30,
"performanceTrend": trend,
"systems": systems,
"weeklyActivity": [],
"recentActivity": []
}
func _assert(condition: bool, message: String) -> void:
if condition:
return
failures += 1
push_error(message)