use super::super::{NO_NAME_HERE, 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, 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");
}
#[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 a_busy_wall_at_280_points_still_says_its_state() {
let mut model = Model {
roster: vec![Chunk {
walls: vec![WsRow {
attention: 5,
agents: 6,
running: true,
..wall("home")
}],
..own()
}],
..Model::default()
};
let window = Window::sized(800.0, 600.0);
let glyphs: Vec<String> = seen(&window, |ctx| {
egui::SidePanel::left("roster")
.exact_width(280.0)
.show(ctx, |ui| render(ui, &mut model));
})
.into_iter()
.map(|seen| seen.text)
.collect();
let row = glyphs
.iter()
.find(|text| text.starts_with("home "))
.unwrap_or_else(|| panic!("the wall's row is on the glass: {glyphs:?}"));
assert!(
row.contains("5 waiting running"),
"the state is cut: {row:?}"
);
}