Files
MusicPlayer/tests/integration/test_character_select_popup.gd
T
Sansan 8d21b0617d
Build / test (push) Successful in 41s
Build / build (push) Successful in 1m13s
Fix and tidy the Character select, Shortcuts, Log and QR popups
Character select
- A card only picks its character when it is clicked. Before, every card
  watched every click, so clicking below the panel could pick a card
  scrolled out of view there.
- Six columns of fixed-size cards that scroll for any number of
  characters, with a gap between the cards and the scrollbar.
- Pictures are read as PNG, JPG or WebP by their first bytes, so JPGs no
  longer print an error. Names are split into words ("Paper Mario") and
  the card under the mouse is highlighted.

Shortcuts
- Alt+Z restarts the song; it was listed as "Reset".
- Grouped by what the keys do, in sentence case, and the panel fits the
  list. A test checks that every button shortcut is listed.

Log
- Scrolls to the newest row, alternates row colours and says "Nothing
  has happened yet" when empty.

QR
- A title, and the code is set up in one place.
2026-10-07 15:24:43 +02:00

116 lines
4.2 KiB
GDScript

extends MainWindowTestSuite
## The character select popup: picking a character by clicking its card, scrolling when
## there are more characters than fit, and reading the pictures and names.
## More characters than fit without scrolling. The number changes on the server over
## time, so nothing here depends on it.
const CHARACTER_COUNT: int = 27
var _popup: CharacterSelectPopup
var _crono: PlayerObject
var _picked: Array[Texture2D] = []
func _before_window_starts() -> void:
var names: Array[String] = []
var png: PackedByteArray = _picture().save_png_to_buffer()
for i: int in CHARACTER_COUNT:
names.append("Character%d.png" % i)
_server.respond_bytes("/character?name=" + names[i].uri_encode(), png)
_server.respond_json("/character/list", names)
func before_test() -> void:
super()
_picked.clear()
_popup = _quiz.get_node("CharacterSelectPopup")
_popup.character_selected.connect(func(texture: Texture2D) -> void: _picked.append(texture))
# Opened from the player's row, like clicking the player's picture
_crono = _add_player("Crono")
_player_row(_crono).change_character()
await _runner.simulate_frames(2)
func _picture() -> Image:
var image: Image = Image.create(20, 10, false, Image.FORMAT_RGB8)
image.fill(Color.ORANGE)
return image
func _cards() -> Array[Node]:
return _popup.character_grid.get_children()
func test_one_card_per_character_in_six_columns() -> void:
assert_int(_cards().size()).is_equal(CHARACTER_COUNT)
assert_int(_popup.character_grid.columns).is_equal(6)
assert_object((_cards()[0] as CharacterCard).character_image.texture).is_not_null()
func test_more_characters_than_fit_can_be_scrolled() -> void:
var scroll: ScrollContainer = _popup.find_child("ScrollContainer")
assert_float(_popup.character_grid.size.y).is_greater(scroll.size.y)
assert_bool(scroll.get_v_scroll_bar().visible).is_true()
func test_cards_keep_away_from_the_scrollbar() -> void:
var scroll: ScrollContainer = _popup.find_child("ScrollContainer")
var scrollbar: Rect2 = scroll.get_v_scroll_bar().get_global_rect()
var last_column: Rect2 = (_cards()[5] as Control).get_global_rect()
assert_float(scrollbar.position.x - last_column.end.x).is_greater_equal(20.0)
func test_clicking_a_card_picks_that_character() -> void:
var card: CharacterCard = _cards()[2]
await _click_at(card.get_global_rect().get_center())
assert_array(_picked).contains_exactly([card.character_image.texture])
assert_object(_crono.character).is_same(card.character_image.texture)
assert_bool(_popup.visible).is_false()
func test_click_where_a_scrolled_away_card_is_picks_nothing() -> void:
# The last row is below the visible part of the list, under the bottom of the panel
var hidden_card: CharacterCard = _cards().back()
var where: Vector2 = hidden_card.get_global_rect().get_center()
assert_bool(_popup.panel.get_global_rect().has_point(where)).is_false()
await _click_at(where)
assert_array(_picked).is_empty()
assert_bool(_popup.visible).is_false()
func test_hovering_a_card_highlights_it() -> void:
var card: CharacterCard = _cards()[0]
card.mouse_entered.emit()
assert_str(String(card.theme_type_variation)).is_equal("CharacterCardHover")
card.mouse_exited.emit()
assert_str(String(card.theme_type_variation)).is_equal("CharacterCard")
func test_names_are_shown_without_extension_and_split_into_words() -> void:
assert_str(CharacterCard.display_name("PaperMario.png")).is_equal("Paper Mario")
assert_str(CharacterCard.display_name("Mizuti.jpg")).is_equal("Mizuti")
assert_str(CharacterCard.display_name("Kingdom Hearts.png")).is_equal("Kingdom Hearts")
assert_str((_cards()[3] as CharacterCard).character_name_label.text).is_equal("Character3")
func test_png_jpg_and_webp_pictures_are_read() -> void:
var picture: Image = _picture()
for bytes: PackedByteArray in [picture.save_png_to_buffer(),
picture.save_jpg_to_buffer(), picture.save_webp_to_buffer()]:
var image: Image = CharacterCard.image_from_bytes(bytes)
assert_object(image).is_not_null()
assert_vector(Vector2(image.get_size())).is_equal(Vector2(20, 10))
func test_something_that_is_not_a_picture_gives_null() -> void:
assert_object(CharacterCard.image_from_bytes("not a picture".to_utf8_buffer())).is_null()
assert_object(CharacterCard.image_from_bytes(PackedByteArray())).is_null()