use super::super::super::screen::press;
use super::super::harness::{MINTED_FIRST, SAID, rows_named, shot};
use super::{AGAIN, LANDED, armed, driver_writes, lines, verbs};
use crate::actions::DraftKey;
use tempfile::tempdir;
#[test]
fn a_draft_survives_the_receipt_and_every_re_keying_of_its_conversation() {
let bin = tempdir().unwrap();
let log = bin.path().join("verbs.log");
let (mut world, screen) = armed(bin.path(), &log);
screen.unsettled(&mut world, vec![egui::Event::Text(SAID.to_owned())]);
screen.unsettled(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
screen.unsettled(&mut world, vec![egui::Event::Text(AGAIN.to_owned())]);
assert!(
verbs(&log).is_empty(),
"still inside the gap: the engine has not answered yet"
);
shot(&screen, &mut world);
assert_eq!(verbs(&log), ["prompt"]);
let named = DraftKey::composer(Some(world.ws.clone()), Some(MINTED_FIRST.to_owned()));
assert_eq!(
world.state.actions.drafts.text(&named),
AGAIN,
"the fired words left and the rest stayed, in the box that is now the \
started conversation's"
);
assert!(
crate::paint_probe::painted_of(&shot(&screen, &mut world))
.iter()
.any(|(text, _)| text.contains(AGAIN)),
"and it is on the glass, where they left it"
);
driver_writes(&mut world);
shot(&screen, &mut world);
assert_eq!(
world.state.actions.drafts.text(&DraftKey::composer(
Some(world.ws.clone()),
Some(LANDED.to_owned())
)),
AGAIN,
"one buffer, carried across the swap rather than stranded under the name"
);
assert_eq!(
world.state.actions.drafts.text(&named),
"",
"and not left behind under the spelling nothing points at any more"
);
}
#[test]
fn a_double_enter_before_the_fire_lands_mints_one_name_and_not_two() {
let bin = tempdir().unwrap();
let log = bin.path().join("verbs.log");
let (mut world, screen) = armed(bin.path(), &log);
screen.unsettled(&mut world, vec![egui::Event::Text(SAID.to_owned())]);
for _ in 0..2 {
screen.unsettled(
&mut world,
vec![press(egui::Key::Enter, egui::Modifiers::NONE)],
);
}
shot(&screen, &mut world);
assert_eq!(
verbs(&log),
["prompt"],
"one fire, one mint: {:?}",
lines(&log)
);
assert_eq!(
rows_named(&world, MINTED_FIRST).len(),
1,
"and one row wearing the one name"
);
assert_eq!(
world.model.focus().agent.as_deref(),
Some(MINTED_FIRST),
"the claim the first fire made is the one that stands"
);
}