TableTower/tests/test_list_view.gd
RobinFiredrake 0ede1d7cd1 List view: the spread as a list with folders
A left-docked panel (View ▾ → List view, ☰ or right-click the spread)
lists every card, with groups as folders. Rows show threads in and out
(hover for where they lead) and a Roll cell; click selects in Build,
double-click shows the card on the spread, right-click opens its menu.
Drag to reorder (the spread's own order, saved and undoable), onto a
folder to move in, folder into folder to nest. Own search, + Folder,
resizable edge.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-10 18:50:32 -06:00

89 lines
3.2 KiB
GDScript

extends SceneTree
## List view: rows for every card with thread counts and Roll, search, new
## folders, and drag-and-drop moves (reorder, into a folder, folder in folder).
## Run: godot --headless --path . -s res://tests/test_list_view.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_rows()
await _test_moves()
print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures])
quit(1 if _failures else 0)
func _rows(it: TreeItem, out: Array) -> Array:
var c := it.get_first_child()
while c:
out.append(c)
_rows(c, out)
c = c.get_next()
return out
func _find(id: String) -> TreeItem:
for it: TreeItem in _rows(main.list_view.tree.get_root(), []):
if ListTree._meta(it).get("id") == id:
return it
return null
func _test_rows() -> void:
var lv := main.list_view
_check(not lv.visible, "the list starts hidden")
lv.set_shown(true)
await _frames(2)
var rows := _rows(lv.tree.get_root(), [])
_check(rows.size() == main.data.tables.size(), "a row per card (%d)" % rows.size())
var road := _find("road")
_check(road != null and road.get_text(ListTree.COL_THREADS).contains("←1") and road.get_text(ListTree.COL_ROLL) == "Roll", "a row shows its threads and Roll: " + (road.get_text(ListTree.COL_THREADS) if road else ""))
_check(road.get_tooltip_text(ListTree.COL_THREADS).contains("from Wilderness Travel"), "the thread tooltip says where they come from")
lv._search.text = "weapon"
lv._search.text_changed.emit("weapon")
await _frames()
var hits := _rows(lv.tree.get_root(), [])
_check(hits.size() >= 1 and hits.size() < rows.size(), "search narrows the list (%d rows)" % hits.size())
lv._search.text = ""
lv._search.text_changed.emit("")
func _test_moves() -> void:
var lv := main.list_view
var n := main.data.groups.size()
lv.new_folder()
await _frames(2)
_check(main.data.groups.size() == n + 1, "+ Folder adds an empty group")
var g := main.data.groups[main.data.groups.size() - 1]
ListOrder.move(main, {"kind": "card", "id": "towns"}, {"kind": "group", "id": g.id}, 0)
await _frames(2)
_check(main.data.group_of("towns") == g, "dropping a card on a folder moves it in")
var f2 := main.data.add_group("Inner", [])
ListOrder.move(main, {"kind": "group", "id": f2.id}, {"kind": "group", "id": g.id}, 0)
_check(f2.parent == g.id, "a folder dropped on a folder goes inside it")
ListOrder.move(main, {"kind": "group", "id": g.id}, {"kind": "group", "id": f2.id}, 0)
_check(g.parent == "", "a folder can't go inside its own inner folder")
var ids := main.data.tables.map(func(t: RollTable) -> String: return t.id)
ListOrder.move(main, {"kind": "card", "id": ids[3]}, {"kind": "card", "id": ids[0]}, -1)
_check(main.data.tables[0].id == ids[3], "dropping above a card reorders the spread's list")
main.undo_redo.undo()
_check(main.data.tables[0].id == ids[0], "and undo puts it back")
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)