feat: Add all tests from #55 except sowing, watering, and harvesting
This commit is contained in:
110
tests/session.rs
Normal file
110
tests/session.rs
Normal file
@@ -0,0 +1,110 @@
|
||||
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();
|
||||
let mut session_tracker = SessionTracker::default();
|
||||
|
||||
next_phase(&mut current_phase, &mut 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();
|
||||
let mut session_tracker = SessionTracker {
|
||||
completed_focus_phases: timer_settings.long_break_interval - 1,
|
||||
}; // To trigger long break on next phase
|
||||
|
||||
next_phase(&mut current_phase, &mut session_tracker, &timer_settings);
|
||||
|
||||
assert_eq!(
|
||||
session_tracker.completed_focus_phases, timer_settings.long_break_interval,
|
||||
"Completed focus phases should reach 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 mut session_tracker = SessionTracker {
|
||||
completed_focus_phases: 1,
|
||||
}; // Arbitrary value, should not change
|
||||
let timer_settings = TimerSettings::default();
|
||||
|
||||
next_phase(&mut current_phase, &mut 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 mut session_tracker = SessionTracker {
|
||||
completed_focus_phases: 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, &mut 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"
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user