use super::{CHAT_FLOOR, CONVS, Column, SIDE_FLOOR, Shape, shape, widths};
const WORTH: f32 = CONVS + CHAT_FLOOR;
#[test]
fn the_list_pane_yields_to_the_conversation_s_floor_and_then_stops() {
assert!(
(widths(WORTH) - CONVS).abs() < 0.01,
"every column worth exactly what it is worth"
);
let list = widths(600.0);
assert!(
(list - 180.0).abs() < 0.5,
"the whole loss is the list's: {list}"
);
assert!(
600.0 - list >= CHAT_FLOOR,
"the conversation kept its floor"
);
let floored = widths(400.0);
assert!(
(floored - SIDE_FLOOR).abs() < f32::EPSILON,
"past its own floor the list pane stops yielding: {floored}"
);
}
#[test]
fn a_window_wider_than_every_column_s_worth_grows_both_together() {
let list = widths(1400.0);
assert!(list > CONVS, "{list}");
assert!(
1400.0 - list > CHAT_FLOOR,
"and the conversation grows too, not only the list"
);
let mut before = 0.0;
for width in [WORTH, 900.0, 1400.0, 2560.0] {
let list = widths(width);
assert!(list > before, "{width}: {list} is not past {before}");
before = list;
}
}
#[test]
fn the_yield_and_the_growth_meet_at_the_width_every_column_is_worth() {
let below = widths(WORTH - 1.0);
let at = widths(WORTH);
let above = widths(WORTH + 1.0);
assert!(below < at && at < above, "{below}, {at}, {above}");
assert!((at - CONVS).abs() < 0.01, "{at}");
}
#[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, WORTH, SIDE_FLOOR + CHAT_FLOOR] {
assert_eq!(
shape(wide),
Shape::Broad { list: widths(wide) },
"at {wide} the conversation still gets its floor"
);
}
for narrow in [SIDE_FLOOR + CHAT_FLOOR - 1.0, 500.0, 400.0, 120.0] {
assert_eq!(
shape(narrow),
Shape::Narrow,
"at {narrow} the two 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] {
assert!(
widths(width) >= 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::chat::HEADING]
);
}
#[test]
fn a_step_sideways_moves_one_column_and_stops_at_the_ends() {
assert_eq!(Column::Engines.stepped(1), Column::Conversation);
assert_eq!(Column::Conversation.stepped(1), Column::Conversation);
assert_eq!(Column::Conversation.stepped(-1), Column::Engines);
assert_eq!(Column::Engines.stepped(-1), Column::Engines);
}
#[test]
fn the_window_opens_on_the_engines_column() {
assert_eq!(Column::default(), Column::Engines);
}