use super::super::{RESPONSE, rows};
use super::idiom::{entry, glass, prose, result, running, with, working};
use super::line::head;
use crate::paint_probe::seen_of;
use crate::reply::transcript::{Entry, EntryKind};
use crate::test_support::window::said;
use crate::ui::Model;
use crate::ui::chat::Kind;
use crate::ui::theme::{Bubble, Speaker, glyph};
fn runs(entries: Vec<Entry>) -> bool {
let shown = rows(&with(entries).transcript, None);
let from = shown
.iter()
.rposition(|row| row.bubble == Bubble::Operator)
.map_or(0, |i| i + 1);
let turn = shown.get(from..).unwrap_or(&[]);
let live = turn.iter().filter(|row| row.live).count();
assert!(live == 0 || live == turn.len(), "{shown:?}");
if live > 0 {
assert!(
turn.iter()
.filter(|row| row.kind == Kind::Said && row.weight == Speaker::Model)
.all(|row| row.bubble == Bubble::Intermediate),
"{shown:?}"
);
}
live > 0
}
#[test]
fn the_turn_runs_until_its_final_prose_stands_or_it_is_wounded() {
let turn = || vec![said("op", "port it"), prose("first I will read"), working()];
assert!(runs(turn()), "a call unanswered");
let mut landed = turn();
landed.push(result("done", false));
assert!(runs(landed.clone()), "a result unanswered");
landed.push(running("so"));
assert!(runs(landed.clone()), "the response open");
landed.pop();
landed.push(prose("the seam is real"));
assert!(!runs(landed.clone()), "the final prose stands");
for end in [
entry(EntryKind::Wounded {
wound: "refused".to_owned(),
reason: None,
auth_row: None,
}),
entry(EntryKind::Compacted {
first: 1,
last: 2,
summary: String::new(),
}),
said("judge-one", "seconded"),
] {
let mut ended = turn();
ended.push(result("done", true));
ended.push(end.clone());
assert!(!runs(ended), "{:?}", end.kind);
}
assert!(!runs(Vec::new()), "nothing is not running");
}
fn seen(model: &mut Model) -> Vec<String> {
seen_of(&glass(model))
.into_iter()
.map(|run| run.text)
.collect()
}
#[test]
fn a_tool_in_flight_keeps_the_working_open_and_the_prose_before_it_whole() {
let mut calling = with(vec![
said("op", "port it"),
prose("first I will read"),
working(),
]);
let flying = seen(&mut calling);
assert!(flying.contains(&head(true, [1, 1, 1, 0])), "{flying:?}");
assert!(
flying.iter().any(|t| t == "first I will read"),
"{flying:?}"
);
assert!(flying.contains(&glyph::CALL.to_owned()), "{flying:?}");
let thought = format!(
"{} model-a (thinking) {} weighing two seams",
glyph::NOTE,
glyph::NOTE
);
assert!(flying.contains(&thought), "{flying:?}");
assert!(!flying.iter().any(|t| t == RESPONSE), "{flying:?}");
let mut landed = with(vec![
said("op", "port it"),
prose("first I will read"),
working(),
result("done", false),
]);
let waiting = seen(&mut landed);
assert!(waiting.contains(&head(true, [1, 1, 1, 0])), "{waiting:?}");
assert!(
waiting.iter().any(|t| t == "first I will read"),
"{waiting:?}"
);
let returned = format!("{} read(src/ui.rs)", glyph::DONE);
assert!(waiting.contains(&returned), "{waiting:?}");
assert!(!waiting.contains(&glyph::CALL.to_owned()), "{waiting:?}");
assert!(!waiting.iter().any(|t| t == RESPONSE), "{waiting:?}");
}