use crate::reply::{Read, Reply};
use crate::test_support::window::{own, seated, trailed};
use crate::ui::{Channel, Model};
#[test]
fn the_pane_opens_with_nothing_aimed_at_and_closes_again() {
let mut model = Model::default();
assert!(!model.trailing());
model.begin_trail();
assert!(model.trailing());
assert!(model.covered(), "the pane covers the conversation");
model.escape();
assert!(!model.trailing());
}
#[test]
fn opening_another_channel_wide_pane_stands_the_trail_down() {
let mut model = Model::default();
model.begin_trail();
model.begin_commands();
assert!(!model.trailing());
assert!(model.commanding());
}
#[test]
fn aiming_and_selecting_leave_it_standing() {
let mut model = seated();
model.begin_trail();
model.select("c-2");
assert!(
model.trailing(),
"a selection retired a pane it is not about"
);
let aim = model.aim.clone().expect("the seated fixture is aimed");
model.aim_at(&aim.channel, &aim.address);
assert!(model.trailing(), "an aim retired a pane it is not about");
}
#[test]
fn an_answer_replaces_its_own_channel_and_leaves_the_others_standing() {
let mut model = seated();
let other = Channel {
name: "elsewhere".to_owned(),
..own().channel
};
model.absorb(
&own().channel,
Read::Answer(Reply::Ops(vec![trailed("bl close x", "live")])),
);
model.absorb(
&other,
Read::Answer(Reply::Ops(vec![trailed("bz login", "acked")])),
);
assert_eq!(model.trails.len(), 2);
model.absorb(&own().channel, Read::Answer(Reply::Ops(Vec::new())));
assert_eq!(
model.trails.len(),
2,
"a section was added rather than replaced"
);
assert!(
model.trails[0].rows.is_empty(),
"the answer did not replace"
);
assert_eq!(
model.trails[1].rows.len(),
1,
"the other channel was disturbed"
);
}
#[test]
fn closing_the_pane_keeps_what_the_channels_said() {
let mut model = seated();
model.absorb(
&own().channel,
Read::Answer(Reply::Ops(vec![trailed("bl close x", "live")])),
);
model.begin_trail();
model.close_lookup();
assert_eq!(model.trails.len(), 1);
}