use super::super::tick;
use super::{asking, reported};
use crate::state::Standing;
use crate::test_support::Scratch;
use crate::test_support::wire::{flat, wired};
use crate::ui::{Aim, Channel, Chunk, Model};
use serde_json::{Value, json};
#[test]
fn the_questions_nest_and_each_one_waits_for_the_last_to_have_an_answer() {
let scratch = Scratch::new();
let engine = wired(
&scratch,
&flat(),
vec![
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "workspaces", "rows": []})],
vec![json!({"ok": true, "kind": "conversations", "rows": []})],
vec![json!({"ok": true, "kind": "transcript", "rows": []})],
],
);
let own = Channel {
name: crate::seat::OWN.to_owned(),
named_there: None,
dials: None,
};
let mut model = Model {
roster: vec![Chunk::of(own.clone())],
..Model::default()
};
let link = asking(&model);
tick(&link, scratch.path());
model.aim = Some(Aim {
channel: own.name.clone(),
address: "home".to_owned(),
});
link.settle(&mut model);
tick(&link, scratch.path());
model.conversation = Some("20260830T051200Z-a1b2".to_owned());
link.settle(&mut model);
tick(&link, scratch.path());
let ops: Vec<String> = engine
.heard()
.iter()
.filter_map(|said| said.get("op").and_then(Value::as_str))
.map(str::to_owned)
.collect();
assert_eq!(
ops,
vec![
"workspaces",
"workspaces",
"conversations",
"workspaces",
"conversations",
"transcript",
]
);
}
#[test]
fn an_empty_standing_set_asks_nothing() {
let scratch = Scratch::new();
let link = asking(&Model::default());
tick(&link, scratch.path());
assert!(reported(&link).is_empty());
assert_eq!(Standing::default().aimed(), None);
}
#[test]
fn an_aimed_read_that_cannot_be_routed_says_so_as_unreachable() {
let scratch = Scratch::new();
let own = Channel {
name: crate::seat::OWN.to_owned(),
named_there: None,
dials: None,
};
let mut model = Model {
roster: vec![Chunk::of(own.clone())],
aim: Some(Aim {
channel: own.name,
address: "home".to_owned(),
}),
..Model::default()
};
let link = asking(&model);
tick(&link, scratch.path());
link.settle(&mut model);
let crate::ui::Held::Unheld(why) = &model.roster[0].held else {
panic!("the leg said nothing: {:?}", model.roster[0].held);
};
assert!(why.contains("no wire provisioned"), "{why}");
assert_eq!(model.notice, None);
}