use super::fixture::{World, world};
use super::screen::{Screen, press};
use crate::actions::DraftKey;
fn arrow(key: egui::Key) -> Vec<egui::Event> {
vec![press(key, egui::Modifiers::NONE)]
}
#[test]
fn up_pages_back_through_your_own_turns_and_down_returns_the_draft() {
let mut world = world();
let ws = world.ws.clone();
world.converge();
let screen = Screen::new();
assert!(screen.idle(&mut world), "the cursor starts in the composer");
world.model.focus_agent(&ws, "c-1");
let key = DraftKey::Message("c-1".to_owned());
screen.frame(&mut world, vec![egui::Event::Text("half-typed".into())]);
let draft = |world: &World| world.state.actions.drafts.text(&key);
assert_eq!(draft(&world), "half-typed");
screen.frame(&mut world, arrow(egui::Key::ArrowUp));
assert_eq!(
draft(&world),
"follow-up message",
"↑ recalls the newest thing said here — the pending deposit"
);
screen.frame(&mut world, arrow(egui::Key::ArrowUp));
assert_eq!(
draft(&world),
"please ping",
"↑ again reaches the delivered transcript"
);
screen.frame(&mut world, arrow(egui::Key::ArrowUp));
assert_eq!(
draft(&world),
"please ping",
"the oldest turn is the end of the walk"
);
screen.frame(&mut world, arrow(egui::Key::ArrowDown));
assert_eq!(draft(&world), "follow-up message", "↓ comes forward again");
screen.frame(&mut world, arrow(egui::Key::ArrowDown));
assert_eq!(
draft(&world),
"half-typed",
"and past the newest the draft comes back verbatim"
);
}
#[test]
fn a_caret_below_the_top_row_still_owns_the_arrow() {
let mut world = world();
let ws = world.ws.clone();
world.converge();
let screen = Screen::new();
assert!(screen.idle(&mut world), "the cursor starts in the composer");
world.model.focus_agent(&ws, "c-1");
let key = DraftKey::Message("c-1".to_owned());
screen.frame(&mut world, vec![egui::Event::Text("first".into())]);
screen.frame(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::SHIFT)],
);
screen.frame(&mut world, vec![egui::Event::Text("second".into())]);
screen.frame(&mut world, arrow(egui::Key::ArrowUp));
assert_eq!(
world.state.actions.drafts.text(&key),
"first\nsecond",
"the caret was on the second row: ↑ moved it, and recalled nothing"
);
screen.frame(&mut world, arrow(egui::Key::ArrowUp));
assert_eq!(
world.state.actions.drafts.text(&key),
"follow-up message",
"from the top row the same key recalls"
);
}