use super::{SEND, render};
use crate::channel::Reach;
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, pane, seated};
use crate::ui::Model;
const GOAL: &str = "port the paint probe, and say what the walk cannot answer";
fn deposited(model: &mut Model) -> Option<String> {
let window = Window::new();
click(&window, SEND, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, model));
});
let posted = model.outbox.last().expect("the click composed a deposit");
crate::envelope::said(&posted.envelope)
}
fn box_reads(model: &mut Model) -> String {
pane(|ui| render(ui, model))
}
#[test]
fn an_act_that_never_left_this_box_gives_its_words_back() {
let mut model = seated();
model.draft = GOAL.to_owned();
let said = deposited(&mut model);
assert_eq!(said.as_deref(), Some(GOAL), "the words rode with the act");
assert!(model.draft.is_empty(), "and the box cleared on firing");
model.acted(
crate::verbs::MESSAGE.word,
&Reach::Unsent("connect: connection refused".to_owned()),
said,
);
assert_eq!(model.draft, GOAL);
assert!(
box_reads(&mut model).contains(GOAL),
"and it is on the glass"
);
}
#[test]
fn an_act_that_crossed_and_was_never_answered_keeps_its_words_to_itself() {
let mut model = seated();
model.draft = GOAL.to_owned();
let said = deposited(&mut model);
model.acted(
crate::verbs::MESSAGE.word,
&Reach::Unanswered("read: timed out".to_owned()),
said,
);
assert!(model.draft.is_empty(), "{:?}", model.draft);
}
#[test]
fn a_refund_never_clobbers_what_was_typed_after_it() {
let mut model = seated();
model.draft = GOAL.to_owned();
let said = deposited(&mut model);
model.draft = "something else entirely".to_owned();
model.acted(
crate::verbs::MESSAGE.word,
&Reach::Unsent("connect: connection refused".to_owned()),
said,
);
assert_eq!(model.draft, "something else entirely");
}
#[test]
fn a_gesture_that_carries_no_words_refunds_nothing() {
let mut model = seated();
model.acted(
crate::verbs::NUDGE.word,
&Reach::Unsent("connect: connection refused".to_owned()),
crate::envelope::said(&crate::verbs::nudge("home".to_owned(), "c-1".to_owned())),
);
assert!(model.draft.is_empty());
}