TableTower/tests/test_top_bar.gd
RobinFiredrake 1735ed09fd Card threads, Morgan's welcome, and typing/scroll/wheel papercuts
- Card threads: a port on each card's bottom edge. Plain runs after any
  result (once the result's own threads finish); Otherwise runs only when
  no thread of the result ran. Saved as card_threads (LOGIC.md 3g).
- Typing on long cards no longer rebuilds the inspector or the card per
  key (~175 ms -> ~7 ms). Timing tool: tests/perf_typing.gd.
- "+ Add result" scrolls to the new row and focuses it.
- Mouse wheel zooms; Shift+wheel pans sideways; scrolling lists keep it.
- "SPREAD" caption over the switcher; Morgan's first-run welcome.
- docs/MECHANICS.md: checklist of table mechanics for planning.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 10:41:13 -06:00

175 lines
7.6 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

extends TestBase
## The top bar's menus (View ▾, the zoom control, Board ▾ with Pack, Help ▾),
## striped result rows, the Build card's ⋯ menu and the row × that shows on
## hover or selection, and the Help window's topics and links.
## Run: godot --headless --path . -s res://tests/test_top_bar.gd -- --sample
func _init() -> void:
if not await start_main():
return
main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
main.size = Vector2(1440, 900)
_test_bar()
await _test_zoom()
await _test_view_menu()
await _test_stripes()
await _test_card_menu()
await _test_help()
await _test_build_hint()
await _test_welcome()
finish()
func _test_bar() -> void:
var bar := main.top_bar
_check(bar.view_menu != null and bar.help_menu != null and bar.zoom != null, "View ▾, Help ▾ and the zoom control are on the bar")
var texts: Array[String] = []
for n in bar._build_tools.find_children("*", "Button", true, false):
texts.append((n as Button).text)
_check(not texts.has("Arrange ▾"), "Arrange ▾ is gone from the Build tools: %s" % str(texts))
var pm := bar._board_menu.get_popup()
_check(pm.get_item_index(IoMenu.ID_PACK) >= 0, "Spread ▾ has Pack collapsed groups")
_check(main.nav._search_button.text == "", "Search is an icon button")
func _test_zoom() -> void:
var z := main.top_bar.zoom
z.activate(ZoomControl.ID_ACTUAL)
await _frames()
_eq(main.board.zoom, 1.0, "Zoom to 100% sets the zoom")
_eq(z.menu.text, "100% ▾", "the percentage follows")
main.board.set_zoom(0.5)
await _frames()
_eq(z.menu.text, "50% ▾", "and follows zoom changes from elsewhere")
z.activate(ZoomControl.ID_FIT)
_check(main.board.zoom != 0.5, "Fit spread changes the zoom")
func _test_view_menu() -> void:
var v := main.top_bar.view_menu
v.activate(ViewMenu.ID_TEXT)
_eq(main.rules_view(), "text", "Rule text")
v.activate(ViewMenu.ID_PLAIN)
_eq(main.rules_view(), "plain", "Plain words")
var was := main.board.minimap.visible
v.activate(ViewMenu.ID_MINIMAP)
_check(main.board.minimap.visible != was, "Minimap toggles")
v.activate(ViewMenu.ID_MINIMAP)
v.activate(ViewMenu.ID_COLLAPSE)
await _frames()
_eq(v.collapse_label(), "Expand all tables", "after Collapse all the menu offers Expand")
v.activate(ViewMenu.ID_COLLAPSE)
await _frames()
_eq(v.collapse_label(), "Collapse all tables", "and Expand all puts it back")
v.sync()
var pm := v.get_popup()
_check(pm.is_item_checked(pm.get_item_index(ViewMenu.ID_PLAIN)) and pm.is_item_checked(pm.get_item_index(ViewMenu.ID_STRIPES)),
"the menu checks Plain words and Striped rows")
func _row_bg(card: TableCard, index: int) -> Color:
var e := card.table.entries[index]
return ((card.rows[e.id] as PanelContainer).get_theme_stylebox("panel") as StyleBoxFlat).bg_color
func _test_stripes() -> void:
var card := main.card_for("loot")
_check(main.local_state.striped_rows(), "stripes are on by default")
_eq(_row_bg(card, 0), Color(0, 0, 0, 0), "the first row is clear")
_eq(_row_bg(card, 1), Style.STRIPE, "the second row is striped")
_eq(_row_bg(card, 2), Color(0, 0, 0, 0), "the third row is clear")
card.rows_ui.set_row_state(card.table.entries[1].id, TableCardRows.RowState.LIT)
_eq(_row_bg(card, 1), Style.LIT, "a lit row shows lit, not striped")
card.rows_ui.restate(card.table.entries[1].id)
main.top_bar.view_menu.activate(ViewMenu.ID_STRIPES)
_eq(_row_bg(card, 1), Color(0, 0, 0, 0), "turning stripes off clears them")
main.top_bar.view_menu.activate(ViewMenu.ID_STRIPES)
_eq(_row_bg(card, 1), Style.STRIPE, "and back on")
await _frames()
func _test_card_menu() -> void:
main.set_mode(Main.Mode.BUILD)
await _frames()
var card := main.card_for("loot")
var menus := card.find_children("*", "MenuButton", true, false)
_check(menus.size() == 1 and (menus[0] as MenuButton).tooltip_text == "Table actions", "the card has one ⋯ menu")
var texts: Array[String] = []
for n in card.find_children("*", "Button", true, false):
texts.append((n as Button).text)
_check(not texts.has("⚙") and not texts.has("Delete"), "no gear and no footer Delete: %s" % str(texts))
var eid := card.table.entries[2].id
var del: Button = card.rows_ui.parts[eid]["delete"]
_eq(del.modulate.a, 0.0, "a row's × is hidden until hovered")
card.select_entry(eid)
_eq(del.modulate.a, 1.0, "the selected row shows its ×")
card.select_entry("")
_eq(del.modulate.a, 0.0, "and hides it again when deselected")
var pm := (menus[0] as MenuButton).get_popup()
_check(Actions.press(pm, "Delete table"), "⋯ has Delete table")
await _frames()
_check(main.data.get_table("loot") == null, "⋯ → Delete table deletes it")
main.undo_redo.undo()
await _frames()
_check(main.data.get_table("loot") != null, "and undo brings it back")
main.set_mode(Main.Mode.PLAY)
await _frames()
func _test_help() -> void:
var titles := HelpDialog.titles()
_check(titles.size() >= 10 and titles.has("Deck mode") and titles.has("Roll modifiers"), "help has its topics: %s" % str(titles))
var src := FileAccess.get_file_as_string(HelpDialog.PATH)
var re := RegEx.create_from_string("\\[topic\\](.+?)\\[/topic\\]")
for m in re.search_all(src):
_check(titles.has(m.get_string(1)), "the link to “%s” has a topic" % m.get_string(1))
for t: Dictionary in HelpDialog.topics():
_check(str(t["body"]).length() > 80, "“%s” has text" % t["title"])
_check(HelpDialog._inline("`[[Loot]]`").contains("[lb][lb]Loot[rb][rb]"), "code spans keep their brackets")
var d := main.top_bar.help_menu.open("deck MODE")
await _frames()
_eq(d.current, "Deck mode", "Help opens at the asked topic, any case")
d._on_meta("topic:Roll modifiers")
_eq(d.current, "Roll modifiers", "a topic link switches topics")
_check(d.text.get_parsed_text().contains("Luck"), "and shows its text")
d.close()
await _frames()
## Play shows that Build mode exists: a greyed "+ Card" that explains and
## offers to switch, and a greyed "New card" in the ☰ menu.
func _test_build_hint() -> void:
main.set_mode(Main.Mode.PLAY)
var bar := main.top_bar
_check(bar.play_add_button.visible and not bar._build_tools.visible, "Play shows the greyed + Card, not the Build tools")
var names := Actions.background(main, Vector2.ZERO).map(func(a: Dictionary) -> String: return str(a.get("text", "")))
var item: Dictionary = Actions.background(main, Vector2.ZERO)[names.find("New card")] if names.has("New card") else {}
_check(item.get("disabled", false), "the ☰ menu shows New card greyed in Play")
bar.play_add_button.pressed.emit()
_eq(bar._toast_label.text, BuildModeHint.MESSAGE, "clicking it explains Build mode")
_check(bar._toast_undo.visible and bar._toast_undo.text == "Switch to Build", "the toast offers Switch to Build")
bar._toast_undo.pressed.emit()
await _frames()
_eq(main.mode, Main.Mode.BUILD, "Switch to Build switches")
_check(not bar.play_add_button.visible, "Build hides the greyed button")
main.toast("Saved")
_eq(bar._toast_undo.text, "Undo", "a later toast's button is Undo again")
## Morgan's welcome: not in a session that doesn't save; open() shows it with
## its three ways to start, and Explore the demo closes it.
func _test_welcome() -> void:
WelcomeDialog.maybe_show(main)
await _frames()
_check(main.find_children("*", "ModalCard", true, false).is_empty(), "no welcome in a session that doesn't save")
var dialog := WelcomeDialog.open(main)
await _frames()
var labels: Array = dialog.footer.get_children().map(func(b: Node) -> String: return (b as Button).text)
_eq(labels, ["Import a spread…", "Start a blank spread", "Explore the demo"], "the welcome's buttons")
(dialog.footer.get_child(2) as Button).pressed.emit()
await _frames(20)
_check(not is_instance_valid(dialog) or dialog.is_queued_for_deletion(), "Explore the demo closes it")