TableTower/tests/test_mobile.gd

111 lines
4.8 KiB
GDScript3
Raw Permalink Normal View History

extends AppTestBase
## The phone layout (List fills the screen, Spread/List swap, slim bar and
## tray, View/Help/Play-Build in ☰) and touch gestures (pinch zoom, a long
## press timing out into a right-click), and sheets on a phone (the stacked
## view in phone order, the Stacked | Canvas switch, Build's "+ Field").
## Run: tools/run_tests.sh mobile
func run() -> void:
if not await start_main():
return
await _test_layout()
await _test_touch()
await _test_sheet()
finish()
func _test_layout() -> void:
main.mobile = MobileLayout.new(main)
main.mobile.apply()
await _frames()
_check(main.list_view.is_visible_in_tree() and not main.board.visible, "the list fills the screen")
_check(not main.top_bar.view_menu.visible and not main.top_bar.help_menu.visible and not main.tray.side_panel.visible, "the bar and tray slim down")
main.mobile.swap.pressed.emit()
_check(main.board.visible and not main.list_view.is_visible_in_tree() and main.mobile.swap.text == "List", "Spread/List swaps to the spread")
main.mobile.add_button.pressed.emit()
_check(main.left_dock.palette.is_visible_in_tree() and not main.board.visible, "+ opens the card palette full screen")
main.left_dock.show_tab(LeftDock.LIST)
main.mobile.show_list(false)
main.mobile.swap.pressed.emit()
var texts: Array = Actions.background(main, Vector2.ZERO).map(func(a: Dictionary) -> String: return str(a.get("text", "")))
_check(texts.has("Switch to Build") and texts.has("Help…"), "☰ carries Play/Build and Help: %s" % str(texts))
main.mobile.show_list(false)
func _test_touch() -> void:
var touch: TouchInput = null
for c in main.get_children():
if c is TouchInput:
touch = c
_check(touch != null, "touch gestures are on")
var z := main.board.zoom
touch._input(_tap(0, Vector2(100, 300), true))
touch._input(_tap(1, Vector2(200, 300), true))
var d := InputEventScreenDrag.new()
d.index = 1
d.position = Vector2(300, 300)
touch._input(d)
_check(main.board.zoom > z * 1.5, "two fingers spreading apart zoom in (%.2f → %.2f)" % [z, main.board.zoom])
touch._input(_tap(1, Vector2(300, 300), false))
touch._input(_tap(0, Vector2(100, 300), false))
touch._input(_tap(0, Vector2(120, 320), true))
touch._process(0.3)
_check(touch._hold_t > 0.0, "a held finger counts toward a long press")
touch._process(0.3)
_check(touch._hold_t < 0.0, "after half a second it fires (as a right-click)")
touch._input(_tap(0, Vector2(120, 320), false))
func _test_sheet() -> void:
var a := SheetBox.new("a")
var b := SheetBox.new("b")
var c := SheetBox.new("c")
var d := SheetBox.new("d")
a.set_rect(Rect2(200, 0, 10, 10))
b.set_rect(Rect2(0, 0, 10, 10))
c.set_rect(Rect2(0, 50, 10, 10))
d.set_rect(Rect2(0, 90, 10, 10))
d.phone_order = 1
var ids: Array = SheetStackView.order_of([a, b, c, d]).map(func(box: SheetBox) -> String: return box.id)
_eq(ids, ["d", "b", "a", "c"], "phone order: numbers first, then top-down, left-right")
main.screens.show(MainScreens.SHEETS)
var ed := main.screens.sheets.editor
main.screens.sheets.open_doc(SheetDemo.create())
await _frames()
var phone := ed.phone
_check(phone != null and phone.stack.visible and not ed.canvas.visible and not ed.palette_dock.visible, "Play on a phone shows the stacked view")
_eq(phone.stack.views.size(), (ed.current_tab()["boxes"] as Array).size(), "every box of the tab is in the stack")
var number: SheetBox = null
for box: SheetBox in ed.current_tab()["boxes"]:
if box.kind == SheetKinds.NUMBER and number == null:
number = box
var plus: Button = phone.stack.views[number.id].find_child("Plus", true, false)
_check(plus.custom_minimum_size.y >= SheetFieldViews.TOUCH, "step buttons are touch size")
_check(not SheetFieldViews.touch, "the touch flag is off again")
var before: Variant = number.value
plus.pressed.emit()
_eq(number.value, int(before) + 1, "+ in the stack changes the value")
phone.undo_button.pressed.emit()
_eq(ed.doc.find_box(number.id).value, before, "Undo in the bottom bar takes it back")
phone.canvas_button.pressed.emit()
_check(ed.canvas.visible and not phone.stack.visible, "Canvas shows the real layout")
ed.set_mode(Main.Mode.BUILD)
_check(ed.canvas.visible and not phone.canvas_button.visible and phone.add_button.visible, "Build uses the canvas, with + Field")
phone.add_button.pressed.emit()
_check(ed.palette_dock.visible and not ed.canvas.visible, "+ Field opens the palette full screen")
ed.palette._add(Vector2.INF, SheetKinds.NUMBER)
_check(ed.canvas.visible and not ed.palette_dock.visible and ed.inspector.visible, "a pick goes back to the canvas, inspector below")
ed.set_mode(Main.Mode.PLAY)
phone.stacked_button.pressed.emit()
main.screens.show(MainScreens.SPREAD)
func _tap(i: int, at: Vector2, down: bool) -> InputEventScreenTouch:
var t := InputEventScreenTouch.new()
t.index = i
t.position = at
t.pressed = down
return t