Newer
Older

Louis
committed
use micro_games_macros::event_system;

Louis
committed
#[test]
fn event_system_correctly_generates_and_dispatches_events() {
use bevy::prelude::*;
let mut app = App::new();
#[event_system]
enum MyEvents {
Wait { source: Entity },
Log { source: Entity, mesasge: String },
}
/// A hatch to allow us to assert that the system has actually run, so we don't miss an
/// assertion
#[derive(Resource)]
struct HasRun(bool);
app.insert_resource(HasRun(false));
app.add_plugins(MyEventsPlugin);
app.add_systems(
Update,

Louis
committed
has_run.0 = true;
let event_length = events.len();
assert_eq!(event_length, 1);
},
);
dispatch_my_events(
&mut app.world,
MyEvents::Wait(WaitEvent {
source: Entity::from_raw(0),
}),
);
app.update();
assert!(app.world.resource::<HasRun>().0);
}