use crate::reply::{Read, Reply};
use crate::test_support::window::{boarded, column, figure, own, seated};
use crate::ui::{Channel, Model};
fn binding(id: &str) -> crate::reply::balls::BallRow {
crate::reply::balls::BallRow {
ball_id: id.to_owned(),
project: "p".to_owned(),
state: "ready".to_owned(),
title: None,
claimant: None,
workspace: None,
}
}
#[test]
fn the_pane_opens_with_nothing_aimed_at_and_closes_again() {
let mut model = Model::default();
assert!(!model.boarding());
model.begin_board();
assert!(model.boarding());
assert!(model.covered(), "the pane covers the conversation");
model.escape();
assert!(!model.boarding());
}
#[test]
fn opening_another_channel_wide_pane_stands_the_board_down() {
let mut model = Model::default();
model.begin_board();
model.begin_trail();
assert!(!model.boarding());
assert!(model.trailing());
}
#[test]
fn an_aim_retires_the_wall_s_answers_and_leaves_the_pane_standing() {
let mut model = boarded();
model.select("c-2");
assert!(
model.boarding(),
"a selection retired a pane it is not about"
);
assert!(
model.holding.is_some(),
"a selection retired the wall's balls"
);
let aim = model.aim.clone().expect("the fixture is aimed");
model.aim_at(&aim.channel, "another wall entirely");
assert!(model.boarding(), "an aim retired a pane it is not about");
assert!(
model.holding.is_none(),
"the old wall's balls outlived the aim"
);
assert!(
model.marks.is_none(),
"the old wall's branch outlived the aim"
);
}
#[test]
fn a_board_answer_replaces_its_own_channel_and_leaves_the_others_standing() {
let mut model = seated();
let other = Channel {
name: "elsewhere".to_owned(),
..own().channel
};
let full = crate::reply::board::Board {
rows: vec![column("bl-1", "ready")],
fleet: Vec::new(),
};
model.absorb(&own().channel, Read::Answer(Reply::Board(full.clone())));
model.absorb(&other, Read::Answer(Reply::Board(full)));
assert_eq!(model.columns.len(), 2);
model.absorb(
&own().channel,
Read::Answer(Reply::Board(crate::reply::board::Board {
rows: Vec::new(),
fleet: Vec::new(),
})),
);
assert_eq!(
model.columns.len(),
2,
"a section was added rather than replaced"
);
assert!(
model.columns[0].board.rows.is_empty(),
"the answer did not replace"
);
assert_eq!(
model.columns[1].board.rows.len(),
1,
"the other channel was disturbed"
);
}
#[test]
fn a_binding_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::Balls(vec![binding("bl-1")])),
);
model.absorb(&other, Read::Answer(Reply::Balls(vec![binding("bl-2")])));
assert_eq!(model.bindings.len(), 2);
model.absorb(&own().channel, Read::Answer(Reply::Balls(Vec::new())));
assert_eq!(
model.bindings.len(),
2,
"a section was added rather than replaced"
);
assert!(
model.bindings[0].rows.is_empty(),
"the answer did not replace"
);
assert_eq!(
model.bindings[1].rows.len(),
1,
"the other channel was disturbed"
);
}
#[test]
fn the_wall_s_two_answers_are_filed_off_the_pane() {
let mut model = seated();
model.absorb(
&own().channel,
Read::Answer(Reply::WorkspaceBalls(vec![
crate::reply::balls::BoundBall {
id: "bl-1".to_owned(),
badge: None,
project: "p".to_owned(),
owner: "alba".to_owned(),
state: "bound".to_owned(),
spend: figure(None, None),
},
])),
);
model.absorb(
&own().channel,
Read::Answer(Reply::Marks {
branch: "balls/tasks".to_owned(),
}),
);
assert_eq!(
model.holding.as_deref().expect("the wall answered").len(),
1
);
assert_eq!(model.marks.as_deref(), Some("balls/tasks"));
}
#[test]
fn closing_the_pane_keeps_what_the_channels_said() {
let mut model = boarded();
model.close_lookup();
assert_eq!(model.columns.len(), 1);
assert_eq!(model.bindings.len(), 1);
assert!(model.holding.is_some());
}