extends SceneTree var failures := 0 func _initialize() -> void: call_deferred("_run") func _run() -> void: var Chart = load("res://scripts/ui/dashboard_chart.gd") _test_point_values(Chart) _test_axis_bounds(Chart) await _test_runtime_modes(Chart) quit(1 if failures > 0 else 0) func _test_point_values(Chart: GDScript) -> void: var active := {"accuracy": 75, "total": 4, "questionBankRating": 1042} var inactive := {"accuracy": 0, "total": 0, "questionBankRating": null} _assert(Chart.point_value(active, "accuracy") == 75.0, "accuracy mode should expose active-day accuracy") _assert(Chart.point_value(inactive, "accuracy") == null, "accuracy mode should leave inactive days empty") _assert(Chart.point_value(active, "rating") == 1042.0, "rating mode should expose stored Elo") _assert(Chart.point_value(inactive, "rating") == null, "rating mode should preserve pre-baseline gaps") func _test_axis_bounds(Chart: GDScript) -> void: _assert(Chart.axis_bounds([], "accuracy") == Vector2(0, 100), "accuracy should use a fixed 0-100 axis") var rating_points := [ {"questionBankRating": 1000}, {"questionBankRating": 1020} ] var bounds: Vector2 = Chart.axis_bounds(rating_points, "rating") _assert(bounds.x < 1000 and bounds.y > 1020, "rating bounds should include padded values") _assert(bounds.y - bounds.x >= 100, "rating bounds should preserve a useful minimum span") func _test_runtime_modes(Chart: GDScript) -> void: var chart = Chart.new() chart.size = Vector2(560, 190) root.add_child(chart) await process_frame var series := [ {"dateUtc": "2026-07-23T00:00:00Z", "total": 2, "accuracy": 50, "questionBankRating": null}, {"dateUtc": "2026-07-24T00:00:00Z", "total": 0, "accuracy": 0, "questionBankRating": 1000}, {"dateUtc": "2026-07-25T00:00:00Z", "total": 1, "accuracy": 100, "questionBankRating": 1018} ] chart.set_series(series, "rating", true) _assert(chart.mode == "rating" and chart.points.size() == 3, "chart should accept dated rating series") chart.set_series(series, "accuracy", false) _assert(chart.mode == "accuracy" and not chart.dark, "chart should switch modes and themes") chart.queue_free() await process_frame func _assert(condition: bool, message: String) -> void: if condition: return failures += 1 push_error(message)