extends SceneTree ## Resizable cards: the grip's corner hit area, a dragged width and list ## height (the list scrolls), saving them, and double-click back to automatic. ## Run: godot --headless --path . -s res://tests/test_card_size.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_resize() print("%s: %d failure(s)" % ["PASS" if _failures == 0 else "FAIL", _failures]) quit(1 if _failures else 0) func _test_resize() -> void: var t := main.data.get_table("road") var card := main.card_for("road") var grip := card.grip _check(grip != null and grip.get_index() == card.get_child_count() - 1, "the grip is the card's last child") _check(grip._has_point(grip.size - Vector2(4, 4)) and not grip._has_point(Vector2(4, 4)), "only the corner takes the mouse") var auto_w := card.size.x card.set_user_size(380.0, 120.0) await _frames() _check(is_equal_approx(card.size.x, 380.0 + card.extra_width()), "the card takes the dragged width") _check(card.list_scroll != null and is_equal_approx(card.list_scroll.size.y, 120.0), "a set height makes the results scroll") _check(card.grip.get_index() == card.get_child_count() - 1, "the grip stays on top after a rebuild") var d := t.to_dict() _check(d.get("w") == 380 and d.get("list_h") == 120, "the size is saved") var back := RollTable.from_dict(d) _check(back.width == 380.0 and back.list_height == 120.0, "and loaded") card.set_user_size(0.0, 0.0) await _frames() _check(is_equal_approx(card.size.x, auto_w) and card.list_scroll == null, "back to automatic") 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)