use super::{
CLOSE, FIND, HEADING, NEEDS_WORDS, NOT_ADDRESSABLE, NOT_ASKED, NOTHING, OPEN, looked_for,
render, unread,
};
use crate::paint_probe::frame::Window;
use crate::reply::search::Found;
use crate::test_support::window::{click, finding, hit, own, pane, seated};
use crate::ui::{Hits, Lookup, Model};
#[test]
fn a_shut_pane_paints_nothing_and_reports_it() {
let mut model = seated();
let mut stood = true;
let painted = pane(|ui| stood = render(ui, &mut model));
assert!(!stood, "a shut pane reports that it painted nothing");
assert!(!painted.contains(HEADING), "{painted}");
}
#[test]
fn the_answered_pane_paints_the_subject_the_field_the_excerpt_and_why_it_is_read_only() {
let mut model = finding();
let painted = pane(|ui| {
render(ui, &mut model);
});
for word in [
"(this box's own engine)",
NOT_ADDRESSABLE,
"looked for \"gate\"",
"conversation /ws/home 20260830T051200Z-a1b2",
"summary +12",
"the gate said no",
"could not be read: p: balls unlistable",
FIND,
CLOSE,
] {
assert!(painted.contains(word), "{word:?}:\n{painted}");
}
}
#[test]
fn no_control_on_this_pane_spends_a_hit() {
let mut model = finding();
let painted = pane(|ui| {
render(ui, &mut model);
});
assert!(!painted.contains(crate::ui::queue::GO), "{painted}");
let _ = crate::test_support::window::painted(&mut model);
assert!(model.outbox.is_empty(), "{:?}", model.outbox);
}
#[test]
fn every_empty_state_is_its_own_sentence() {
let mut unasked = Model {
lookup: Some(Lookup::Finding),
..seated()
};
let painted = pane(|ui| {
render(ui, &mut unasked);
});
assert!(painted.contains(NOT_ASKED), "{painted}");
assert!(!painted.contains(NOT_ADDRESSABLE), "{painted}");
let mut empty = Model {
found: vec![Hits {
channel: own().channel,
found: Found {
needle: "gate".to_owned(),
rows: Vec::new(),
unreadable: Vec::new(),
},
}],
..unasked
};
let painted = pane(|ui| {
render(ui, &mut empty);
});
assert!(painted.contains(NOTHING), "{painted}");
assert!(!painted.contains(NOT_ASKED), "{painted}");
}
#[test]
fn the_act_stands_unlive_with_its_reason_beside_it() {
let mut unarmed = Model {
lookup: Some(Lookup::Finding),
..seated()
};
let painted = pane(|ui| {
render(ui, &mut unarmed);
});
assert!(painted.contains(FIND), "the control stays on the glass");
assert!(painted.contains(NEEDS_WORDS), "{painted}");
let mut armed = finding();
let painted = pane(|ui| {
render(ui, &mut armed);
});
assert!(!painted.contains(NEEDS_WORDS), "{painted}");
}
#[test]
fn what_was_looked_for_and_what_could_not_be_read_are_two_claims() {
let found = Found {
needle: "gate".to_owned(),
rows: vec![hit("ball")],
unreadable: vec!["p: balls unlistable".to_owned()],
};
assert_eq!(looked_for(&found), "looked for \"gate\"");
assert_eq!(
unread(&found.unreadable[0]),
"could not be read: p: balls unlistable"
);
}
#[test]
fn the_roster_opens_it_and_the_act_inside_it_composes_the_search() {
let window = Window::new();
let mut model = seated();
click(&window, OPEN, |ctx| crate::ui::render(ctx, &mut model));
assert!(model.finding());
assert!(model.outbox.is_empty(), "opening asks nothing");
model.needle = "gate".to_owned();
click(&window, FIND, |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(
model.outbox,
vec![crate::ui::Posted::read(crate::verbs::search(
"gate".to_owned()
))]
);
assert!(model.finding(), "searching does not close the pane");
click(&window, CLOSE, |ctx| crate::ui::render(ctx, &mut model));
assert!(!model.finding());
}