From 2dcf2cd133a03868189625d5496c09d45252187d Mon Sep 17 00:00:00 2001 From: demenik Date: Wed, 10 Dec 2025 17:38:38 +0100 Subject: [PATCH] test: Add integration tests for trapping prevention --- tests/trapped.rs | 109 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/trapped.rs diff --git a/tests/trapped.rs b/tests/trapped.rs new file mode 100644 index 0000000..c5c38a4 --- /dev/null +++ b/tests/trapped.rs @@ -0,0 +1,109 @@ +use bevy::ecs::system::RunSystemOnce; +use pomomon_garden::features::grid::components::{Grid, TileState}; +use pomomon_garden::features::inventory::components::ItemType; +use pomomon_garden::features::notification::components::Notifications; +use pomomon_garden::features::pom::actions::InteractionAction; +use pomomon_garden::features::pom::components::{GridPosition, InteractionTarget, PathQueue, Pom}; +use pomomon_garden::features::pom::perform_interaction; +use pomomon_garden::prelude::*; + +mod common; +use common::setup_app; + +#[test] +fn test_prevent_trapping_plant() { + let occupied = TileState::Occupied { + seed: ItemType::BerrySeed { + name: "Wall".into(), + }, + watered: false, + growth_stage: 0, + withered: false, + dry_counter: 0, + }; + + let mut app = setup_app( + 2, + 2, + &[ + (0, 0, TileState::Empty), // Pom + (1, 0, TileState::Empty), // Target + (0, 1, occupied.clone()), + (1, 1, occupied.clone()), + ], + vec![( + ItemType::BerrySeed { + name: "Test".into(), + }, + 10, + )], + None, + ); + + app.init_resource::(); + + app.world_mut().spawn(( + Pom, + GridPosition { x: 0, y: 0 }, + InteractionTarget { + target: Some((1, 0)), + action: Some(InteractionAction::Plant(ItemType::BerrySeed { + name: "Test".into(), + })), + }, + PathQueue::default(), + )); + + let _ = app.world_mut().run_system_once(perform_interaction); + + let grid = app.world().resource::(); + let tile_entity = grid.get_tile((1, 0)).unwrap(); + let tile_state = app.world().entity(tile_entity).get::().unwrap(); + + // Should remain Empty because planting was blocked + match tile_state { + TileState::Empty => (), + _ => panic!("Should have prevented planting! State is {:?}", tile_state), + } +} + +#[test] +fn test_allow_safe_plant() { + let mut app = setup_app( + 10, + 10, + &[(0, 0, TileState::Empty), (1, 0, TileState::Empty)], + vec![( + ItemType::BerrySeed { + name: "Test".into(), + }, + 10, + )], + None, + ); + app.init_resource::(); + + app.world_mut().spawn(( + Pom, + GridPosition { x: 0, y: 0 }, + InteractionTarget { + target: Some((1, 0)), + action: Some(InteractionAction::Plant(ItemType::BerrySeed { + name: "Test".into(), + })), + }, + PathQueue::default(), + )); + + let _ = app.world_mut().run_system_once(perform_interaction); + + let grid = app.world().resource::(); + let tile_entity = grid.get_tile((1, 0)).unwrap(); + let tile_state = app.world().entity(tile_entity).get::().unwrap(); + + // Should be Occupied + match tile_state { + TileState::Occupied { .. } => (), + _ => panic!("Should have allowed planting! State is {:?}", tile_state), + } +}