TableTower/tests/test_small_ui.gd
RobinFiredrake a527bf545c Batches: Roll several times… on a card's menu
Rolls the card's whole chain a chosen number of times (up to 100) and
shows every result together, with Copy all. Each run asks its questions,
changes values and decks, and goes into Earlier like a normal roll.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 19:07:37 -06:00

136 lines
5.5 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
## Small UI items: backwards ranges warn and block rolling (no auto-swap), the
## inspector's thread lists, replacing a template, the tray chip's bold source
## name, and the export menu's Other formats.
## Run: godot --headless --path . -s res://tests/test_small_ui.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)
await _test_backwards_range()
await _test_thread_lists()
_test_template_replace()
await _test_chip_and_export()
await _test_deck_mode()
await _test_batch()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
func _test_backwards_range() -> void:
var t := main.data.get_table("wilderness")
var e := t.entries[0]
e.range_lo = 40
e.range_hi = 10
var card := main.card_for("wilderness")
card.update_warning()
_check(e.range_lo == 40 and e.range_hi == 10, "the ends aren't swapped")
_check(RollRange.backwards(t) != "" and t.range_problems().contains("runs backwards"), "a warning says the range runs backwards")
_check(card.header_ui.roll_button.disabled, "the die button is greyed out")
main.rolling.start_roll("wilderness")
await _frames()
_check(not str(main.current).contains("wilderness") or main.current.is_empty() or main.current.get("table_id", "") != "wilderness", "it can't be rolled")
e.range_lo = 1
e.range_hi = 30
card.update_warning()
_check(not card.header_ui.roll_button.disabled, "fixing it enables the die again")
func _test_thread_lists() -> void:
main.set_mode(Main.Mode.BUILD)
await _frames()
main.select_card("road")
await _frames(3)
var texts: Array[String] = []
for b in main.inspector.find_children("*", "Button", true, false):
texts.append((b as Button).text)
var heads: Array[String] = []
for l in main.inspector.find_children("*", "Label", true, false):
heads.append((l as Label).text)
_check(heads.any(func(s: String) -> bool: return s.begins_with("THREADS IN (")), "the card inspector lists threads in")
_check(texts.any(func(s: String) -> bool: return s.begins_with("Wilderness Travel · ")), "a thread in names its card and result: %s" % str(texts.slice(0, 6)))
_check(texts.any(func(s: String) -> bool: return s.contains(" → ")), "threads out name where they go")
func _test_template_replace() -> void:
var lib := main.templating.templates()
var tpl := TemplateKit.make(main.data, ["road"], "card", "Road")
var id := lib.add(tpl)
var changed := tpl.duplicate(true)
changed["name"] = "Road, revised"
changed["replace_id"] = id
main.templating.store_template(changed)
_check(lib.get_template(id).get("name") == "Road, revised", "Replace saves over the same template")
_check(not lib.get_template(id).has("replace_id"), "without the replace marker")
var count := lib.list().size()
main.templating.store_template(tpl.duplicate(true))
_check(lib.list().size() == count + 1, "a plain save still adds a new one")
func _test_chip_and_export() -> void:
main.set_mode(Main.Mode.PLAY)
main.rolling.start_roll("road", true)
await _frames(4)
var bold := false
for l in main.tray.find_children("*", "Label", true, false):
var lab := l as Label
if lab.text == "Road Encounter" and lab.get_theme_font("font") == Style.body_bold():
bold = true
_check(bold, "the chip names its card in bold")
var pm := main.top_bar._board_menu.get_popup()
var subs := pm.find_children("*", "PopupMenu", false, false)
_check(subs.size() == 1 and (subs[0] as PopupMenu).item_count == IoMenu.EXPORTS.size() - 1, "rare formats sit under Other formats")
## Deck mode: drawn results fade, an empty deck that waits for Shuffle gives
## its Empty result, and Shuffle all puts everything back.
func _test_deck_mode() -> void:
var t := main.data.get_table("party_roles")
_check(t != null and t.card_mode, "the sample's Party Roles is a deck")
t.deck_empty = "stop"
t.deck_empty_text = "No roles left"
for i in t.entries.size():
main.rolling.start_roll("party_roles", true)
await _frames(2)
var card := main.card_for("party_roles")
var faded := 0
for e in t.entries:
if card.rows.has(e.id) and (card.rows[e.id] as Control).modulate.a < 0.5:
faded += 1
_check(faded == t.entries.size(), "every drawn result is faded (%d of %d)" % [faded, t.entries.size()])
main.rolling.start_roll("party_roles", true)
await _frames(2)
var steps: Array = main.current.get("steps", [])
var last: Dictionary = steps[steps.size() - 1] if not steps.is_empty() else {}
_check(str(last.get("text", "")) == "No roles left" and last.get("deck_empty", false), "an empty deck gives its Empty result: %s" % str(last.get("text", "")))
main.local_state.reshuffle_all()
await _frames()
_check((card.rows[t.entries[0].id] as Control).modulate.a == 1.0, "Shuffle all brings them back")
func _test_batch() -> void:
var texts: Array[String] = await BatchRoll.run(main, "road", 4)
_check(texts.size() == 4 and texts[0].contains("Road Encounter"), "a batch gives every result: %d" % texts.size())
var dialogs := main.find_children("*", "ModalCard", true, false)
_check(not dialogs.is_empty() and (dialogs[dialogs.size() - 1] as ModalCard).title_label.text == "Road Encounter × 4", "and shows them together")
(dialogs[dialogs.size() - 1] as ModalCard).close()
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)