switched from codex to claude as tutor and moved tests to their own folder
This commit is contained in:
@@ -159,78 +159,3 @@ impl Countdown {
|
||||
self.target_timestamp = None;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn start_from_idle_enters_running() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(10));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
assert_eq!(countdown.state(), CountdownState::Running);
|
||||
assert_eq!(countdown.remaining_at(now), Duration::from_secs(10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pause_and_resume_preserve_remaining_time() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(10));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
let after_three_seconds = now.checked_add(Duration::from_secs(3)).unwrap();
|
||||
countdown
|
||||
.pause(after_three_seconds)
|
||||
.expect("pause should succeed");
|
||||
assert_eq!(countdown.state(), CountdownState::Paused);
|
||||
assert_eq!(
|
||||
countdown.remaining_at(after_three_seconds),
|
||||
Duration::from_secs(7)
|
||||
);
|
||||
|
||||
let resume_time = after_three_seconds
|
||||
.checked_add(Duration::from_secs(1))
|
||||
.unwrap();
|
||||
countdown
|
||||
.resume(resume_time)
|
||||
.expect("resume should succeed");
|
||||
assert_eq!(countdown.state(), CountdownState::Running);
|
||||
assert_eq!(countdown.remaining_at(resume_time), Duration::from_secs(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_transition_returns_error() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(5));
|
||||
|
||||
let err = countdown
|
||||
.pause(now)
|
||||
.expect_err("pause should fail from idle");
|
||||
assert_eq!(
|
||||
err,
|
||||
CountdownError::InvalidTransition {
|
||||
from: CountdownState::Idle,
|
||||
action: "pause",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_countdown_reaches_finished() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(2));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
let after_two_seconds = now.checked_add(Duration::from_secs(2)).unwrap();
|
||||
countdown.sync_finished_at(after_two_seconds);
|
||||
|
||||
assert_eq!(countdown.state(), CountdownState::Finished);
|
||||
assert_eq!(
|
||||
countdown.remaining_at(after_two_seconds),
|
||||
Duration::from_secs(0)
|
||||
);
|
||||
assert!(countdown.is_finished());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
extern crate core;
|
||||
|
||||
mod app_state;
|
||||
mod countdown;
|
||||
pub mod countdown;
|
||||
|
||||
use crate::countdown::commands::{
|
||||
countdown_create, countdown_delete, countdown_list, countdown_pause, countdown_reset,
|
||||
|
||||
73
src-tauri/tests/countdown_model.rs
Normal file
73
src-tauri/tests/countdown_model.rs
Normal file
@@ -0,0 +1,73 @@
|
||||
use owlerlay_lib::countdown::errors::CountdownError;
|
||||
use owlerlay_lib::countdown::model::{Countdown, CountdownState};
|
||||
use tokio::time::{Duration, Instant};
|
||||
|
||||
#[test]
|
||||
fn start_from_idle_enters_running() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(10));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
assert_eq!(countdown.state(), CountdownState::Running);
|
||||
assert_eq!(countdown.remaining_at(now), Duration::from_secs(10));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn pause_and_resume_preserve_remaining_time() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(10));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
let after_three_seconds = now.checked_add(Duration::from_secs(3)).unwrap();
|
||||
countdown
|
||||
.pause(after_three_seconds)
|
||||
.expect("pause should succeed");
|
||||
assert_eq!(countdown.state(), CountdownState::Paused);
|
||||
assert_eq!(
|
||||
countdown.remaining_at(after_three_seconds),
|
||||
Duration::from_secs(7)
|
||||
);
|
||||
|
||||
let resume_time = after_three_seconds
|
||||
.checked_add(Duration::from_secs(1))
|
||||
.unwrap();
|
||||
countdown
|
||||
.resume(resume_time)
|
||||
.expect("resume should succeed");
|
||||
assert_eq!(countdown.state(), CountdownState::Running);
|
||||
assert_eq!(countdown.remaining_at(resume_time), Duration::from_secs(7));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn invalid_transition_returns_error() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(5));
|
||||
|
||||
let err = countdown
|
||||
.pause(now)
|
||||
.expect_err("pause should fail from idle");
|
||||
assert_eq!(
|
||||
err,
|
||||
CountdownError::InvalidTransition {
|
||||
from: CountdownState::Idle,
|
||||
action: "pause",
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn running_countdown_reaches_finished() {
|
||||
let now = Instant::now();
|
||||
let mut countdown = Countdown::new("test", Duration::from_secs(2));
|
||||
countdown.start(now).expect("start should succeed");
|
||||
|
||||
let after_two_seconds = now.checked_add(Duration::from_secs(2)).unwrap();
|
||||
countdown.sync_finished_at(after_two_seconds);
|
||||
|
||||
assert_eq!(countdown.state(), CountdownState::Finished);
|
||||
assert_eq!(
|
||||
countdown.remaining_at(after_two_seconds),
|
||||
Duration::from_secs(0)
|
||||
);
|
||||
assert!(countdown.is_finished());
|
||||
}
|
||||
Reference in New Issue
Block a user