use super::{
GOVERNING_HEAD, NO_CARDS, NO_FILES, NO_NOTCHES, NOT_ANSWERED_GOVERNING, NOT_ANSWERED_SPINE,
ROLE_SAID, SPINE_HEAD, card, forking, headline, render, seated as placed,
};
use crate::paint_probe::frame::Window;
use crate::reply::governing::{Governance, Governing};
use crate::reply::rail::{Notch, Rail};
use crate::test_support::window::{click, notch, painted, pane, recorded, seated};
use crate::ui::{Forking, Model};
#[test]
fn the_answered_half_paints_the_governing_commit_the_notches_and_the_cards() {
let mut model = recorded();
let text = pane(|ui| render(ui, &mut model));
for word in [
GOVERNING_HEAD,
"policy follows config/default, now at bbbbbbbb",
"bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb",
"workflow.yaml",
SPINE_HEAD,
ROLE_SAID,
"001 abcdef1 — 120 tokens",
"above 003-claude.json — it had read 2 entries",
"002 — — 120 tokens",
"fork from abcdef1",
"Cobalt — from here — live — 9 tokens",
"working",
] {
assert!(text.contains(word), "{word:?}:\n{text}");
}
}
#[test]
fn only_an_operable_notch_offers_a_fork() {
let bare = Notch {
commit: None,
seat: None,
..notch("002")
};
assert!(!bare.operable());
let mut model = Model {
records: crate::ui::Records {
rail: Some(Rail {
notches: vec![bare.clone()],
cards: Vec::new(),
}),
..recorded().records
},
..recorded()
};
let text = pane(|ui| render(ui, &mut model));
assert!(!text.contains("fork from"), "{text}");
assert_eq!(forking(¬ch("001")), "fork from abcdef1");
assert_eq!(forking(&bare), "fork from —");
}
#[test]
fn every_empty_state_is_its_own_sentence() {
let mut unanswered = Model {
records: crate::ui::Records {
rail: None,
governing: None,
..recorded().records
},
..recorded()
};
let text = pane(|ui| render(ui, &mut unanswered));
assert!(text.contains(NOT_ANSWERED_SPINE), "{text}");
assert!(text.contains(NOT_ANSWERED_GOVERNING), "{text}");
let mut empty = Model {
records: crate::ui::Records {
rail: Some(Rail {
notches: Vec::new(),
cards: Vec::new(),
}),
governing: Some(Governing {
oid: "c".to_owned(),
short_oid: "c".to_owned(),
governance: Governance::Held { diverged: 2 },
files: Vec::new(),
}),
..recorded().records
},
..recorded()
};
let text = pane(|ui| render(ui, &mut empty));
for word in [
NO_NOTCHES,
NO_CARDS,
NO_FILES,
"policy held at c — 2 diverged config lineages",
] {
assert!(text.contains(word), "{word:?}:\n{text}");
}
}
#[test]
fn the_lines_are_values_and_an_unseated_notch_has_none() {
assert_eq!(headline(¬ch("001")), "001 abcdef1 — 120 tokens");
assert_eq!(
placed(¬ch("001")).as_deref(),
Some("above 003-claude.json — it had read 2 entries")
);
let unseated = Notch {
seat: None,
..notch("003")
};
assert_eq!(placed(&unseated), None);
let rail = recorded()
.records
.rail
.expect("the fixture answers a spine");
assert_eq!(card(&rail.cards[0]), "Cobalt — from here — live — 9 tokens");
}
#[test]
fn the_fork_control_waits_for_the_draft_and_then_carries_its_own_commit() {
let window = Window::new();
let mut model = recorded();
click(&window, &forking(¬ch("001")), |ctx| {
crate::ui::render(ctx, &mut model);
});
assert!(model.outbox.is_empty(), "a blank draft fires nothing");
model.forking = Forking {
role: "worker".to_owned(),
goal: "try it".to_owned(),
};
click(&window, &forking(¬ch("001")), |ctx| {
crate::ui::render(ctx, &mut model);
});
assert_eq!(model.outbox.len(), 1, "the armed control fires once");
assert_eq!(model.outbox[0].envelope["from"], "abcdef1234567890");
}
#[test]
fn a_shut_pane_paints_no_spine() {
let mut model = Model {
listing: None,
..recorded()
};
let text = painted(&mut model);
assert!(!text.contains(SPINE_HEAD), "{text}");
let mut nothing = seated();
assert!(!painted(&mut nothing).contains(GOVERNING_HEAD));
}