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, seen};
use crate::ui::{Enrolling, Grade, Model, theme};
#[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::ui::Posted::act(crate::verbs::enroll(
"home".to_owned(),
"phone-1".to_owned(),
"foot".to_owned(),
None,
))]
);
}
#[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);
}
#[test]
fn the_warning_that_the_material_is_kept_nowhere_is_note_ink() {
let mut model = opened();
fixtures::file(&mut model);
let window = Window::new();
let runs = seen(&window, |ctx| crate::ui::render(ctx, &mut model));
let run = runs
.iter()
.find(|run| run.text == KEPT)
.expect("the warning reached the glass");
assert_eq!(run.ink, theme::accent(theme::State::Annotation));
}
#[test]
fn the_grades_stand_one_row_per_line_and_a_click_on_one_chooses_it() {
let mut model = opened();
let window = Window::new();
let runs = seen(&window, |ctx| crate::ui::render(ctx, &mut model));
let word = |grade: Grade| {
runs.iter()
.find(|run| run.text == grade.word())
.unwrap_or_else(|| panic!("{grade:?} is not on the glass"))
.laid
};
let (first, second) = (word(Grade::Operator), word(Grade::Foot));
assert!(
second.min.y - first.min.y >= theme::ROW - 1.0,
"one grade per line: {first:?} against {second:?}"
);
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, &Grade::Operator.word(), |ctx| {
crate::ui::render(ctx, &mut model);
});
assert_eq!(
model.enroll.as_ref().map(|e| e.grade),
Some(Grade::Operator)
);
}
mod fixtures;
mod modal;
mod shown;