use crate::paint_probe::frame::Window;
use crate::test_support::window::seated;
use crate::ui::Model;
use crate::ui::composer;
use crate::ui::theme::glyph;
use serde_json::json;
fn unselected() -> Model {
Model {
conversation: None,
..seated()
}
}
fn field_height(window: &Window, body: &mut impl FnMut(&egui::Context), word: &str) -> f32 {
let output = window.frame(Vec::new(), body);
let act = crate::paint_probe::seen_of(&output)
.into_iter()
.find(|run| run.text == word)
.expect("the act is on the glass");
crate::paint_probe::fills_of(&output)
.into_iter()
.find(|(rect, _)| rect.contains_rect(act.laid) && rect.width() > 300.0)
.expect("the act stands inside the field")
.0
.height()
}
#[test]
fn the_start_field_stands_as_tall_as_the_deposit_s_with_its_act_inside_it() {
let said = {
let window = Window::sized(400.0, 400.0);
let mut model = seated();
field_height(
&window,
&mut |ctx: &egui::Context| {
egui::CentralPanel::default().show(ctx, |ui| composer::render(ui, &mut model));
},
glyph::PROMPT,
)
};
let begun = {
let window = Window::sized(400.0, 400.0);
let mut model = unselected();
field_height(
&window,
&mut |ctx: &egui::Context| {
egui::CentralPanel::default().show(ctx, |ui| composer::render(ui, &mut model));
},
glyph::PROMPT,
)
};
assert!(
(said - begun).abs() < f32::EPSILON,
"one field in both modes: the deposit stands {said} and the start {begun}"
);
}
#[test]
fn the_start_control_still_carries_both_of_its_acts() {
let harness = crate::snapshot::seat(unselected(), 1400.0, 900.0);
let inventory = crate::snapshot::parity::inventory(&harness);
for op in [crate::verbs::PREPARE, crate::verbs::PROMPT] {
assert!(inventory.contains(op), "{op:?} is tagged: {inventory:?}");
}
}
#[test]
fn the_plan_verb_writes_the_born_on_role_onto_the_fire_and_nothing_else_does() {
for (planning, born) in [(false, None), (true, Some(json!("planner")))] {
let mut model = unselected();
model.draft = "do the thing".to_owned();
if planning {
assert!(crate::ui::slash::fire(
&mut model,
crate::ui::slash::PLAN,
""
));
}
let window = Window::sized(400.0, 400.0);
let mut body = |ctx: &egui::Context| {
egui::CentralPanel::default().show(ctx, |ui| composer::render(ui, &mut model));
};
window.frame(Vec::new(), &mut body);
window.focus(egui::Id::new(crate::ui::keys::BOX_ID));
window.frame(
vec![crate::paint_probe::frame::press(egui::Key::Enter)],
&mut body,
);
assert_eq!(
model.plan, planning,
"the seat holds what it was pressed to"
);
model.absorb(
&crate::test_support::window::own().channel,
crate::reply::read(&json!({"ok": true, "kind": "prepared",
"prepared": {"workspace": "home", "goal": ""}})),
);
let fire = model
.outbox
.iter()
.find(|said| said.envelope["op"] == json!("prompt"))
.expect("the fire is composed from the receipt");
assert_eq!(
fire.envelope["prepared"].get(crate::verbs::start::ROLE),
born.as_ref(),
"planning: {planning}"
);
}
}