Files
MusicPlayer/tests/integration/test_shortcuts_popup.gd
T
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

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:
await 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/PlayButton": "Play or pause",
"MusicPlayer/PlayerBar/MusicPlayerContainer/RestartButton": "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)