90 lines
3.4 KiB
GDScript
90 lines
3.4 KiB
GDScript
extends SceneTree
|
|
## Headless smoke test for DiscoveryUI.
|
|
|
|
func _initialize() -> void:
|
|
_run()
|
|
|
|
func _run() -> void:
|
|
print("[SMOKE] Starting DiscoveryUI smoke test...")
|
|
await process_frame
|
|
|
|
var scene = load("res://scenes/discovery_ui.tscn")
|
|
if not scene:
|
|
printerr("[FAIL] Could not load res://scenes/discovery_ui.tscn")
|
|
quit(1)
|
|
return
|
|
|
|
var ui: DiscoveryUI = scene.instantiate()
|
|
root.add_child(ui)
|
|
await process_frame
|
|
|
|
# 1. Verify node references
|
|
assert(ui.search_edit != null, "search_edit is null")
|
|
assert(ui.category_option != null, "category_option is null")
|
|
assert(ui.sort_option != null, "sort_option is null")
|
|
assert(ui.filter_button != null, "filter_button is null")
|
|
assert(ui.worlds_container != null, "worlds_container is null")
|
|
assert(ui.prev_button != null, "prev_button is null")
|
|
assert(ui.next_button != null, "next_button is null")
|
|
assert(ui.page_label != null, "page_label is null")
|
|
print("[PASS] Node references verified")
|
|
|
|
# 2. Verify sort options
|
|
assert(ui.sort_option.item_count == 3, "sort_option should have 3 items")
|
|
assert(ui.sort_option.get_item_text(0) == "Newest", "sort 0 should be Newest")
|
|
assert(ui.sort_option.get_item_text(1) == "Most Played", "sort 1 should be Most Played")
|
|
assert(ui.sort_option.get_item_text(2) == "Trending", "sort 2 should be Trending")
|
|
print("[PASS] Sort options verified")
|
|
|
|
# 3. Verify category dropdown initial state
|
|
assert(ui.category_option.item_count >= 1, "category_option should have at least All Categories")
|
|
assert(ui.category_option.get_item_text(0) == "All Categories", "category 0 should be All Categories")
|
|
print("[PASS] Category dropdown verified")
|
|
|
|
# 4. Test rendering of WorldSummary cards
|
|
var mock_w := DiscoveryApiClient.WorldSummary.new()
|
|
mock_w.id = 101
|
|
mock_w.name = "Cyber Nexus"
|
|
mock_w.category = "Action"
|
|
mock_w.tags = ["cyberpunk", "pvp"]
|
|
mock_w.play_count = 256
|
|
mock_w.description = "A futuristic arena"
|
|
mock_w.owner_username = "neon_builder"
|
|
|
|
var mock_worlds: Array[DiscoveryApiClient.WorldSummary] = [mock_w]
|
|
ui._render_worlds(mock_worlds)
|
|
assert(ui.worlds_container.get_child_count() == 1, "Should render 1 card")
|
|
assert(ui.empty_label.visible == false, "empty_label should be hidden when items present")
|
|
print("[PASS] World card rendering verified")
|
|
|
|
# 5. Test empty state
|
|
var empty_list: Array[DiscoveryApiClient.WorldSummary] = []
|
|
ui._render_worlds(empty_list)
|
|
assert(ui.worlds_container.get_child_count() == 0, "Container should have 0 children")
|
|
assert(ui.empty_label.visible == true, "empty_label should be visible when empty")
|
|
print("[PASS] Empty state verified")
|
|
|
|
# 6. Test pagination logic
|
|
ui._total_count = 25
|
|
ui._page_size = 10
|
|
ui._current_page = 0
|
|
ui._update_pagination()
|
|
assert(ui.prev_button.disabled == true, "Page 0 prev_button should be disabled")
|
|
assert(ui.next_button.disabled == false, "Page 0 next_button should be enabled")
|
|
assert(ui.page_label.text.contains("Page 1 of 3"), "Page 1 of 3 mismatch: %s" % ui.page_label.text)
|
|
|
|
ui._current_page = 1
|
|
ui._update_pagination()
|
|
assert(ui.prev_button.disabled == false, "Page 1 prev_button should be enabled")
|
|
assert(ui.next_button.disabled == false, "Page 1 next_button should be enabled")
|
|
|
|
ui._current_page = 2
|
|
ui._update_pagination()
|
|
assert(ui.prev_button.disabled == false, "Page 2 prev_button should be enabled")
|
|
assert(ui.next_button.disabled == true, "Page 2 next_button should be disabled")
|
|
print("[PASS] Pagination logic verified")
|
|
|
|
ui.queue_free()
|
|
print("[SMOKE] DiscoveryUI smoke test PASSED")
|
|
quit(0)
|