TableTower/tests/test_top_bar.gd
RobinFiredrake 8f16d337cf UI pass: striped rows, View/Help menus, zoom control, card ⋯ menu, fuller sample
- Striped result rows (parchment tint, on by default, `striped_rows` setting).
- Top bar: View ▾ (Plain words / Rule text, Collapse/Expand all, Striped rows,
  Minimap) and a "− 90% ▾ +" zoom control replace the Plain|Text switch,
  Collapse all, −/Fit/+ and Map. Arrange ▾ folds into Board ▾; Search is an icon.
- Help ▾ and F1 open a Help window; the 17 topics live in help/topics.txt.
- Build cards get a ⋯ menu (settings, template, collapse, delete) instead of
  the gear and footer Delete, sharing Style.overflow_button with group cards.
  Row × buttons show only on hover, focus or selection.
- Sample: Luck value card, Make Camp (pick card) and Search the Ruins
  (1d6 + Luck, with results only a modifier reaches).
- New test suite test_top_bar; Canvas/GraphML round-trip tests compare plain
  tables only, since logic keys are JSON-only.
- DESIGN.md: open items, including the Card Mode UI redesign.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-09 10:36:38 -06:00

166 lines
6.3 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 SceneTree
## 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
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
main = load("res://ui/main.tscn").instantiate()
root.add_child(main)
await _frames(5)
if main._saving_enabled:
print("Saving is enabled; refusing to run.")
quit(2)
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()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
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, "Board ▾ 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 board 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()
pm.id_pressed.emit(TableCardEditing.MENU_DELETE)
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("Card 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("card MODE")
await _frames()
_eq(d.current, "Card 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()
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)
func _eq(got: Variant, want: Variant, what: String) -> void:
_check(got == want, "%s: got %s, want %s" % [what, str(got), str(want)])