Fix persisted review startup
This commit is contained in:
+51
-2
@@ -173,8 +173,11 @@ impl App {
|
|||||||
fn new_with_event_log_path(event_log_path: impl AsRef<Path>) -> Result<Self> {
|
fn new_with_event_log_path(event_log_path: impl AsRef<Path>) -> Result<Self> {
|
||||||
let window_snapshot = window::get_snapshot();
|
let window_snapshot = window::get_snapshot();
|
||||||
let mut session_controller = SessionController::new(event_log_path)?;
|
let mut session_controller = SessionController::new(event_log_path)?;
|
||||||
if session_controller.runtime_state() == RuntimeState::Locked {
|
match session_controller.runtime_state() {
|
||||||
session_controller.enter_planning()?;
|
RuntimeState::Locked => session_controller.enter_planning()?,
|
||||||
|
// The rating screen is not durable enough to reconstruct after restart.
|
||||||
|
RuntimeState::Review => session_controller.return_to_planning_after_review()?,
|
||||||
|
_ => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
let active_commitment = session_controller.active_commitment().cloned();
|
let active_commitment = session_controller.active_commitment().cloned();
|
||||||
@@ -1642,6 +1645,52 @@ mod tests {
|
|||||||
let _ = fs::remove_file(path);
|
let _ = fs::remove_file(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn hydrated_review_session_returns_to_planning_and_can_start_next_commitment() {
|
||||||
|
let path = unique_event_log_path("hydrated-review-cycle");
|
||||||
|
{
|
||||||
|
let mut app = App::new_with_event_log_path(&path).unwrap();
|
||||||
|
app.user_intention = "write tests".to_string();
|
||||||
|
app.user_success_condition = "tests pass".to_string();
|
||||||
|
app.user_duration_str = "1".to_string();
|
||||||
|
app.to_in_progress().unwrap();
|
||||||
|
app.to_end().unwrap();
|
||||||
|
assert_eq!(app.session_controller.runtime_state(), RuntimeState::Review);
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut app = App::new_with_event_log_path(&path).unwrap();
|
||||||
|
|
||||||
|
assert_eq!(app.state, State::InputIntention);
|
||||||
|
assert_eq!(
|
||||||
|
app.session_controller.runtime_state(),
|
||||||
|
RuntimeState::Planning
|
||||||
|
);
|
||||||
|
|
||||||
|
app.user_intention = "write next test".to_string();
|
||||||
|
app.user_success_condition = "next test passes".to_string();
|
||||||
|
app.user_duration_str = "1".to_string();
|
||||||
|
app.to_in_progress().unwrap();
|
||||||
|
|
||||||
|
assert_eq!(app.state, State::InProgress);
|
||||||
|
assert_eq!(app.session_controller.runtime_state(), RuntimeState::Active);
|
||||||
|
assert_eq!(
|
||||||
|
app.session_controller
|
||||||
|
.active_commitment()
|
||||||
|
.unwrap()
|
||||||
|
.next_action,
|
||||||
|
"write next test"
|
||||||
|
);
|
||||||
|
|
||||||
|
let records = EventLog::open(&path).unwrap().records().unwrap();
|
||||||
|
assert!(records.iter().any(|record| {
|
||||||
|
record.event_type == EventType::RuntimeTransition
|
||||||
|
&& record.runtime_state == RuntimeState::Planning
|
||||||
|
&& record.payload_json["action"] == "return_to_planning_after_review"
|
||||||
|
}));
|
||||||
|
|
||||||
|
let _ = fs::remove_file(path);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hydrated_active_session_keeps_elapsed_time() {
|
fn hydrated_active_session_keeps_elapsed_time() {
|
||||||
let path = unique_event_log_path("hydrated-active-timer");
|
let path = unique_event_log_path("hydrated-active-timer");
|
||||||
|
|||||||
Reference in New Issue
Block a user