palette.gd / theme_keys.gd already declare `class_name`, so `const Palette =
preload(...)` in every consumer shadowed the global class and emitted 4
editor errors ("has the same name as a global class"). Reference the global
class_names directly. Editor reload now clean; suite 125/125; runtime probe
still builds all 75 showcase nodes with the theme applied.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
51 lines
1.7 KiB
GDScript
51 lines
1.7 KiB
GDScript
# client/tests/unit/test_theme_resource.gd
|
|
extends "res://addons/gut/test.gd"
|
|
|
|
const Builder = preload("res://scripts/theme/build_game_theme.gd")
|
|
const THEME_PATH := "res://assets/theme/game_theme.tres"
|
|
|
|
|
|
func test_theme_loads():
|
|
assert_true(FileAccess.file_exists(THEME_PATH), "theme not built — run build_game_theme.gd")
|
|
var t = load(THEME_PATH)
|
|
assert_true(t is Theme)
|
|
|
|
|
|
func test_every_variation_resolves():
|
|
var t: Theme = load(THEME_PATH)
|
|
for key in ThemeKeys.ALL:
|
|
var base: String = ThemeKeys.ALL[key]
|
|
assert_eq(t.get_type_variation_base(key), StringName(base),
|
|
"variation %s missing or wrong base" % key)
|
|
|
|
|
|
func test_cta_has_normal_stylebox():
|
|
var t: Theme = load(THEME_PATH)
|
|
assert_true(t.has_stylebox(&"normal", ThemeKeys.PRIMARY_CTA))
|
|
|
|
|
|
func test_default_font_is_set():
|
|
var t: Theme = load(THEME_PATH)
|
|
assert_true(t.default_font is FontFile)
|
|
|
|
|
|
func test_committed_tres_matches_builder():
|
|
# Catches "palette/builder changed but nobody regenerated game_theme.tres."
|
|
# Preloading the builder script and calling its static build_theme() does
|
|
# NOT run _init() (that only fires on .new()), so this is side-effect-free.
|
|
var fresh: Theme = Builder.build_theme()
|
|
var committed: Theme = load(THEME_PATH)
|
|
|
|
var checks := [
|
|
[ThemeKeys.PRIMARY_CTA, &"normal"],
|
|
[ThemeKeys.PARCHMENT_CARD, &"panel"],
|
|
[ThemeKeys.DARK_PANEL, &"panel"],
|
|
]
|
|
for pair in checks:
|
|
var variation: StringName = pair[0]
|
|
var state: StringName = pair[1]
|
|
var fresh_box: StyleBoxFlat = fresh.get_stylebox(state, variation)
|
|
var committed_box: StyleBoxFlat = committed.get_stylebox(state, variation)
|
|
assert_eq(fresh_box.bg_color, committed_box.bg_color,
|
|
"stale game_theme.tres — %s/%s bg_color drifted from the builder; re-run build_game_theme.gd" % [variation, state])
|