use super::super::{NO_NAME_HERE, acts, line, render};
use crate::paint_probe::{fills_of, frame::Window};
use crate::reply::roster::WsRow;
use crate::test_support::window::{click, own, seated, seen, wall};
use crate::ui::theme::{BRAND, INK_FAINT, INK_WEAK, RAISED, RULE, State, accent};
use crate::ui::{Channel, Chunk, Model};
fn fills(window: &Window, body: impl FnMut(&egui::Context)) -> Vec<(egui::Rect, egui::Color32)> {
fills_of(&window.frame(Vec::new(), body))
}
fn shown(window: &Window, model: &mut Model) -> Vec<(egui::Rect, egui::Color32)> {
fills(window, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, model));
})
}
fn ruled(fills: &[(egui::Rect, egui::Color32)], ink: egui::Color32) -> bool {
fills
.iter()
.any(|(rect, fill)| *fill == ink && rect.width() <= RULE + 0.5)
}
#[test]
fn an_asking_wall_wears_the_attention_rule_and_a_running_one_the_working_rule() {
let mut model = Model {
roster: vec![Chunk {
walls: vec![
WsRow {
attention: 3,
..wall("asking")
},
WsRow {
running: true,
..wall("busy")
},
],
..own()
}],
..Model::default()
};
let window = Window::new();
let painted = shown(&window, &mut model);
for state in [State::Attention, State::Working] {
assert!(ruled(&painted, accent(state)), "{state:?} stands as a rule");
}
}
#[test]
fn the_aimed_row_is_raised_and_wears_the_brand_rule() {
let mut model = seated();
let window = Window::new();
let painted = shown(&window, &mut model);
assert!(
painted.iter().any(|(_, fill)| *fill == RAISED),
"the aimed row is raised"
);
assert!(ruled(&painted, BRAND), "and wears the brand rule");
}
fn queue_ink(model: &mut Model) -> Option<egui::Color32> {
let window = Window::new();
seen(&window, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| acts::render(ui, model));
})
.into_iter()
.find(|run| run.text == crate::ui::queue::OPEN)
.map(|run| run.ink)
}
#[test]
fn the_queue_entry_is_green_while_something_waits_and_weak_otherwise() {
let mut quiet = Model::default();
assert_eq!(queue_ink(&mut quiet), Some(INK_WEAK));
let mut asked = Model {
waiting: vec![crate::ui::Asking {
channel: own().channel,
rows: vec![crate::test_support::window::waiting("home", "c-1")],
}],
..Model::default()
};
assert_eq!(queue_ink(&mut asked), Some(accent(State::Attention)));
let mut answered = Model {
waiting: vec![crate::ui::Asking {
channel: own().channel,
rows: Vec::new(),
}],
..Model::default()
};
assert_eq!(queue_ink(&mut answered), Some(INK_WEAK));
let mut rolled = Model {
roster: vec![crate::ui::Chunk {
walls: vec![crate::reply::roster::WsRow {
attention: 2,
..wall("home")
}],
..own()
}],
..Model::default()
};
assert_eq!(queue_ink(&mut rolled), Some(accent(State::Attention)));
}
#[test]
fn a_row_no_entry_names_is_faint_and_takes_no_click() {
let mut model = Model {
roster: vec![Chunk {
channel: Channel {
name: "home".to_owned(),
named_there: Some("personal".to_owned()),
dials: None,
},
walls: vec![wall("somebody-elses")],
..Chunk::default()
}],
..Model::default()
};
let label = format!("{} — {NO_NAME_HERE}", line(&wall("somebody-elses")));
let window = Window::new();
let ink = seen(&window, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, &mut model));
})
.into_iter()
.find(|run| run.text == label)
.map(|run| run.ink);
assert_eq!(ink, Some(INK_FAINT), "{label}");
click(&window, &label, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, &mut model));
});
assert_eq!(model.aim, None, "a click on it aims nothing");
}
#[test]
fn the_two_bands_are_compact_strips_at_the_rosters_width() {
let mut model = seated();
let window = Window::sized(crate::ui::shell::policy::CONVS, 600.0);
let runs = seen(&window, |ctx| {
egui::CentralPanel::default().show(ctx, |ui| render(ui, &mut model));
});
let lines = |words: &[&str]| -> usize {
let mut tops: Vec<f32> = words
.iter()
.map(|word| {
let run = runs
.iter()
.find(|run| run.text == *word)
.unwrap_or_else(|| panic!("{word:?} is on the glass whole"));
run.laid.min.y
})
.collect();
tops.sort_by(f32::total_cmp);
tops.dedup_by(|a, b| (*a - *b).abs() < 1.0);
tops.len()
};
let window_acts = [
acts::REFRESH,
crate::ui::queue::OPEN,
crate::ui::commands::OPEN,
crate::ui::trail::OPEN,
crate::ui::board::OPEN,
crate::ui::find::OPEN,
];
assert!(lines(&window_acts) <= 2, "the window's strip");
let wall_acts = [
super::super::PIN,
crate::ui::enroll::OPEN,
crate::ui::tuning::OPEN,
crate::ui::login::OPEN,
crate::ui::clients::OPEN,
crate::ui::config::OPEN,
crate::ui::fleet::OPEN,
crate::ui::unmake::OPEN,
];
assert!(lines(&wall_acts) <= 3, "the wall's strip");
}