use super::{
CLOSE, HEADING, NO_BYTES, NO_LINEAGES, NO_SETTINGS, NOT_ANSWERED, NOT_READ, NOTHING_PICKED,
render,
};
use crate::paint_probe::frame::Window;
use crate::test_support::window::{click, configured, lineage, pane, seated};
use crate::ui::{Configuring, Model};
use crate::verbs::Where;
#[test]
fn a_shut_pane_paints_nothing_and_reports_it() {
let mut model = seated();
let mut stood = true;
let painted = pane(|ui| stood = render(ui, &mut model));
assert!(!stood, "a shut pane reports that it painted nothing");
assert!(!painted.contains(HEADING), "{painted}");
}
#[test]
fn the_three_empty_states_say_three_different_things() {
for (lineages, expected) in [
(None, NOT_ANSWERED),
(Some(Vec::new()), NO_LINEAGES),
(Some(vec![lineage("default")]), "default"),
] {
let mut model = Model {
configuring: Some(Configuring::default()),
lineages,
..seated()
};
let painted = pane(|ui| {
render(ui, &mut model);
});
assert!(painted.contains(expected), "{expected:?}:\n{painted}");
assert!(painted.contains(NOTHING_PICKED), "{painted}");
}
}
#[test]
fn every_destination_the_pane_offers_is_on_the_glass() {
let mut model = configured();
let painted = pane(|ui| {
render(ui, &mut model);
});
for word in [
"brazen",
"litany models",
"cadence",
"default: providers.yaml",
"default: workflow.yaml",
"abcdef1",
] {
assert!(painted.contains(word), "{word:?}:\n{painted}");
}
}
#[test]
fn the_settings_and_the_bytes_are_painted_as_one_answer() {
let mut model = configured();
let painted = pane(|ui| {
render(ui, &mut model);
});
for word in [
"worker.provider",
"gone",
"provider",
"watcher.debounce_ms",
"number 0–10000",
"roles:",
] {
assert!(painted.contains(word), "{word:?}:\n{painted}");
}
}
#[test]
fn a_faulted_setting_carries_the_engine_s_own_sentence() {
let mut model = configured();
let painted = pane(|ui| {
render(ui, &mut model);
});
assert!(
painted.contains("brazen's table has no provider row"),
"{painted}"
);
}
#[test]
fn an_empty_schema_and_an_empty_file_are_two_sentences() {
let mut model = Model {
config: Some(crate::reply::config::Config {
text: String::new(),
settings: Vec::new(),
}),
..configured()
};
let painted = pane(|ui| {
render(ui, &mut model);
});
assert!(painted.contains(NO_SETTINGS), "{painted}");
assert!(painted.contains(NO_BYTES), "{painted}");
}
#[test]
fn a_file_asked_for_and_unanswered_says_so_under_its_own_name() {
let mut model = Model {
config: None,
..configured()
};
let painted = pane(|ui| {
render(ui, &mut model);
});
assert!(painted.contains(NOT_READ), "{painted}");
}
#[test]
fn clicking_a_destination_points_the_pane_at_that_file() {
let window = Window::new();
let mut model = configured();
click(&window, "cadence", |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(model.configured(), Some(Where::Cadence));
assert!(model.outbox.is_empty(), "a read stands rather than posting");
}
#[test]
fn the_close_control_puts_the_pane_down() {
let window = Window::new();
let mut model = configured();
click(&window, CLOSE, |ctx| crate::ui::render(ctx, &mut model));
assert_eq!(model.configuring, None);
}