use super::super::{DISMISS, render};
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, painted, seated, seen};
use crate::ui::{Model, Notice};
#[test]
fn a_notice_stands_where_the_content_would_have_been_and_says_whose_it_is() {
for (notice, expected) in [
(
Notice::Refused("unknown workspace \"hoem\"".to_owned()),
"the engine refused: unknown workspace \"hoem\"",
),
(
Notice::Unreadable("cannot paint a \"board\" answer".to_owned()),
"this seat could not read the answer: cannot paint a \"board\" answer",
),
] {
let mut model = Model {
notice: Some(notice),
..seated()
};
let shown = painted(&mut model);
assert!(shown.contains(expected), "{expected:?}:\n{shown}");
assert!(
shown.contains("home 2 conversations (named)"),
"a refusal about one pane does not stop the others:\n{shown}"
);
}
}
#[test]
fn a_notice_can_be_put_down() {
let mut model = Model {
notice: Some(Notice::Refused("no".to_owned())),
..seated()
};
let window = Window::new();
click(&window, DISMISS, |ctx| render(ctx, &mut model));
assert_eq!(model.notice, None);
}
#[test]
fn a_long_refusal_wraps_and_its_remedy_reaches_the_glass() {
let said = format!(
"no wire provisioned at /home/u/.local/share/lernie/wire: {}",
crate::channel::material::Whose::Own.remedy()
);
let mut model = Model {
notice: Some(Notice::Unreachable(said.clone())),
..seated()
};
let window = Window::sized(900.0, 600.0);
window.text(|ctx| render(ctx, &mut model));
let bar = seen(&window, |ctx| render(ctx, &mut model))
.into_iter()
.find(|run| run.text.starts_with("this seat could not reach it"))
.expect("the bar is on the glass");
assert!(
bar.laid.width() <= 900.0,
"the run was laid inside the window rather than past it: {:?}",
bar.laid
);
assert!(
bar.shown.width() >= bar.laid.width() - 0.5,
"and nothing was clipped off its end: laid {:?}, shown {:?}",
bar.laid,
bar.shown
);
assert!(
bar.text.ends_with("the seat mints nothing"),
"so the remedy's last words are on the glass: {:?}",
bar.text
);
}
#[test]
fn a_notice_wears_its_state_s_ink() {
use crate::ui::theme::{State, accent};
for (notice, ink) in [
(Notice::Refused("no".to_owned()), accent(State::Error)),
(
Notice::Said("the floor stands".to_owned()),
accent(State::Annotation),
),
] {
let mut model = Model {
notice: Some(notice.clone()),
..seated()
};
let window = Window::new();
let run = seen(&window, |ctx| render(ctx, &mut model))
.into_iter()
.find(|run| run.text == notice.line())
.expect("the notice is on the glass");
assert_eq!(run.ink, ink, "{notice:?}");
}
}