Short songs (#30): a quiz settings switch and a Seconds per song row (30 by default, 10-120 in steps of 5), saved with the quiz settings. Only part of each quiz song plays, from a random point 10-60% into it, picked once per song so restart and repeat play the same part. The progress bar, time and seeking stay within the part, a hidden beginning counts inside it, and its end counts as the song ending (repeat, stop or go to the next song as set). Random songs (#51): the low-played switch in Settings is now a Normal / Low played / Classic choice, stored as Settings.random_mode and not saved. fetch_random_song(mode) picks /music/rand, /music/rand/low or /music/rand/classic. Closes #30 Closes #51 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
210 lines
7.1 KiB
GDScript
210 lines
7.1 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:
|
|
await 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",
|
|
}
|
|
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.hide_next_track = false
|
|
Settings.auto_repeat_song = false
|
|
|
|
await _open()
|
|
|
|
assert_bool(_card.hide_next_track_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()
|
|
|
|
|
|
func test_statistics_settings_are_in_the_settings_popup_instead() -> void:
|
|
await _open()
|
|
|
|
assert_object(_card.find_child("LowPlayedCheckButton")).is_null()
|
|
assert_object(_card.find_child("AddToDatabaseCheckButton")).is_null()
|
|
|
|
|
|
func test_changes_are_saved_at_once() -> void:
|
|
Settings.hide_next_track = true
|
|
Settings.winning_score = 20
|
|
await _open()
|
|
|
|
await _click_at(_card.hide_next_track_button.get_global_rect().get_center())
|
|
_card.lower_winning_score_button.pressed.emit()
|
|
|
|
var saved: ConfigFile = ConfigFile.new()
|
|
assert_int(saved.load(Settings.saved_settings_path())).is_equal(OK)
|
|
assert_bool(saved.get_value("quiz", "hide_next_track")).is_false()
|
|
assert_int(saved.get_value("quiz", "winning_score")).is_equal(19)
|
|
|
|
|
|
func test_short_songs_shows_its_seconds_and_is_saved() -> void:
|
|
Settings.short_songs = false
|
|
await _open()
|
|
assert_bool(_card.short_song_seconds_row.visible).is_false()
|
|
|
|
_card.short_songs_button.button_pressed = true
|
|
|
|
assert_bool(Settings.short_songs).is_true()
|
|
assert_bool(_card.short_song_seconds_row.visible).is_true()
|
|
var saved: ConfigFile = ConfigFile.new()
|
|
assert_int(saved.load(Settings.saved_settings_path())).is_equal(OK)
|
|
assert_bool(saved.get_value("quiz", "short_songs")).is_true()
|
|
|
|
|
|
func test_seconds_per_song_go_in_fives_between_ten_and_two_minutes() -> void:
|
|
Settings.short_song_seconds = 30
|
|
Settings.short_songs = true
|
|
await _open()
|
|
|
|
_card.increase_short_song_seconds_button.pressed.emit()
|
|
assert_int(Settings.short_song_seconds).is_equal(35)
|
|
assert_str(_card.short_song_seconds_label.text).is_equal("35")
|
|
for i: int in 10:
|
|
_card.lower_short_song_seconds_button.pressed.emit()
|
|
assert_int(Settings.short_song_seconds).is_equal(QuizSettingsCard.MIN_SHORT_SONG_SECONDS)
|
|
for i: int in 40:
|
|
_card.increase_short_song_seconds_button.pressed.emit()
|
|
assert_int(Settings.short_song_seconds).is_equal(QuizSettingsCard.MAX_SHORT_SONG_SECONDS)
|