facett-manual/tests/robot_variants.rs
//! **Robot render scenario for the MERGED Manual pane's two variants** (`egui_kittest`).
//!
//! Builds the REAL [`facett_manual::ManualPane`] from the crate's OWN embedded content
//! ([`ManualPane::embedded`]) and drives its real `ui` through the kittest harness,
//! asserting off the live AccessKit tree + `state_json`:
//!
//! 1. **Default variant is Typeset (SVG)** — a fresh embedded pane reports
//! `variant == "typeset"`, carries a typeset book (`has_typeset`,
//! `typeset_page_count >= 1`), and the docview book's TOC (e.g. "Reading the
//! manual") paints — proving the SVG variant drives facett-docview underneath
//! (the "inside docview" mounting context).
//! 2. **The toggle switches to Markdown** — after flipping to `Variant::Markdown` the
//! pane reports `variant == "markdown"`, the markdown category sidebar paints
//! (the "standalone manual pane" context), and the typeset book TOC is gone.
//! 3. **All content is embedded** — nothing on disk is touched; every page and doc
//! comes from `include_bytes!`/`include_str!` (asserted in the unit tests too).
use std::sync::{Arc, Mutex};
use egui_kittest::kittest::Queryable;
use egui_kittest::Harness;
use facett_manual::{ManualPane, Variant};
/// Render the SAME persistent embedded pane every frame (so variant switches
/// accumulate across `run()`s, like the live app).
fn harness_over(pane: Arc<Mutex<ManualPane>>) -> Harness<'static> {
Harness::builder().with_size(egui::vec2(1000.0, 760.0)).build_ui(move |ui| {
pane.lock().unwrap().ui(ui);
})
}
#[test]
fn embedded_pane_defaults_to_typeset_svg_then_toggles_to_markdown() {
let pane = Arc::new(Mutex::new(ManualPane::embedded("facett")));
let mut harness = harness_over(Arc::clone(&pane));
harness.run();
// ── 1. Default is the pretty Typeset (SVG) variant, backed by the docview book ──
{
let st = pane.lock().unwrap().state_json();
assert_eq!(st["variant"], serde_json::json!("typeset"), "default variant is typeset (SVG)");
assert_eq!(st["has_typeset"], serde_json::json!(true), "a typeset book is present");
assert!(
st["typeset_page_count"].as_u64().unwrap_or(0) >= 1,
"the embedded typeset book has pages"
);
}
// A typeset-only signal: the docview book's TOC chapter (the SVG variant mounts
// facett-docview, whose sidebar lists these chapters).
assert!(
harness.query_by_label("Reading the manual").is_some(),
"the typeset book's TOC paints (docview drives the SVG variant)"
);
// ── 2. Toggle to Markdown (headless twin of the header variant toggle) ──
pane.lock().unwrap().set_variant(Variant::Markdown);
harness.run();
{
let st = pane.lock().unwrap().state_json();
assert_eq!(st["variant"], serde_json::json!("markdown"), "toggled to the markdown variant");
}
// A markdown-only signal: the category sidebar header the markdown variant draws.
assert!(
harness.query_by_label("🔰 For idiots (start here)").is_some(),
"the markdown category sidebar paints after the toggle"
);
// …and the typeset book's TOC is no longer shown (we left the docview variant).
assert!(
harness.query_by_label("Reading the manual").is_none(),
"the typeset book is not shown in the markdown variant"
);
// testmatrix cell — the merged Manual pane defaults to typeset (SVG) and toggles
// to markdown, both variants embedded (surfaces in `--features testmatrix`).
facett_core::testmatrix::emit(
"facett-manual/variants",
"embedded_pane_defaults_to_typeset_svg_then_toggles_to_markdown",
true,
"merged Manual pane: default typeset (SVG) → toggle → markdown, both compiled-in",
);
}