Files
MusicPlayer/tests/integration/test_quiz_settings_card.gd
T
Sansan b510aa47f2
Build / test (push) Successful in 44s
Build / build (push) Successful in 1m13s
Split settings into a quiz card and an application Settings popup
- A Quiz settings button under the player bar opens a small card above
  it with the quiz settings, including Auto repeat, which moves there
  from under the player bar. The card does not dim the quiz, so it can
  be changed during a song, and grows to fit its rows.
- A Settings button in the top bar opens the application settings:
  server, fullscreen and songs to download ahead. Quick sync is gone,
  as the server no longer has it, and the server list is in Settings.
- Labels use sentence case, and seconds to hide show as whole numbers.
- Debug builds switch to the local server and a low winning score in
  the Settings autoload, before any scene asks the server for anything.
  The DEBUG label moves to the top bar, so it shows on every tab.
- Search moves from the top bar back to the quiz toolbar, as the
  Statistics tab has its own search.
2026-10-07 16:05:13 +02:00

161 lines
5.3 KiB
GDScript

extends MainWindowTestSuite
## The quiz settings card: opened from the button under the player bar, it changes the
## quiz settings without dimming or stopping the quiz.
var _card: QuizSettingsCard
var _button: Button
func before_test() -> void:
super()
_card = _quiz.get_node("QuizSettingsCard")
_button = _quiz.get_node("QuizSettingsButton")
func _open() -> void:
await _click_at(_button.get_global_rect().get_center())
await _runner.simulate_frames(1)
func test_button_opens_the_card_above_it_without_dimming() -> void:
await _open()
assert_bool(_card.visible).is_true()
var card: Rect2 = _card.card_panel.get_global_rect()
var button: Rect2 = _button.get_global_rect()
assert_float(card.end.y).is_less_equal(button.position.y)
var bar: Rect2 = (_quiz.get_node("MusicPlayer/PlayerBar") as Control).get_global_rect()
assert_float(card.end.y).override_failure_message("The card covers the player bar") \
.is_less_equal(bar.position.y)
assert_float(card.position.x).is_equal(button.position.x)
assert_bool(Rect2(Vector2.ZERO, Vector2(1920, 1080)).encloses(card)).is_true()
assert_bool((_quiz.get_node("PopupBackdrop") as Control).visible).is_false()
assert_bool((_window.get_node("PopupBackdrop") as Control).visible).is_false()
func test_song_keeps_playing_while_the_card_is_open() -> void:
await _play_first_song()
await _open()
assert_int(Playlist.currently_playing_song).is_equal(0)
assert_bool((_quiz.get_node("MusicPlayer") as MusicPlayer).audio_player.stream_paused) \
.is_false()
func test_clicking_outside_closes_it_without_pressing_what_is_behind() -> void:
await _open()
var reset_button: Button = _quiz.get_node("QuizToolbar/ResetPlaylistButton")
await _click_at(reset_button.get_global_rect().get_center())
assert_bool(_card.visible).is_false()
assert_int(_server.count("/music/reset")).is_equal(0)
func test_button_closes_an_open_card() -> void:
await _open()
await _click_at(_button.get_global_rect().get_center())
assert_bool(_card.visible).is_false()
func test_each_toggle_changes_its_setting() -> void:
var toggles: Dictionary = {
"auto_repeat_button": "auto_repeat_song",
"stop_after_current_button": "stop_after_current",
"hide_next_track_button": "hide_next_track",
"hide_beginning_button": "hide_beginning",
"hide_length_button": "hide_length",
"hide_ticks_button": "hide_ticks",
"low_played_button": "use_low_played_mode",
"add_to_database_button": "add_to_stats",
}
await _open()
for button_name: String in toggles:
var toggle: CheckButton = _card.get(button_name)
var before: bool = Settings.get(toggles[button_name])
assert_bool(toggle.button_pressed).override_failure_message(button_name) \
.is_equal(before)
await _click_at(toggle.get_global_rect().get_center())
assert_bool(Settings.get(toggles[button_name])).override_failure_message(
button_name + " did not change its setting").is_equal(!before)
assert_bool(toggle.button_pressed).is_equal(!before)
func test_card_shows_settings_changed_elsewhere() -> void:
await _open()
_card.close()
Settings.add_to_stats = false
Settings.auto_repeat_song = false
await _open()
assert_bool(_card.add_to_database_button.button_pressed).is_false()
assert_bool(_card.auto_repeat_button.button_pressed).is_false()
func test_seconds_to_hide_only_show_while_hiding_the_beginning() -> void:
Settings.hide_beginning = false
await _open()
assert_bool(_card.hide_for_seconds_row.visible).is_false()
_card.hide_beginning_button.button_pressed = true
assert_bool(_card.hide_for_seconds_row.visible).is_true()
assert_str(_card.hide_for_seconds_label.text).is_equal("%d" % Settings.hide_for_seconds)
func test_seconds_to_hide_are_whole_numbers_between_0_and_10() -> void:
Settings.hide_for_seconds = 9.0
await _open()
_card.increase_hide_for_seconds_button.pressed.emit()
_card.increase_hide_for_seconds_button.pressed.emit()
assert_float(Settings.hide_for_seconds).is_equal(10.0)
assert_str(_card.hide_for_seconds_label.text).is_equal("10")
for i: int in 12:
_card.lower_hide_for_seconds_button.pressed.emit()
assert_float(Settings.hide_for_seconds).is_equal(0.0)
assert_str(_card.hide_for_seconds_label.text).is_equal("0")
func test_winning_score_goes_up_and_down_but_not_below_one() -> void:
Settings.winning_score = 2
await _open()
_card.increase_winning_score_button.pressed.emit()
assert_int(Settings.winning_score).is_equal(3)
for i: int in 5:
_card.lower_winning_score_button.pressed.emit()
assert_int(Settings.winning_score).is_equal(1)
assert_str(_card.score_label.text).is_equal("1")
func test_auto_repeat_in_the_card_is_what_the_player_uses() -> void:
Settings.auto_repeat_song = true
await _open()
await _click_at(_card.auto_repeat_button.get_global_rect().get_center())
assert_bool(Settings.auto_repeat_song).is_false()
assert_object(_quiz.get_node("MusicPlayer").get_node_or_null("RepeatSongCheckButton")) \
.is_null()
func test_card_grows_upward_for_the_seconds_row() -> void:
Settings.hide_beginning = false
await _open()
var closed_row: Rect2 = _card.card_panel.get_global_rect()
_card.hide_beginning_button.button_pressed = true
var open_row: Rect2 = _card.card_panel.get_global_rect()
assert_float(open_row.end.y).is_equal(closed_row.end.y)
assert_float(open_row.size.y).is_greater(closed_row.size.y)
# Every row stays inside the card
assert_bool(open_row.encloses(_card.rows.get_global_rect())).is_true()