From a5ba776dfb75bc555e7c34308d493ab67740f7d0 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:50:22 +0000 Subject: [PATCH] test: add test for sync_rhythm_ui in logic_test.rs Added `test_sync_rhythm_ui_updates_components` to verify that `sync_rhythm_ui` correctly updates text and slider values when `RhythmState` duration changes. Tests that both the text display and the Slider component are updated appropriately. This improves test coverage for the rhythm training logic. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- src/logic_test.rs | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/logic_test.rs b/src/logic_test.rs index c5cc380..353df50 100644 --- a/src/logic_test.rs +++ b/src/logic_test.rs @@ -241,6 +241,45 @@ mod tests { assert_eq!(arrow_target.0, Some(2)); } + /// Verifies that `sync_rhythm_ui` correctly updates text and slider values + /// when the `RhythmState` duration changes. + #[test] + fn test_sync_rhythm_ui_updates_components() { + use bevy_ui_widgets::{Slider, SliderValue}; + use crate::components::RhythmText; + + let mut app = setup_app(); + + // Spawn a text entity with RhythmText marker. + let text_entity = app.world_mut().spawn(( + Text("Initial".to_string()), + RhythmText, + )).id(); + + // Spawn a slider entity. + let slider_entity = app.world_mut().spawn(Slider::default()).id(); + + // Run an update cycle. Nothing should change since RhythmState hasn't changed. + app.update(); + + // Now, change the RhythmState duration. + { + let mut rhythm_state = app.world_mut().get_resource_mut::().unwrap(); + rhythm_state.duration = 2.5; + } + + // Run the update cycle to trigger `sync_rhythm_ui`. + app.update(); + + // Verify that the text was updated to reflect the new duration. + let text = app.world().get::(text_entity).unwrap(); + assert_eq!(text.0, "Rhythm: 2.5s"); + + // Verify that the slider entity has received a SliderValue component with the new duration. + let slider_val = app.world().get::(slider_entity).unwrap(); + assert_eq!(slider_val.0, 2.5); + } + /// Verifies that the arrow animation progress resets and increments over time. #[test] fn test_arrow_animation_progress() {