use super::{CHAT_FLOOR, Column, SIDE_FLOOR, Shape, shape, widths};
use crate::ui::Pane;
#[test]
fn the_list_panes_yield_to_the_conversation_s_floor_and_then_stop() {
assert_eq!(widths(1200.0), (280.0, 320.0), "wide enough for both");
assert_eq!(
widths(1020.0),
(280.0, 320.0),
"exactly enough is still enough"
);
let (roster, convs) = widths(900.0);
assert!(
(roster - 224.0).abs() < 0.5 && (convs - 256.0).abs() < 0.5,
"the loss is shared in proportion: {roster}, {convs}"
);
assert!(
900.0 - roster - convs >= CHAT_FLOOR,
"the conversation kept its floor"
);
assert_eq!(
widths(400.0),
(SIDE_FLOOR, SIDE_FLOOR),
"past their own floor the list panes stop yielding"
);
}
#[test]
fn the_shape_turns_over_at_the_width_the_yield_can_no_longer_keep_the_floor() {
for wide in [1400.0_f32, 900.0, 720.0] {
let (roster, convs) = widths(wide);
assert_eq!(
shape(wide),
Shape::Broad { roster, convs },
"at {wide} the conversation still gets its floor"
);
}
for narrow in [719.0_f32, 700.0, 400.0, 120.0] {
assert_eq!(
shape(narrow),
Shape::Narrow,
"at {narrow} the three columns cannot stand together"
);
}
}
#[test]
fn a_window_of_any_width_at_all_is_promised_a_shape() {
for width in [0.0_f32, 1.0, 400.0, 4000.0] {
let (roster, convs) = widths(width);
assert!(
roster >= SIDE_FLOOR && convs >= SIDE_FLOOR,
"the yield never goes under the floor: {width}"
);
assert!(
matches!(shape(width), Shape::Broad { .. } | Shape::Narrow),
"there is an answer at {width}"
);
}
}
#[test]
fn each_column_is_named_by_the_pane_it_shows() {
assert_eq!(
Column::all().map(Column::word),
[
crate::ui::roster::HEADING,
crate::ui::convs::HEADING,
crate::ui::chat::HEADING,
]
);
}
#[test]
fn each_column_says_which_list_the_arrows_walk() {
assert_eq!(Column::Channels.arrows(), Pane::Roster);
assert_eq!(Column::Conversations.arrows(), Pane::Conversations);
assert_eq!(Column::Conversation.arrows(), Pane::Conversations);
}
#[test]
fn a_step_sideways_moves_one_column_and_stops_at_the_ends() {
assert_eq!(Column::Channels.stepped(1), Column::Conversations);
assert_eq!(Column::Conversations.stepped(1), Column::Conversation);
assert_eq!(Column::Conversation.stepped(1), Column::Conversation);
assert_eq!(Column::Conversation.stepped(-1), Column::Conversations);
assert_eq!(Column::Conversations.stepped(-1), Column::Channels);
assert_eq!(Column::Channels.stepped(-1), Column::Channels);
}
#[test]
fn the_window_opens_on_the_channels_column() {
assert_eq!(Column::default(), Column::Channels);
}