diff --git a/crates/cli/src/tui/actor/mod.rs b/crates/cli/src/tui/actor/mod.rs index 848c8f8..6369c76 100644 --- a/crates/cli/src/tui/actor/mod.rs +++ b/crates/cli/src/tui/actor/mod.rs @@ -3,6 +3,9 @@ mod handlers; pub mod messages; mod model; +#[cfg(test)] +mod tests; + use std::sync::mpsc::Sender; use actix::{Actor, ActorContext as _, Context}; diff --git a/crates/cli/src/tui/actor/model.rs b/crates/cli/src/tui/actor/model.rs index 524e4cf..a62214c 100644 --- a/crates/cli/src/tui/actor/model.rs +++ b/crates/cli/src/tui/actor/model.rs @@ -277,8 +277,12 @@ impl RepoState { #[tracing::instrument] pub fn clear_alert(&mut self) { - if let Self::Ready { alert, .. } = self { - *alert = None; + match self { + Self::Identified { alert, .. } + | Self::Configured { alert, .. } + | Self::Ready { alert, .. } => { + *alert = None; + } } } diff --git a/crates/cli/src/tui/actor/tests.rs b/crates/cli/src/tui/actor/tests.rs new file mode 100644 index 0000000..66d6f54 --- /dev/null +++ b/crates/cli/src/tui/actor/tests.rs @@ -0,0 +1,99 @@ +// +mod model { + mod repo_state { + use git_next_core::{git::graph::Log, RepoBranches}; + use ratatui::style::Style; + + use crate::{ + repo::tests::given, + tui::actor::{RepoMessage, RepoState, ViewState}, + }; + type Alert = Option; + + fn identified_with_alert(alert: Alert) -> RepoState { + RepoState::Identified { + repo_alias: given::a_repo_alias(), + message: RepoMessage::builder() + .text(given::a_name()) + .style(Style::default()) + .build(), + alert, + } + } + + fn configured_with_alert(alert: Alert) -> RepoState { + RepoState::Configured { + repo_alias: given::a_repo_alias(), + message: RepoMessage::builder() + .text(given::a_name()) + .style(Style::default()) + .build(), + alert, + branches: RepoBranches::new(String::new(), String::new(), String::new()), + log: Log::default(), + } + } + fn ready_with_alert(alert: Alert) -> RepoState { + RepoState::Ready { + repo_alias: given::a_repo_alias(), + message: RepoMessage::builder() + .text(given::a_name()) + .style(Style::default()) + .build(), + alert, + branches: RepoBranches::new(String::new(), String::new(), String::new()), + log: Log::default(), + view_state: ViewState::default(), + main: given::a_commit(), + next: given::a_commit(), + dev: given::a_commit(), + } + } + + #[rstest::rstest] + #[case(identified_with_alert(None))] + #[case(configured_with_alert(None))] + #[case(ready_with_alert(None))] + fn none_alert_remains_none(#[case] mut repo_state: RepoState) { + // given + match &repo_state { + RepoState::Identified { alert, .. } + | RepoState::Configured { alert, .. } + | RepoState::Ready { alert, .. } => { + assert!(alert.is_none(), "should be none at start"); + } + } + // when + repo_state.clear_alert(); + // then + match &repo_state { + RepoState::Identified { alert, .. } + | RepoState::Configured { alert, .. } + | RepoState::Ready { alert, .. } => assert!(alert.is_none(), "should remain none"), + } + } + + #[rstest::rstest] + #[case(identified_with_alert(Some(String::new())))] + #[case(configured_with_alert(Some(String::new())))] + #[case(ready_with_alert(Some(String::new())))] + fn some_alert_becomes_none(#[case] mut repo_state: RepoState) { + // given + match &repo_state { + RepoState::Identified { alert, .. } + | RepoState::Configured { alert, .. } + | RepoState::Ready { alert, .. } => { + assert!(alert.is_some(), "should be some at start"); + } + } + // when + repo_state.clear_alert(); + // then + match &repo_state { + RepoState::Identified { alert, .. } + | RepoState::Configured { alert, .. } + | RepoState::Ready { alert, .. } => assert!(alert.is_none(), "should become none"), + } + } + } +}