TableTower/tests/test_inspector_list.gd
RobinFiredrake cc7cd0f660 Lore Index: the Book is renamed and is a tab beside the inspector
UI words only: Book -> Lore Index, Page -> Lore Entry (code keeps book and
BookPage). In Build the Inspector and the Lore Index share the dock as two
tabs (SideTabs); selecting on the spread goes back to the Inspector. In
Play the Lore Index opens alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-15 12:46:05 -06:00

106 lines
4.4 KiB
GDScript

extends TestBase
## The inspector's card page as one list (InspectorList): a section for the
## card and one per result; selecting on the spread opens only that section;
## sections opened by hand stay open and edits go to the section clicked in;
## a result's weight, range and position (InspectorRange).
## Run: godot --headless --path . -s res://tests/test_inspector_list.gd -- --sample
var insp: Inspector
func _init() -> void:
if not await start_main():
return
main.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
main.size = Vector2(1440, 900)
main.set_mode(Main.Mode.BUILD)
insp = main.inspector
main.data.load_dict({"format_version": 2, "id": "list-test", "name": "List test", "tables": [
{"id": "work", "name": "Workday Job", "x": 40, "y": 40, "dice": "1d100", "ranged": true,
"range_edit": "weights", "entries": [
{"id": "a", "text": "Result 1", "range": [1, 5], "weight": 5},
{"id": "b", "text": "Bob", "range": [6, 80], "weight": 75},
{"id": "c", "text": "Joe", "range": [81, 87], "weight": 7},
{"id": "d", "text": "Kevin", "range": [88, 100], "weight": 13}]}]})
main._rebuild_cards()
main.clear_inspector()
await _frames(4)
await _test_sections()
await _test_open_by_hand()
await _test_position_and_weight()
await _test_lore_tab()
finish()
func _t() -> RollTable:
return main.data.get_table("work")
func _open_keys() -> Array:
var out: Array = []
for k: String in insp.section_parts:
if insp.section_parts[k].get("built", false):
out.append(k)
return out
func _test_sections() -> void:
main.select_result("work", "b")
await _frames()
_eq(insp.section_parts.keys(), ["card", "a", "b", "c", "d"], "a section for the card and each result")
_eq(_open_keys(), ["b"], "selecting a result opens only its section")
_eq((insp.fields["text"] as LineEdit).text, "Bob", "the open section edits that result")
main.select_card("work")
await _frames()
_eq(_open_keys(), ["card"], "selecting the card opens only the card section")
_check(insp.fields.has("name"), "the card's fields are active")
var card := main.card_for("work")
var panel := card.get_theme_stylebox("panel") as StyleBoxFlat
_check(card._inspected and panel.border_color == Style.SELECTED, "the inspected card glows in the Selected colour")
_check(card.find_children("*", "CardMoveHandle", true, false).size() == 1, "Build shows a move handle on the header")
func _test_open_by_hand() -> void:
main.select_result("work", "a")
await _frames()
InspectorList.toggle(insp, "c")
await _frames()
_eq(_open_keys(), ["a", "c"], "a section opened by hand joins the open one")
_eq(str(insp.selection.get("eid")), "c", "the section just opened is active")
InspectorList.activate(insp, "a")
insp.set_entry_text("First")
_eq(_t().find_entry("a").text, "First", "edits go to the section made active")
_eq(_t().find_entry("c").text, "Joe", "the other open section is untouched")
await _frames()
_eq(_open_keys(), ["a", "c"], "an edit keeps both sections open")
main.select_result("work", "d")
await _frames()
_eq(_open_keys(), ["d"], "a click on the spread closes the rest again")
func _test_position_and_weight() -> void:
var t := _t()
InspectorRange.set_weight(insp, t, t.find_entry("a"), 10)
_eq(Vector2i(t.find_entry("b").range_lo, t.find_entry("b").range_hi), Vector2i(11, 85), "a weight edit moves the ranges after it")
InspectorRange.move_to(insp, t, t.find_entry("d"), 0)
_eq(t.entries[0].id, "d", "Position moves the result")
_eq(t.entries[0].range_lo, 1, "Weights lay the ranges out again after a move")
RangeWeights.set_mode(t, RangeWeights.RANGES)
InspectorRange.set_range(insp, t, t.find_entry("d"), 120, 125)
_eq(t.entries.back().id, "d", "auto-sort puts an edited range in roll order")
## In Build the Lore Index is a tab beside the inspector; in Play it opens alone.
func _test_lore_tab() -> void:
SideTabs.show_tab(main, SideTabs.LORE)
_check(main.book.visible and not insp.visible, "Build: the Lore Index tab replaces the inspector")
_check(main.book._tabs.visible, "Build: the Lore Index shows the tab row")
main.select_result("work", "a")
await _frames()
_check(insp.visible and not main.book.visible, "selecting on the spread goes back to the Inspector tab")
main.set_mode(Main.Mode.PLAY)
main.book.toggle()
_check(main.book.visible and not insp.visible and not main.book._tabs.visible, "Play: the Lore Index opens alone, with no tabs")
main.book.toggle()
main.set_mode(Main.Mode.BUILD)
_check(insp.visible, "back in Build the inspector shows")