use super::{NOT_ANSWERED, costing, named};
use crate::reply::transcript::{Block, Entry, EntryKind, Transcript, Usage};
use crate::test_support::window::{pane, seated};
use crate::ui::Model;
fn answered(model: &str) -> Transcript {
Transcript {
entries: vec![
Entry {
name: "003-model.json".to_owned(),
raw: "{}".to_owned(),
kind: EntryKind::Model {
model_id: model.to_owned(),
blocks: vec![Block::Text("done".to_owned())],
usage: Usage::new(),
},
},
crate::test_support::window::said("op", "and again"),
],
}
}
fn row() -> crate::reply::agent::Agent {
crate::test_support::window::own_row()
}
#[test]
fn the_line_names_the_conversation_and_says_how_it_is_resting() {
let mut row = row();
row.display = "ZucchiniFrost".to_owned();
row.state = crate::reply::convs::AgentState::Stopped;
row.refused = false;
assert_eq!(
named(&row, &Transcript::default()),
"ZucchiniFrost — stopped"
);
row.refused = true;
assert_eq!(
named(&row, &Transcript::default()),
"ZucchiniFrost — stopped — the provider refused the latest turn"
);
}
#[test]
fn a_conversation_with_no_context_reading_says_which_model_answered_last() {
let mut row = row();
row.display = "ZucchiniFrost".to_owned();
row.state = crate::reply::convs::AgentState::Quiescent;
row.refused = false;
row.context = None;
assert_eq!(
named(&row, &answered("claude-sonnet-5")),
"ZucchiniFrost — quiescent — claude-sonnet-5"
);
let held = self::row();
assert!(!named(&held, &answered("claude-sonnet-5")).contains("claude-sonnet-5"));
assert_eq!(
named(&row, &Transcript::default()),
"ZucchiniFrost — quiescent"
);
}
#[test]
fn the_costing_line_carries_the_spend_and_the_model() {
let mut row = row();
row.spend.tokens.total = 5_089_466;
let said = costing(&row);
assert!(said.contains("5089466 tokens"), "{said}");
assert!(
said.contains(&row.context.expect("the fixture is in flight").model),
"{said}"
);
}
fn showing() -> crate::ui::Model {
let mut model = seated();
let mut row = row();
row.display = "ZucchiniFrost".to_owned();
row.state = crate::reply::convs::AgentState::Stopped;
row.refused = false;
row.spend.tokens.total = 5_089_466;
model.records.agent = Some(row);
model
}
#[test]
fn the_pane_says_which_conversation_it_is_showing() {
let model = showing();
let painted = pane(|ui| crate::ui::chat::render(ui, &model));
for clause in ["ZucchiniFrost", "stopped", "5089466 tokens"] {
assert!(painted.contains(clause), "{painted}");
}
}
#[test]
fn the_resting_clause_is_painted_in_the_state_s_accent() {
let mut model = showing();
let window = crate::paint_probe::frame::Window::new();
let runs = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model));
let resting = runs
.iter()
.find(|run| run.text == "stopped")
.expect("the resting clause is on the glass");
assert_eq!(
resting.ink,
crate::ui::theme::accent(crate::ui::theme::State::Error)
);
let named = runs
.iter()
.find(|run| run.text == "ZucchiniFrost")
.expect("the name is on the glass");
assert_eq!(named.ink, crate::ui::theme::INK, "the name is body ink");
assert!(
named.laid.height() > resting.laid.height(),
"{:?} over {:?}",
named.laid,
resting.laid
);
}
#[test]
fn a_child_conversation_says_what_it_hangs_under_and_a_root_does_not() {
let mut model = showing();
let window = crate::paint_probe::frame::Window::new();
let runs = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model));
let under = runs
.iter()
.find(|run| run.text == "under 20260830T050000Z-root")
.expect("the path is on the glass");
assert_eq!(under.ink, crate::ui::theme::INK_WEAK);
if let Some(row) = model.records.agent.as_mut() {
row.ancestors = Vec::new();
}
let runs = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model));
assert!(
!runs.iter().any(|run| run.text.starts_with("under ")),
"a root hangs under nothing"
);
}
#[test]
fn the_last_model_stands_on_the_line_in_weak_ink_where_the_engine_holds_no_reading() {
let mut model = showing();
model.transcript = answered("house-model-9");
if let Some(row) = model.records.agent.as_mut() {
row.context = None;
}
let window = crate::paint_probe::frame::Window::new();
let runs = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model));
let answered_by = runs
.iter()
.find(|run| run.text == "house-model-9")
.expect("the model is on the glass");
assert_eq!(answered_by.ink, crate::ui::theme::INK_WEAK);
}
#[test]
fn a_failed_conversation_says_so_where_it_is_being_read() {
let mut model = seated();
let mut row = row();
row.failure = Some("no credential for provider row \"work\"".to_owned());
model.records.agent = Some(row);
let window = crate::paint_probe::frame::Window::new();
let said = crate::test_support::window::seen(&window, |ctx| crate::ui::render(ctx, &mut model))
.into_iter()
.find(|run| run.text.contains("no credential for provider row"))
.expect("the provider's clause is on the glass");
assert_eq!(
said.ink,
crate::ui::theme::accent(crate::ui::theme::State::Error)
);
}
#[test]
fn a_conversation_nobody_has_been_answered_about_says_so() {
let model = Model {
records: crate::ui::Records::default(),
..seated()
};
let painted = pane(|ui| crate::ui::chat::render(ui, &model));
assert!(painted.contains(NOT_ANSWERED), "{painted}");
}