test: Fix interaction tests for harvesting update

This commit is contained in:
demenik
2025-12-03 22:34:07 +01:00
parent 48b3f475b2
commit f8c14cb82d

View File

@@ -1,4 +1,5 @@
use bevy::ecs::system::RunSystemOnce;
use pomomon_garden::features::config::components::BerrySeedConfig;
use pomomon_garden::features::grid::components::{Grid, Tile, TileState};
use pomomon_garden::features::inventory::components::{Inventory, ItemStack, ItemType};
use pomomon_garden::features::pom::actions::InteractionAction;
@@ -49,6 +50,16 @@ fn setup_interaction_app(
items: inventory_items,
});
let mut game_config = GameConfig::default();
game_config.berry_seeds.push(BerrySeedConfig {
name: "TestSeed".to_string(),
cost: 1,
grants: 1,
slice: "seed.aseprite".to_string(),
growth_stages: 2,
});
app.insert_resource(game_config);
app
}
@@ -64,13 +75,13 @@ fn test_plant_seed_interaction() {
vec![(seed_type.clone(), 1)],
);
// Run the interaction logic as a system or closure
let _ = app.world_mut().run_system_once(
move |grid: Res<Grid>,
mut tile_query: Query<&mut TileState>,
mut inventory: ResMut<Inventory>,
mut item_stack_query: Query<&mut ItemStack>,
mut commands: Commands| {
mut commands: Commands,
game_config: Res<GameConfig>| {
let action = InteractionAction::Plant(seed_type.clone());
action.execute(
(1, 1),
@@ -79,6 +90,7 @@ fn test_plant_seed_interaction() {
&mut inventory,
&mut item_stack_query,
&mut commands,
&game_config,
);
},
);
@@ -138,7 +150,8 @@ fn test_plant_seed_no_inventory() {
mut tile_query: Query<&mut TileState>,
mut inventory: ResMut<Inventory>,
mut item_stack_query: Query<&mut ItemStack>,
mut commands: Commands| {
mut commands: Commands,
game_config: Res<GameConfig>| {
let action = InteractionAction::Plant(seed_type.clone());
action.execute(
(1, 1),
@@ -147,6 +160,7 @@ fn test_plant_seed_no_inventory() {
&mut inventory,
&mut item_stack_query,
&mut commands,
&game_config,
);
},
);
@@ -192,10 +206,11 @@ fn test_water_crop() {
move |grid: Res<Grid>,
tile_query: Query<&TileState>,
inventory: Res<Inventory>,
item_query: Query<&ItemStack>| {
item_query: Query<&ItemStack>,
game_config: Res<GameConfig>| {
let tile_entity = grid.get_tile((1, 1)).unwrap();
let tile_state = tile_query.get(tile_entity).unwrap();
let options = InteractionAction::list_options(tile_state, &inventory, item_query);
let options = InteractionAction::list_options(tile_state, &inventory, item_query, &game_config);
assert!(
options.contains(&InteractionAction::Water),
@@ -210,7 +225,8 @@ fn test_water_crop() {
mut tile_query: Query<&mut TileState>,
mut inventory: ResMut<Inventory>,
mut item_stack_query: Query<&mut ItemStack>,
mut commands: Commands| {
mut commands: Commands,
game_config: Res<GameConfig>| {
let action = InteractionAction::Water;
action.execute(
(1, 1),
@@ -219,6 +235,7 @@ fn test_water_crop() {
&mut inventory,
&mut item_stack_query,
&mut commands,
&game_config,
);
},
);
@@ -241,10 +258,11 @@ fn test_water_crop() {
move |grid: Res<Grid>,
tile_query: Query<&TileState>,
inventory: Res<Inventory>,
item_query: Query<&ItemStack>| {
item_query: Query<&ItemStack>,
game_config: Res<GameConfig>| {
let tile_entity = grid.get_tile((1, 1)).unwrap();
let tile_state = tile_query.get(tile_entity).unwrap();
let options = InteractionAction::list_options(tile_state, &inventory, item_query);
let options = InteractionAction::list_options(tile_state, &inventory, item_query, &game_config);
assert!(
!options.contains(&InteractionAction::Water),