From 0389f9b670b5120b48894607379a4aec79645c03 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:43:00 +0000 Subject: [PATCH] test: add unit test for curriculum_grade_system Added `src/ui/systems_test.rs` to test the state changes produced by `curriculum_grade_system`. Simulated the UI interaction using Bevy's `Interaction::Pressed` and verified that the mock application correctly advances the curriculum grades and default documents in `CurriculumState` according to `CURRICULUM_MANIFEST`. registered the new test module in `src/ui/mod.rs`. Co-authored-by: dynamikdev <717692+dynamikdev@users.noreply.github.com> --- src/ui/mod.rs | 2 ++ src/ui/systems_test.rs | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 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..54b1daa --- /dev/null +++ b/src/ui/systems_test.rs @@ -0,0 +1,35 @@ +use bevy::prelude::*; +use bevy::app::TaskPoolPlugin; +use crate::components::CurriculumGradeButton; +use crate::resources::CurriculumState; +use crate::ui::systems::curriculum_grade_system; + +#[test] +fn test_curriculum_grade_system() { + let mut app = App::new(); + app.add_plugins(TaskPoolPlugin::default()); + + // Setup initial state + let mut state = CurriculumState::default(); + state.selected_grade = Some("Niveau 1.1".to_string()); + state.selected_document = Some("Passage de Grade 1.1".to_string()); + app.insert_resource(state); + + // Spawn button with pressed interaction + app.world_mut().spawn(( + CurriculumGradeButton, + Interaction::Pressed, + )); + + app.add_systems(Update, curriculum_grade_system); + + // Run app to process the interaction + app.update(); + + let new_state = app.world().resource::(); + + // According to CURRICULUM_MANIFEST, the grades sorted are "Niveau 1.1" and "Niveau 1.2" + // So if current is "Niveau 1.1", next should be "Niveau 1.2" + assert_eq!(new_state.selected_grade, Some("Niveau 1.2".to_string())); + assert_eq!(new_state.selected_document, Some("Passage de grade 1.2".to_string())); +}