use pretty_assertions::assert_eq;
use rho_protocol::{RewindConversation, SessionRewindPreviewResponse, TreeNodeId};
use super::RewindConfirmation;
use crate::tui::{
daemon_events::{Moved, PreviewAsked},
tests::test_app,
ComposerMode, PickerItem, UiPicker,
};
enum Before {
Empty,
Draft,
ConfirmationOf(&'static str),
}
#[test]
fn a_late_preview_opens_only_where_it_cannot_be_confirmed_unseen() {
let confirmation = |checkpoint: &str, tip: &str| RewindConfirmation {
checkpoint: TreeNodeId::new(checkpoint),
tip: TreeNodeId::new(tip),
};
let cases = [
(
"picked over empty",
Before::Empty,
PreviewAsked::Picked,
Some(confirmation("b", "new")),
),
(
"picked over draft",
Before::Draft,
PreviewAsked::Picked,
None,
),
(
"picked over another confirmation",
Before::ConfirmationOf("a"),
PreviewAsked::Picked,
Some(confirmation("b", "new")),
),
(
"again over its own confirmation",
Before::ConfirmationOf("b"),
PreviewAsked::Again(Moved::Conversation),
Some(confirmation("b", "new")),
),
(
"again over another confirmation",
Before::ConfirmationOf("a"),
PreviewAsked::Again(Moved::Session),
Some(confirmation("a", "old")),
),
];
for (name, before, asked, expected) in cases {
let mut app = test_app();
match before {
Before::Empty => {}
Before::Draft => app.input_ui.set_text("draft".into()),
Before::ConfirmationOf(checkpoint) => {
app.input_ui
.set_composer(ComposerMode::Picker(UiPicker::confirm_rewind(
"Confirm workspace rewind",
vec![PickerItem::new(
"Confirm workspace rewind".into(),
confirmation(checkpoint, "old").value(),
)],
)));
}
}
let preview = SessionRewindPreviewResponse::new(
vec![TreeNodeId::new("b")],
TreeNodeId::new("new"),
0,
Vec::new(),
Vec::new(),
RewindConversation::Moves {
to: TreeNodeId::new("before"),
},
);
app.show_rewind_preview(TreeNodeId::new("b"), asked, Ok(Box::new(preview)));
assert_eq!(app.open_rewind_confirmation(), expected, "{name}");
}
}