Files
MusicPlayer/tests/integration/test_character_select_popup.gd
SansanandClaude Opus 5.5 70e970b24c
Build / test (push) Successful in 1m30s
Build / build (push) Successful in 1m17s
Make the buttons consistent and rework the player list
Buttons get 12 px of side padding. The top bar buttons, the quiz toolbar and
Show answer/Next are laid out in rows with 12 px gaps and are all 36 px tall,
and the ±1 buttons use a compact StepButton style. "Randomize new track" is now
"Next song".

Player rows show the name and the score apart, alternate like the other lists
and highlight the character under the mouse. The name field is a LineEdit with
a 10-letter limit; blank and duplicate names are refused, and a full list says
"Up to 7 players". Remove buttons update when editing is switched instead of
every frame, and the spacer panels are gone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-11 21:35:24 +02:00

117 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:
await super()
_picked.clear()
_popup = _quiz.get_node("CharacterSelectPopup")
_popup.character_selected.connect(
func(texture: Texture2D, _name: String) -> 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()