use crate::test_support::window::{queued, seated, waiting};
use crate::ui::{Aim, Asking, Channel, Model};
fn own() -> Channel {
crate::test_support::window::own().channel
}
#[test]
fn it_opens_on_an_unaimed_seat_and_keeps_its_rows_when_it_shuts() {
let mut model = Model::default();
model.begin_queue();
assert!(model.showing(crate::ui::Listing::Queue) && model.covered());
let mut model = queued();
model.close_queue();
assert!(!model.showing(crate::ui::Listing::Queue));
assert_eq!(model.waiting.len(), 1, "the rows outlive the pane");
}
#[test]
fn no_aim_and_no_selection_can_retire_it() {
let mut model = queued();
model.aim_at("(this box's own engine)", "home");
model.select("c-2");
assert!(
model.showing(crate::ui::Listing::Queue),
"the queue is about no focus"
);
assert_eq!(model.waiting.len(), 1);
}
#[test]
fn one_channel_s_answer_leaves_every_other_standing() {
let elsewhere = Channel {
name: "elsewhere".to_owned(),
named_there: None,
dials: None,
};
let mut model = Model::default();
model.absorb(
&own(),
crate::reply::Read::Answer(crate::reply::Reply::Attention(vec![waiting("home", "c-1")])),
);
model.absorb(
&elsewhere,
crate::reply::Read::Answer(crate::reply::Reply::Attention(vec![waiting("far", "c-9")])),
);
assert_eq!(model.waiting.len(), 2);
model.absorb(
&own(),
crate::reply::Read::Answer(crate::reply::Reply::Attention(Vec::new())),
);
assert_eq!(model.waiting.len(), 2);
assert!(model.waiting[0].rows.is_empty());
assert_eq!(model.waiting[1].rows.len(), 1, "the other channel stands");
}
#[test]
fn a_row_resolves_against_the_roster_and_not_against_its_section() {
let model = queued();
assert_eq!(
model.wall("home"),
Some(Aim {
channel: "(this box's own engine)".to_owned(),
address: "home".to_owned(),
})
);
assert_eq!(model.wall("elsewhere"), None);
let mut renamed = model;
renamed.waiting = vec![Asking {
channel: Channel {
name: "wrong".to_owned(),
named_there: Some("theirs".to_owned()),
dials: None,
},
rows: vec![waiting("home", "c-1")],
}];
assert!(renamed.wall("home").is_some());
}
#[test]
fn seen_is_composed_only_where_the_wall_resolves() {
let mut model = queued();
model.post_seen(&waiting("elsewhere", "c-3"));
assert!(model.outbox.is_empty(), "no address, no gesture");
model.post_seen(&waiting("home", "c-1"));
assert_eq!(
model.outbox,
vec![crate::ui::Posted::act(crate::verbs::seen(
"home".to_owned(),
"c-1".to_owned()
))]
);
}
#[test]
fn going_to_a_row_aims_selects_and_closes() {
let mut model = queued();
model.go_to(&waiting("elsewhere", "c-3"));
assert!(
model.showing(crate::ui::Listing::Queue),
"an unaddressable row leaves the pane standing"
);
model.go_to(&waiting("home", "c-1"));
assert!(!model.showing(crate::ui::Listing::Queue));
assert_eq!(
model.aim,
Some(Aim {
channel: "(this box's own engine)".to_owned(),
address: "home".to_owned(),
})
);
assert_eq!(model.conversation.as_deref(), Some("c-1"));
assert!(model.outbox.is_empty(), "a view crosses no wire");
}
#[test]
fn escape_closes_the_queue_before_reaching_the_notice() {
let mut model = queued();
model.notice = Some(crate::ui::Notice::Refused("no".to_owned()));
model.escape();
assert!(
!model.showing(crate::ui::Listing::Queue),
"the pane went down"
);
assert!(model.notice.is_some(), "the notice did not");
model.escape();
assert_eq!(model.notice, None, "the next escape reaches it");
}
#[test]
fn the_raise_clears_the_notice_and_files_nothing() {
let mut model = Model {
notice: Some(crate::ui::Notice::Refused("earlier".to_owned())),
..seated()
};
model.absorb(
&own(),
crate::reply::Read::Answer(crate::reply::Reply::Flagged),
);
assert!(model.notice.is_none());
assert!(model.waiting.is_empty());
}