use super::{CLEAR, marking, post, row};
use crate::paint_probe::frame::Window;
use crate::reply::governing::Mark;
use crate::test_support::window::{click, mark, pane, recorded};
use crate::ui::Model;
use serde_json::json;
fn painted(model: &mut Model, mark: Option<&Mark>) -> String {
pane(|ui| row(ui, model, mark))
}
fn press(model: &mut Model, label: &str) {
let held = model
.records
.governing
.clone()
.and_then(|config| config.workflow_mark);
let window = Window::new();
click(&window, label, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| row(ui, model, held.as_ref()));
});
}
#[test]
fn no_mark_paints_no_sentence_and_offers_no_clear() {
let mut model = recorded();
let text = painted(&mut model, None);
assert!(!text.contains("workflow.yaml"), "{text}");
assert!(!text.contains(CLEAR), "{text}");
assert!(text.contains(&marking("strict")), "{text}");
}
#[test]
fn a_mark_on_a_head_names_its_lineage() {
let mut model = recorded();
let text = painted(&mut model, Some(&mark(Some("strict"))));
for word in [
"workflow.yaml marked to config/strict at dddddddd, on r-0",
CLEAR,
] {
assert!(text.contains(word), "{word:?}:\n{text}");
}
}
#[test]
fn a_mark_its_lineage_moved_past_is_painted_as_the_pinned_commit() {
let mut model = recorded();
let text = painted(&mut model, Some(&mark(None)));
for word in [
"workflow.yaml pinned at dddddddd, a commit its lineage has moved past, on r-0",
CLEAR,
] {
assert!(text.contains(word), "{word:?}:\n{text}");
}
}
#[test]
fn each_act_composes_the_envelope_its_verb_row_builds() {
for (label, expected) in [
(
marking("strict"),
json!({"op": "workflow", "workspace": "home",
"agent": "20260830T051200Z-a1b2", "config": "strict"}),
),
(
CLEAR.to_owned(),
json!({"op": "clear-workflow", "workspace": "home",
"agent": "20260830T051200Z-a1b2"}),
),
] {
let mut model = recorded();
press(&mut model, &label);
assert_eq!(
model.outbox,
vec![crate::ui::Posted::act(expected)],
"{label}"
);
}
}
#[test]
fn unanswered_lineages_offer_no_mark() {
let mut model = Model {
lineages: None,
..recorded()
};
assert!(!painted(&mut model, None).contains("workflow from"));
}
#[test]
fn nothing_selected_posts_nothing() {
let mut model = Model {
conversation: None,
..recorded()
};
post(&mut model, &crate::verbs::clear_workflow);
assert!(model.outbox.is_empty());
}