Files
pomomon-garden/tests/session.rs

120 lines
3.8 KiB
Rust

use pomomon_garden::features::phase::components::{
CurrentPhase, Phase, SessionTracker, TimerSettings,
};
use pomomon_garden::features::phase::next_phase;
#[test]
fn test_session_tracker_focus_to_short_break() {
let mut current_phase = CurrentPhase(Phase::Finished {
completed_phase: Box::new(Phase::Focus {
duration: 25.0 * 60.0,
}),
});
let timer_settings = TimerSettings::default();
// Simulate that grant_focus_rewards has already incremented the counter
let session_tracker = SessionTracker {
completed_focus_phases: 1,
total_berries_earned: 0,
};
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, 1,
"Completed focus phases should be 1"
);
if let Phase::Break { duration } = current_phase.0 {
assert_eq!(
duration, timer_settings.short_break_duration as f32,
"Should transition to short break"
);
} else {
panic!("Expected a Break phase, got {:?}", current_phase.0);
}
}
#[test]
fn test_session_tracker_focus_to_long_break() {
let mut current_phase = CurrentPhase(Phase::Finished {
completed_phase: Box::new(Phase::Focus {
duration: 25.0 * 60.0,
}),
});
let timer_settings = TimerSettings::default();
// Simulate that grant_focus_rewards has already incremented the counter to the interval
let session_tracker = SessionTracker {
completed_focus_phases: timer_settings.long_break_interval,
total_berries_earned: 0,
};
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, timer_settings.long_break_interval,
"Completed focus phases should remain at long break interval"
);
if let Phase::Break { duration } = current_phase.0 {
assert_eq!(
duration, timer_settings.long_break_duration as f32,
"Should transition to long break"
);
} else {
panic!("Expected a Break phase, got {:?}", current_phase.0);
}
}
#[test]
fn test_session_tracker_break_to_focus() {
let mut current_phase = CurrentPhase(Phase::Finished {
completed_phase: Box::new(Phase::Break {
duration: 5.0 * 60.0,
}),
});
let session_tracker = SessionTracker {
completed_focus_phases: 1,
total_berries_earned: 0,
}; // Arbitrary value, should not change
let timer_settings = TimerSettings::default();
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
session_tracker.completed_focus_phases, 1,
"Completed focus phases should not change"
);
if let Phase::Focus { duration } = current_phase.0 {
assert_eq!(
duration, timer_settings.focus_duration as f32,
"Should transition to Focus phase"
);
} else {
panic!("Expected a Focus phase, got {:?}", current_phase.0);
}
}
#[test]
fn test_session_tracker_not_finished_phase_no_change() {
// Test that nothing changes if the phase is not `Finished`
let mut current_phase = CurrentPhase(Phase::Focus { duration: 100.0 });
let session_tracker = SessionTracker {
completed_focus_phases: 0,
total_berries_earned: 0,
};
let timer_settings = TimerSettings::default();
let initial_phase = current_phase.0.clone();
let initial_completed_focus = session_tracker.completed_focus_phases;
next_phase(&mut current_phase, &session_tracker, &timer_settings);
assert_eq!(
current_phase.0, initial_phase,
"Phase should not change if not Finished"
);
assert_eq!(
session_tracker.completed_focus_phases, initial_completed_focus,
"Session tracker should not change if phase not Finished"
);
}