use fixtures::{file, opened};
use super::{CLOSE, HEADING, KEPT, MINTING, NAME_HINT, OPEN, SEND};
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, painted, seated};
use crate::ui::{Enrolling, Grade, Model};
#[test]
fn the_roster_offers_the_control_only_on_the_aimed_wall() {
let mut aimed = seated();
assert!(painted(&mut aimed).contains(OPEN));
let mut adrift = Model {
aim: None,
..seated()
};
assert!(
!painted(&mut adrift).contains(OPEN),
"offered with nothing aimed at"
);
}
#[test]
fn the_roster_s_control_opens_the_pane() {
let mut model = seated();
let window = Window::new();
click(&window, OPEN, |ctx| crate::ui::render(ctx, &mut model));
assert!(model.enroll.is_some(), "the control opened nothing");
assert!(!painted(&mut model).contains(OPEN));
}
#[test]
fn an_enrollment_cannot_be_opened_with_nothing_aimed_at() {
let mut adrift = Model::default();
adrift.begin_enrollment();
assert!(adrift.enroll.is_none());
}
#[test]
fn the_form_asks_for_a_name_and_a_grade_and_names_the_wall() {
let mut model = opened();
let glass = painted(&mut model);
for word in [HEADING, NAME_HINT, SEND, CLOSE, "home"] {
assert!(
glass.contains(word),
"{word:?} is not on the glass:\n{glass}"
);
}
for grade in Grade::both() {
assert!(glass.contains(&grade.word()), "{grade:?} has no control");
}
}
#[test]
fn the_pane_stands_where_the_conversation_would() {
let mut chatting = seated();
let before = painted(&mut chatting);
assert!(
before.contains("port it"),
"the conversation is painted:\n{before}"
);
let mut model = opened();
let during = painted(&mut model);
assert!(
!during.contains("port it"),
"the conversation is still legible:\n{during}"
);
}
#[test]
fn an_unnamed_enrollment_composes_no_gesture() {
let mut model = opened();
model.post_enrollment();
assert!(model.outbox.is_empty());
if let Some(enrolling) = model.enroll.as_mut() {
enrolling.name = " ".to_owned();
}
model.post_enrollment();
assert!(model.outbox.is_empty(), "whitespace is not a name");
}
#[test]
fn the_composed_gesture_is_the_row_the_command_line_spends() {
let mut model = opened();
if let Some(enrolling) = model.enroll.as_mut() {
enrolling.name = " phone-1 ".to_owned();
enrolling.grade = Grade::Foot;
}
model.post_enrollment();
assert_eq!(
model.outbox,
vec![crate::verbs::enroll(
"home".to_owned(),
"phone-1".to_owned(),
"foot".to_owned()
)]
);
}
#[test]
fn the_default_grade_is_the_one_an_operator_enrolls_first() {
assert_eq!(Grade::default().word(), "operator");
assert_eq!(Grade::Foot.word(), "foot");
}
#[test]
fn a_mint_in_flight_is_said_and_outlives_the_outbox() {
let mut model = opened();
if let Some(enrolling) = model.enroll.as_mut() {
enrolling.name = "phone-1".to_owned();
}
assert!(
!painted(&mut model).contains(MINTING),
"said before it was asked"
);
model.post_enrollment();
model.outbox.clear();
assert!(model.enroll.as_ref().is_some_and(Enrolling::minting));
let glass = painted(&mut model);
assert!(glass.contains(MINTING), "{glass}");
file(&mut model);
assert!(!model.enroll.as_ref().is_some_and(Enrolling::minting));
assert!(!painted(&mut model).contains(MINTING));
}
#[test]
fn the_pane_s_controls_fire_from_the_glass() {
let mut model = opened();
if let Some(enrolling) = model.enroll.as_mut() {
enrolling.name = "phone-1".to_owned();
}
let window = Window::new();
click(&window, &Grade::Foot.word(), |ctx| {
crate::ui::render(ctx, &mut model);
});
assert_eq!(model.enroll.as_ref().map(|e| e.grade), Some(Grade::Foot));
click(&window, SEND, |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(model.outbox.len(), 1, "the mint composed nothing");
assert!(model.enroll.as_ref().is_some_and(Enrolling::minting));
model.post_enrollment();
assert_eq!(model.outbox.len(), 1, "a second click minted again");
assert!(painted(&mut model).contains(MINTING));
}
#[test]
fn the_form_s_close_drops_an_unanswered_enrollment() {
let mut model = opened();
let window = Window::new();
click(&window, CLOSE, |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(model.enroll, None);
}
mod fixtures;
mod modal;
mod shown;