use super::super::{CLOSE, KEPT, SEND};
use super::fixtures::{file, material, opened};
use crate::paint_probe::frame::Window;
use crate::qr::Symbol;
use crate::reply::enrolled::Enrolled;
use crate::test_support::window::{click, painted, seated};
use crate::ui::Shown;
#[test]
fn the_material_is_drawn_as_the_envelope_and_nothing_else() {
let held = material();
let shown = Shown::of(&held).expect("the measured envelope fits one symbol");
let straight = Symbol::encode(held.envelope().as_bytes()).expect("it fits");
assert_eq!(shown.symbol, straight);
assert_eq!(shown.caption, held.caption());
}
#[test]
fn the_shown_pane_paints_the_caption_the_warning_and_no_material() {
let mut model = opened();
file(&mut model);
let glass = painted(&mut model);
assert!(glass.contains("phone-1"), "{glass}");
assert!(glass.contains(KEPT), "{glass}");
for secret in ["notreal-key", "notreal-leaf", "BEGIN"] {
assert!(
!glass.contains(secret),
"{secret} is on the glass:\n{glass}"
);
}
assert!(
!glass.contains(SEND),
"the form is still offering to mint:\n{glass}"
);
}
#[test]
fn closing_the_pane_drops_the_material() {
let mut model = opened();
file(&mut model);
assert!(model.enroll.as_ref().is_some_and(|e| e.shown.is_some()));
model.close_enrollment();
assert_eq!(model.enroll, None);
}
#[test]
fn material_arriving_for_a_closed_pane_is_reported_rather_than_dropped() {
let mut model = seated();
file(&mut model);
assert!(model.enroll.is_none());
let said = model
.notice
.as_ref()
.map(crate::ui::Notice::line)
.unwrap_or_default();
assert!(said.contains("phone-1"), "{said}");
assert!(
!said.contains("BEGIN"),
"the notice quoted the material: {said}"
);
}
fn oversized() -> Enrolled {
Enrolled {
ca: "notreal".repeat(400),
..material()
}
}
#[test]
fn material_too_big_for_a_symbol_closes_the_pane_and_says_why() {
assert!(Shown::of(&oversized()).is_err());
let mut model = opened();
model.absorb(
&crate::ui::Channel::default(),
crate::reply::Read::Answer(crate::reply::Reply::Enrolled(oversized())),
);
assert_eq!(model.enroll, None, "the material outlived the refusal");
let said = model
.notice
.as_ref()
.map(crate::ui::Notice::line)
.unwrap_or_default();
assert!(said.contains("will not fit"), "{said}");
assert!(!said.contains("notreal"), "the notice quoted it: {said}");
}
#[test]
fn the_shown_pane_s_close_forgets_the_material() {
let mut model = opened();
file(&mut model);
let window = Window::new();
click(&window, CLOSE, |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(model.enroll, None);
}