From d25c49ba8cd42d93beaa7eaf8b8cbb33b95657f1 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 16 Apr 2026 13:55:46 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=AA=20add=20tests=20for=20rhythm=5Fmod?= =?UTF-8?q?e=5Ftoggle=5Fsystem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit adds comprehensive unit tests for `rhythm_mode_toggle_system` in `src/ui/systems.rs`. It introduces a new file `src/ui/systems_test.rs` which verifies state transitions when the RhythmModeButton is pressed, hovered, and released, improving the robustness and coverage of the UI interaction code. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- src/ui/mod.rs | 2 + src/ui/systems_test.rs | 129 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 src/ui/systems_test.rs diff --git a/src/ui/mod.rs b/src/ui/mod.rs index f77092d..ba51e35 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -12,6 +12,8 @@ mod setup_test; #[cfg(test)] mod curriculum_test; pub mod systems; +#[cfg(test)] +mod systems_test; pub mod target; use bevy::prelude::*; diff --git a/src/ui/systems_test.rs b/src/ui/systems_test.rs new file mode 100644 index 0000000..c58159f --- /dev/null +++ b/src/ui/systems_test.rs @@ -0,0 +1,129 @@ +//! Tests for the UI systems module. +#[cfg(test)] +mod tests { + use bevy::prelude::*; + use crate::components::RhythmModeButton; + use crate::resources::{RhythmState, RhythmMode}; + use crate::ui::systems::rhythm_mode_toggle_system; + + fn setup_app() -> App { + let mut app = App::new(); + // Since bevy::core doesn't have it and it's not in prelude let's just use MinimalPlugins to set up App schedule. + app.add_plugins(MinimalPlugins); + app + } + + #[test] + fn test_rhythm_mode_toggle_system_pressed_constant_to_accelerate() { + let mut app = setup_app(); + + app.insert_resource(RhythmState { + mode: RhythmMode::Constant, + duration: 1.0, + accelerate_counter: 5, + }); + + app.add_systems(Update, rhythm_mode_toggle_system); + + let text_entity = app.world_mut().spawn(Text::new("Rhythm: Constant")).id(); + let _button_entity = app.world_mut().spawn(( + RhythmModeButton, + Interaction::Pressed, + BackgroundColor(Color::NONE), + )).add_child(text_entity).id(); + + app.update(); + + let state = app.world().resource::(); + assert_eq!(state.mode, RhythmMode::Accelerate); + assert_eq!(state.accelerate_counter, 0); + + let text = app.world().get::(text_entity).unwrap(); + assert_eq!(text.0, "Rhythm: Accelerate"); + } + + #[test] + fn test_rhythm_mode_toggle_system_pressed_accelerate_to_constant() { + let mut app = setup_app(); + + app.insert_resource(RhythmState { + mode: RhythmMode::Accelerate, + duration: 1.0, + accelerate_counter: 8, + }); + + app.add_systems(Update, rhythm_mode_toggle_system); + + let text_entity = app.world_mut().spawn(Text::new("Rhythm: Accelerate")).id(); + let _button_entity = app.world_mut().spawn(( + RhythmModeButton, + Interaction::Pressed, + BackgroundColor(Color::NONE), + )).add_child(text_entity).id(); + + app.update(); + + let state = app.world().resource::(); + assert_eq!(state.mode, RhythmMode::Constant); + assert_eq!(state.accelerate_counter, 0); + + let text = app.world().get::(text_entity).unwrap(); + assert_eq!(text.0, "Rhythm: Constant"); + } + + #[test] + fn test_rhythm_mode_toggle_system_hovered() { + let mut app = setup_app(); + + app.insert_resource(RhythmState { + mode: RhythmMode::Constant, + duration: 1.0, + accelerate_counter: 0, + }); + + app.add_systems(Update, rhythm_mode_toggle_system); + + let text_entity = app.world_mut().spawn(Text::new("Rhythm: Constant")).id(); + let button_entity = app.world_mut().spawn(( + RhythmModeButton, + Interaction::Hovered, + BackgroundColor(Color::NONE), + )).add_child(text_entity).id(); + + app.update(); + + let state = app.world().resource::(); + assert_eq!(state.mode, RhythmMode::Constant); // Should not change + + let background = app.world().get::(button_entity).unwrap(); + assert_eq!(background.0, Color::srgba(0.886, 0.886, 0.886, 0.1)); + } + + #[test] + fn test_rhythm_mode_toggle_system_none() { + let mut app = setup_app(); + + app.insert_resource(RhythmState { + mode: RhythmMode::Constant, + duration: 1.0, + accelerate_counter: 0, + }); + + app.add_systems(Update, rhythm_mode_toggle_system); + + let text_entity = app.world_mut().spawn(Text::new("Rhythm: Constant")).id(); + let button_entity = app.world_mut().spawn(( + RhythmModeButton, + Interaction::None, + BackgroundColor(Color::srgba(0.886, 0.886, 0.886, 0.1)), + )).add_child(text_entity).id(); + + app.update(); + + let state = app.world().resource::(); + assert_eq!(state.mode, RhythmMode::Constant); // Should not change + + let background = app.world().get::(button_entity).unwrap(); + assert_eq!(background.0, Color::NONE); + } +}