use super::{ARM, DELETE, FLAG, RETARGET, STOP, WHY, render};
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, pane, seated};
use crate::ui::{Aim, Model};
use serde_json::json;
fn subject(model: &Model) -> (Aim, String) {
(
model.aim.clone().expect("the fixture is aimed at a wall"),
model.conversation.clone().expect("and has one selected"),
)
}
fn press(model: &mut Model, label: &str) {
let (aim, agent) = subject(model);
let window = Window::new();
click(&window, label, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, model, &aim, &agent));
});
}
#[test]
fn the_row_offers_the_four_acts_and_says_what_each_box_is_for() {
let mut model = seated();
let (aim, agent) = subject(&model);
let painted = pane(|ui| render(ui, &mut model, &aim, &agent));
for word in [STOP, RETARGET, FLAG, DELETE, ARM, WHY] {
assert!(
painted.lines().any(|line| line == word),
"{word:?}:\n{painted}"
);
}
}
#[test]
fn each_act_composes_the_envelope_its_verb_row_builds() {
for (label, expected) in [
(
STOP,
json!({"op": "stop", "workspace": "home", "agent": "20260830T051200Z-a1b2"}),
),
(
RETARGET,
json!({"op": "retarget", "workspace": "home", "agent": "20260830T051200Z-a1b2"}),
),
(
DELETE,
json!({"op": "delete-agent", "workspace": "home",
"agent": "20260830T051200Z-a1b2", "typed": ""}),
),
] {
let mut model = seated();
press(&mut model, label);
assert_eq!(
model.outbox,
vec![crate::ui::Posted::act(expected)],
"{label}"
);
}
}
#[test]
fn the_typed_name_rides_the_deletion_verbatim_and_stays_the_operators() {
let mut model = seated();
model.typed = "port the paint probe".to_owned();
press(&mut model, DELETE);
assert_eq!(
model.outbox,
vec![crate::ui::Posted::act(
json!({"op": "delete-agent", "workspace": "home",
"agent": "20260830T051200Z-a1b2", "typed": "port the paint probe"})
)]
);
assert_eq!(
model.typed, "port the paint probe",
"a delete the engine refuses while the conversation is live must not \
charge the operator a retype"
);
}
#[test]
fn the_acts_carry_the_address_the_channel_resolves() {
let mut model = Model {
aim: Some(Aim {
channel: "(this box's own engine)".to_owned(),
address: "elsewhere".to_owned(),
}),
..seated()
};
press(&mut model, STOP);
assert_eq!(model.outbox[0].envelope["workspace"], json!("elsewhere"));
}
#[test]
fn the_raise_carries_the_reason_and_spends_the_box() {
let mut model = seated();
model.reason = "it is rewriting an unrelated crate".to_owned();
press(&mut model, FLAG);
assert_eq!(
model.outbox,
vec![crate::ui::Posted::act(
json!({"op": "flag", "workspace": "home",
"agent": "20260830T051200Z-a1b2",
"reason": "it is rewriting an unrelated crate"})
)]
);
assert!(model.reason.is_empty(), "a flag that fired is said");
}
#[test]
fn a_raise_with_no_words_is_offered_and_fires_nothing() {
let mut model = seated();
model.reason = " ".to_owned();
let (aim, agent) = subject(&model);
let window = Window::new();
let painted = pane(|ui| render(ui, &mut model, &aim, &agent));
assert!(painted.lines().any(|line| line == FLAG), "{painted}");
click(&window, FLAG, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, &mut model, &aim, &agent));
});
assert!(model.outbox.is_empty(), "{:?}", model.outbox);
}
#[test]
fn painting_the_row_composes_nothing() {
let mut model = seated();
let (aim, agent) = subject(&model);
let _ = pane(|ui| render(ui, &mut model, &aim, &agent));
assert!(model.outbox.is_empty(), "{:?}", model.outbox);
}