use super::*;
use crate::nav::convs::expand::forest_rows;
use crate::nav::convs::{ConvRow, selection};
fn family() -> [Agent; 5] {
[
agent("r-0", AgentState::Quiescent, 10),
agent("r-0-a-1", AgentState::Quiescent, 11),
agent("r-0-b-1", AgentState::Live, 12),
agent("r-0-b-1-x-2", AgentState::Quiescent, 13),
agent("s-0", AgentState::Quiescent, 90),
]
}
fn forest(agents: &[Agent]) -> Vec<ConvRow> {
forest_rows(agents, "/ws", &unseen, 100, &plain, &[])
}
#[test]
fn the_chain_above_a_member_is_every_shallower_row_over_it() {
let rows = forest(&family());
let deep = selection(&rows, "r-0-b-1-x-2");
assert_eq!(deep.ancestors, ["r-0".to_owned(), "r-0-b-1".to_owned()]);
assert_eq!(deep.root, "r-0");
assert_eq!(selection(&rows, "r-0-a-1").ancestors, ["r-0".to_owned()]);
let root = selection(&rows, "s-0");
assert!(root.ancestors.is_empty(), "a root opens nothing");
assert_eq!(root.root, "s-0");
}
#[test]
fn the_name_is_the_conversations_and_the_gates_are_the_members_own() {
let mut agents = family();
if let Some(root) = agents.first_mut() {
root.name = Some("pennant".to_owned());
}
let rows = forest(&agents);
let member = selection(&rows, "r-0-b-1");
assert_eq!(
member.name, "pennant",
"the conversation's name, not its own"
);
assert!(!member.display_only);
assert!(member.present);
assert!(member.stoppable);
assert!(
!selection(&rows, "r-0").stoppable,
"a quiet root kills nothing"
);
assert!(selection(&rows, "r-0").stop_children);
assert!(member.stop_children);
assert!(!selection(&rows, "r-0-b-1-x-2").stop_children);
let mut legacy = family();
if let Some(root) = legacy.first_mut() {
root.goal_name = Some("relic".to_owned());
}
let legacy = selection(&forest(&legacy), "r-0-a-1");
assert_eq!(legacy.name, "relic");
assert!(legacy.display_only);
}
#[test]
fn a_selection_the_forest_does_not_carry_is_answered_as_itself() {
for rows in [forest(&family()), Vec::new()] {
let ghost = selection(&rows, "20260801T000000Z-gh0");
assert_eq!(ghost.agent_id, "20260801T000000Z-gh0");
assert_eq!(ghost.root, ghost.agent_id, "it roots itself");
assert!(ghost.ancestors.is_empty());
assert_eq!(ghost.name, "20260801T000000Z-gh0", "the ladder's floor");
assert!(!ghost.display_only);
assert_eq!(ghost.flight, None);
assert!(!ghost.present, "nothing to message");
assert!(!ghost.stoppable && !ghost.stop_children);
}
}
#[test]
fn the_flight_class_is_the_conversations_and_every_member_reads_it() {
let mut agents = family();
if let Some(kid) = agents.get_mut(3) {
kid.state = AgentState::InFlight;
}
let rows = forest(&agents);
let class = selection(&rows, "r-0").flight;
assert_eq!(class, Some(crate::nav::convs::Flight::Inference));
for id in ["r-0-a-1", "r-0-b-1", "r-0-b-1-x-2"] {
assert_eq!(
selection(&rows, id).flight,
class,
"one conversation, one class"
);
}
assert_eq!(
selection(&rows, "s-0").flight,
None,
"the other one is at rest"
);
}