TableTower/tests/test_group_marks.gd
RobinFiredrake d41a6e40aa Tests: 15 s budget, shared Godot workers; a freed Main cancels its roll
tools/run_tests.sh stops every run at 15 s and lists what was not run.
Suites are nodes run by tests/run_suites.gd, several per Godot process;
TestBase no longer compiles the app (AppTestBase does). Audit: fewer
repeats and less setup; 51 suites in about 12 s (was 45 s).

Fix a crash when a roll was still animating as its Main was freed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 16:19:30 -06:00

58 lines
2.9 KiB
GDScript

extends AppTestBase
## Group marks: a member card's top-right corner shows its group's colour (its
## own, else the theme's GROUP); a card that only lies inside the frame has
## none. The colour is saved and undoable.
## Run: tools/run_tests.sh group_marks
func run() -> void:
if not await start_main(false):
return
main.data.load_dict({"format_version": 2, "id": "marks-test", "name": "Marks", "tables": [
{"id": "a", "name": "Alpha", "x": 40, "y": 60, "entries": [{"id": "e1", "text": "One"}]},
{"id": "b", "name": "Bravo", "x": 400, "y": 60, "entries": [{"id": "e1", "text": "Two"}]},
{"id": "c", "name": "Charlie", "x": 40, "y": 500, "entries": [{"id": "e1", "text": "Three"}]},
]})
main._rebuild_cards()
main.set_mode(Main.Mode.BUILD)
await _frames()
var g := main.data.add_group("G", ["a", "b"])
main.mark_dirty()
await _frames()
var mark := main.card_for("a").group_mark
_check(mark.visible and mark._color == GroupMark.DEFAULT_COLOR, "a member shows the default group mark (the same in every theme)")
_check(not main.card_for("c").group_mark.visible, "a card outside the group has no mark")
Actions.set_group_colour(main, g, "#3c8dd8")
await _frames()
_check(main.card_for("b").group_mark._color == Color("#3c8dd8"), "colouring the group recolours its members' marks")
_eq(TableGroup.from_dict(g.to_dict()).color, "#3c8dd8", "the group colour is saved")
main.undo_redo.undo()
await _frames()
_check(main.card_for("b").group_mark._color == GroupMark.DEFAULT_COLOR, "undo puts the default colour back")
# Lying inside the frame isn't membership: no mark until it joins.
var c := main.card_for("c")
c.position = main.data.groups[0].position + Vector2(20, 40)
await _frames()
_check(not c.group_mark.visible, "a card that only overlaps the frame stays unmarked")
main.data.add_to_group("c", main.data.groups[0].id)
main.mark_dirty()
await _frames()
_check(main.card_for("c").group_mark.visible, "joining the group marks it")
main.data.remove_from_group("c")
main.mark_dirty()
await _frames()
_check(not main.card_for("c").group_mark.visible, "leaving the group clears the mark")
_check(GroupMark.outline_for(Color.WHITE) != GroupMark.outline_for(Color.BLACK), "the tab's outline stands out from light and dark colours")
main.toggle_group(g.id)
await _frames()
var marks: Array = main.group_node(g.id).find_children("*", "GroupMark", true, false)
_check(marks.size() == 1 and (marks[0] as GroupMark).visible and (marks[0] as GroupMark)._color == GroupMark.color_of(g), "a collapsed group shows its own corner tab")
var menu := Actions.group(main, g)
var colour_menu: Dictionary = {}
for item: Dictionary in menu:
if str(item.get("text", "")) == "Colour":
colour_menu = item
_check((colour_menu.get("sub", []) as Array).any(func(item: Dictionary) -> bool: return str(item["text"]).ends_with("Any colour…")), "the group Colour menu ends with Any colour…")
finish()