fix(tui): alerts, such as WIP aren't being reset
All checks were successful
Rust / build (push) Successful in 6m11s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 1m20s
All checks were successful
Rust / build (push) Successful in 6m11s
ci/woodpecker/push/cron-docker-builder Pipeline was successful
ci/woodpecker/push/push-next Pipeline was successful
ci/woodpecker/push/tag-created Pipeline was successful
Release Please / Release-plz (push) Successful in 1m20s
This commit is contained in:
parent
566125f5c0
commit
df6b96fbfd
3 changed files with 108 additions and 2 deletions
|
@ -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};
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
99
crates/cli/src/tui/actor/tests.rs
Normal file
99
crates/cli/src/tui/actor/tests.rs
Normal file
|
@ -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<String>;
|
||||
|
||||
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"),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue