Files
MusicPlayer/tests/integration/test_shortcuts_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

100 lines
3.4 KiB
GDScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
extends MainWindowTestSuite
## The Shortcuts popup lists every shortcut in the game with the right keys, grouped by
## what they do.
var _popup: ShortcutsPopup
func before_test() -> void:
super()
_popup = _window.get_node("ShortcutsPopup")
## How the list writes [param event]: "Alt + Ctrl + Left", with player numbers as 1–9.
static func _key_text(event: InputEventKey) -> String:
var parts: PackedStringArray = []
if event.alt_pressed:
parts.append("Alt")
if event.ctrl_pressed:
parts.append("Ctrl")
var keycode: Key = event.keycode if event.keycode != KEY_NONE else event.physical_keycode
var key: String = OS.get_keycode_string(keycode)
parts.append("1–9" if key.is_valid_int() else key)
return " + ".join(parts)
## Every button in [param node] and below it that has a keyboard shortcut.
func _buttons_with_shortcuts(node: Node) -> Array[BaseButton]:
var buttons: Array[BaseButton] = []
if node is BaseButton && node.shortcut != null:
buttons.append(node)
for child: Node in node.get_children():
buttons.append_array(_buttons_with_shortcuts(child))
return buttons
func _description(keys: String) -> String:
for group: Array in ShortcutsPopup.SHORTCUTS:
for shortcut: Array in group[1]:
if shortcut[0] == keys:
return shortcut[1]
return ""
func test_every_button_shortcut_is_listed() -> void:
# A player row brings the point keys
_add_player("Crono")
var buttons: Array[BaseButton] = _buttons_with_shortcuts(_window)
assert_int(buttons.size()).is_greater(5)
for button: BaseButton in buttons:
for event: InputEvent in button.shortcut.events:
var keys: String = _key_text(event)
assert_array(ShortcutsPopup.listed_keys()).override_failure_message(
"%s (%s) is not in the list" % [keys, button.name]).contains([keys])
func test_buttons_do_what_the_list_says() -> void:
var expected: Dictionary = {
"SongControls/NextButton": "Next song",
"SongControls/ShowAnswerButton": "Show answer",
"MusicPlayer/PlayerBar/MusicPlayerContainer/PlayTextureButton": "Play or pause",
"MusicPlayer/PlayerBar/MusicPlayerContainer/RestartTextureButton": "Restart song",
}
for path: String in expected:
var button: BaseButton = _quiz.get_node(path)
assert_str(_description(_key_text(button.shortcut.events[0]))) \
.override_failure_message(path).is_equal(expected[path])
func test_keys_are_listed_once() -> void:
var keys: Array[String] = ShortcutsPopup.listed_keys()
for keys_text: String in keys:
assert_int(keys.count(keys_text)).override_failure_message(keys_text).is_equal(1)
func test_groups_have_headings_and_rows() -> void:
_popup.open()
await _runner.simulate_frames(1)
var headings: Array[String] = []
var rows: int = 0
for child: Node in _popup.shortcuts_vbox.get_children():
if child is Label:
headings.append(child.text)
elif child is PanelContainer:
rows += 1
assert_array(headings).contains_exactly(["Players and points", "Songs", "Windows"])
assert_int(rows).is_equal(ShortcutsPopup.listed_keys().size())
func test_list_fits_without_scrolling_or_empty_space() -> void:
_popup.open()
await _runner.simulate_frames(2)
var scroll: ScrollContainer = _popup.shortcuts_vbox.get_parent()
var content: float = _popup.shortcuts_vbox.get_combined_minimum_size().y
assert_float(content).is_less_equal(scroll.size.y)
assert_float(scroll.size.y - content).override_failure_message(
"%d px empty below the list" % (scroll.size.y - content)).is_less_equal(30.0)