extends SceneTree ## Theme sets: applying built-ins sets Style tokens and fills, saving and ## deleting a user set, and the Theme dialog building its editors. ## Run: godot --headless --path . -s res://tests/test_theme.gd -- --sample var _failures := 0 var main: Main func _init() -> void: if not OS.get_cmdline_user_args().has("--sample"): print("Run with -- --sample so the test can't touch saved data.") quit(2) return ThemeStore.DIR = OS.get_temp_dir().path_join("tt_theme_test_%d/" % OS.get_process_id()) main = load("res://ui/main.tscn").instantiate() root.add_child(main) await _frames(5) _test_apply() _test_save_delete() await _test_dialog() print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) func _test_apply() -> void: _check(ThemeStore.current.get("id") == "tarot", "Tarot is the default set") _check(Style.BG == Color("#2c0744"), "Tarot sets the background colour") _check(Style.fill_texture(Style.BG_FILL) != null, "Tarot's background is a gradient") _check(BoardView.pattern_texture("stars") != null and BoardView.pattern_texture("none") == null, "patterns build") ThemeStore.apply(BuiltinThemes.FELT) _check(Style.BG == Color("#1f4a39"), "Felt falls back to the original colours") _check(Style.PATTERN == "dots", "Felt uses dots") _check(Style.panel_box() is StyleBoxFlat, "a solid panel fill is a flat box") ThemeStore.apply(BuiltinThemes.TAROT) _check(Style.panel_box() is StyleBoxTexture, "a gradient panel fill is a texture box") var cols := ThemeStore.resolved_colors(BuiltinThemes.FELT) _check(cols.size() == ThemeStore.TOKENS.size(), "resolved colours cover every token") func _test_save_delete() -> void: var t := BuiltinThemes.TAROT.duplicate(true) t["name"] = "Night Sky" var id := ThemeStore.save(t) _check(id != "tarot", "saving a built-in makes a new id: " + id) _check(ThemeStore.find(id).get("name") == "Night Sky", "the saved set is found") _check(ThemeStore.all().size() == BuiltinThemes.all().size() + 1, "the saved set is listed") ThemeStore.delete("tarot") _check(ThemeStore.find("tarot").get("builtin", false), "built-ins can't be deleted") ThemeStore.delete(id) _check(ThemeStore.all().size() == BuiltinThemes.all().size(), "the user set is deleted") func _test_dialog() -> void: var d := ThemeDialog.new(main) main.add_child(d) await _frames() _check(d._content.find_children("*", "FillEditor", true, false).size() == 2, "background and panel fill editors") var basic := d._content.find_children("*", "ColorPickerButton", true, false).size() d._more = true d._rebuild() await _frames() var all := d._content.find_children("*", "ColorPickerButton", true, false).size() _check(all > basic, "More colours shows more swatches (%d > %d)" % [all, basic]) var fe := d._content.find_children("*", "FillEditor", true, false)[0] as FillEditor fe._set_kind(1) _check((fe.fill["colors"] as Array).size() >= 2 and d._dirty, "a gradient gets two colours and marks the set changed") d.close() await _frames() func _frames(n: int = 2) -> void: for i in n: await process_frame func _check(ok: bool, what: String) -> void: if not ok: _failures += 1 print("FAIL ", what)