Files
MusicPlayer/tests/integration/test_character_select_popup.gd
T
Sansan e4352a9f34
Build / test (push) Successful in 1m25s
Build / build (push) Successful in 1m12s
Save the quiz and continue it after a restart; load characters from a folder
The quiz is saved to current_quiz.json in the config folder after every
change, and the game goes on where it was when it starts again: the
players with their points and characters, every song with who got a point
for it and whether it was played, answered or is playing, and the songs
downloaded ahead with their files. The song that was playing is ready to
play again. Songs whose files are gone are downloaded again.

On a server, the saved songs are checked against the server's playlist. If
it changed, e.g. after a sync, or another server is used, the quiz starts
over with the same players. A quiz from a music folder continues offline,
including how far a prepared quiz has come. A new game is saved like any
other change, and a file that can't be read starts a new quiz.

Characters can be read from a folder picked in Settings instead of the
server, for this session. A music folder with a characters folder brings
its own characters, e.g. for a themed quiz; that folder is not counted as
a soundtrack. When the characters come from somewhere else, players pick
their characters again.

Closes #11, closes #44
2026-10-09 18:08:50 +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:
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()