test(engine): add XpAwardedEvent and LevelUpEvent total_xp coverage

Two tests in progress_plugin: verify XpAwardedEvent fires with the
correct amount on a slow no-undo win (75 XP), and verify LevelUpEvent's
total_xp field matches the ProgressResource after the win.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
funman300
2026-04-27 04:46:11 +00:00
parent 74fa6c7cff
commit be4cefe79a
+36
View File
@@ -208,4 +208,40 @@ mod tests {
let mut cursor = events.get_cursor();
assert!(cursor.read(events).next().is_none());
}
#[test]
fn xp_awarded_event_fired_with_correct_amount() {
let mut app = headless_app();
// Slow win, no undo → base 50 + no_undo 25 = 75
app.world_mut().send_event(GameWonEvent {
score: 500,
time_seconds: 300,
});
app.update();
let events = app.world().resource::<Events<XpAwardedEvent>>();
let mut cursor = events.get_cursor();
let fired: Vec<_> = cursor.read(events).copied().collect();
assert_eq!(fired.len(), 1);
assert_eq!(fired[0].amount, 75);
}
#[test]
fn levelup_event_total_xp_matches_progress_resource() {
let mut app = headless_app();
app.world_mut().resource_mut::<ProgressResource>().0.total_xp = 480;
app.world_mut().send_event(GameWonEvent {
score: 500,
time_seconds: 300,
});
app.update();
let total_xp = app.world().resource::<ProgressResource>().0.total_xp;
let events = app.world().resource::<Events<LevelUpEvent>>();
let mut cursor = events.get_cursor();
let fired: Vec<_> = cursor.read(events).copied().collect();
assert_eq!(fired.len(), 1);
assert_eq!(fired[0].total_xp, total_xp);
}
}