facett-korp/tests/search_render.rs
//! Real `egui_kittest` render + click proof for the korp **SearchPane** — the
//! visible (watch-on-DISPLAY) leg of the robot scenario the headless `update_json`
//! drive covers (Palantir pillar P5 / gap S-1, global object search). The pane
//! paints its query box + results list, and a real click on the *Search* button
//! drives the Elm loop to emit a `Query` effect.
use std::sync::{Arc, Mutex};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use facett_core::{Elm, Panel};
use facett_korp::{SearchEffect, SearchMsg, SearchPane, SearchRow};
fn seeded() -> SearchPane {
let mut p = SearchPane::new("Search");
// Pre-load the query + a host-fed ranked result so the list paints.
p.update(SearchMsg::SetQuery("volvo".into()));
p.sync_results(
"volvo",
vec![
SearchRow::new("Company/5560160680", "Company", "Volvo", 100, "name"),
SearchRow::new("Vessel/265547890", "Vessel", "Sea Star", 30, "property:owner"),
],
7,
);
p
}
#[test]
fn search_pane_paints_the_controls_and_results() {
let mut pane = seeded();
let mut harness = Harness::builder().with_size(egui::vec2(520.0, 420.0)).build_ui(move |ui| {
Panel::ui(&mut pane, ui);
});
harness.run();
assert!(harness.query_by_label("🔎 Search").is_some(), "the query bar painted");
// The top ranked result rode into the AccessKit tree.
assert!(
harness.query_by_label("Volvo — Company (name)").is_some(),
"the ranked result row painted",
);
}
#[test]
fn clicking_search_emits_a_query_effect() {
let effects: Arc<Mutex<Vec<SearchEffect>>> = Arc::new(Mutex::new(Vec::new()));
let sink = Arc::clone(&effects);
let mut pane = seeded();
let mut harness = Harness::builder().with_size(egui::vec2(520.0, 420.0)).build_ui(move |ui| {
// The host wiring: view emits msgs, update yields effects → record them.
let msgs = pane.view(ui);
for m in msgs {
for e in pane.update(m) {
sink.lock().unwrap().push(e);
}
}
});
harness.run();
harness.get_by_label("🔎 Search").click();
harness.run();
let got = effects.lock().unwrap();
assert!(
matches!(got.first(), Some(SearchEffect::Query(q)) if q == "volvo"),
"a real click on Search drove the Elm loop to emit Query(\"volvo\"), got {got:?}",
);
}
#[test]
fn search_pane_paints_after_json_drive() {
let mut pane = seeded();
Panel::update_json(&mut pane, r#"{"select":0}"#);
assert_eq!(Panel::state_json(&pane)["selected_id"], "Company/5560160680");
let mut harness = Harness::builder().with_size(egui::vec2(520.0, 420.0)).build_ui(move |ui| {
Panel::ui(&mut pane, ui);
});
harness.run();
let _ = SearchMsg::Clear; // msg type is public/constructible
}