Your browser sucks, JavaScript disabled! Gunnar's console needs JavaScript and WebAssembly. Git over SSH on port 2222 does not.

nordisk/facett

facett-demo/tests/effects_showcase.rs

//! **T1.3 SHOWCASE matrix gate** — prove, as DATA, that the new rendering (glass
//! chrome + bloom-glow + smooth-scroll + tween motion) is actually wired ON in the
//! demo, and that it degrades correctly under the effects-off Device preset.
//!
//! GPU-free: drives the whole demo through `draw_app` on an egui_kittest harness
//! (no `render()` call, so no GPU is needed) and reads everything back from
//! `state_json`. The companion `examples/robot_drive.rs` adds the actual PNG
//! screenshot leg on top of these same assertions.
//!
//! FAIL-ON-BUG / PASS-ON-FIX: revert the demo to `EffectsPolicy::None` / an
//! `Opaque` surface / `chrome = false`, or drop the motion wiring, and these trip.

use facett_demo::DemoState;

/// Run the demo headless for a few frames on the `jobs` tab with a row selected,
/// then return its `state_json`. No `render()` → no GPU.
fn drive_jobs_tab() -> serde_json::Value {
    let mut demo = DemoState::new();
    demo.show_about = false;
    assert!(demo.deck.set_active_by_title("jobs"), "the demo has a `jobs` tab");

    // Select the first job row so its selection cross-fade is exercised on render.
    if let Some(id) = demo.state_json()["deck"]["facets"]["jobs"]["jobs"]
        .get(0)
        .and_then(|r| r["id"].as_str())
        .map(str::to_string)
        && let Some(jv) = demo.deck.facet_mut::<facett_jobview::JobList>("jobs")
    {
        jv.select(Some(id));
    }

    let mut harness = egui_kittest::Harness::builder()
        .with_size(egui::vec2(1100.0, 760.0))
        .build_ui_state(|ui, demo: &mut DemoState| demo.draw_app(ui), demo);
    harness.run_steps(6);
    harness.state().state_json()
}

#[test]
fn demo_renders_glass_chrome_bloom_and_motion_as_data() {
    let s = drive_jobs_tab();

    // The glass/card chrome wrap around the active facet is ON.
    assert_eq!(s["deck"]["fx"]["chrome"].as_bool(), Some(true), "deck glass chrome wired ON");

    // Full-effects preset (non-`None`) with a NON-DEFAULT glass surface.
    let look = &s["look"];
    assert_eq!(look["effects"].as_str(), Some("Full"), "demo theme is full-effects (non-None)");
    assert_eq!(look["allows_transparency"].as_bool(), Some(true), "transparency (glass) allowed");
    assert_eq!(look["allows_decorative_motion"].as_bool(), Some(true), "decorative motion allowed");
    let surface = &look["surface"];
    assert_ne!(surface.as_str(), Some("Opaque"), "the demo theme declares a NON-default surface");
    assert!(
        surface.get("Frosted").is_some() || surface.get("Tint").is_some(),
        "surface is glass (Frosted/Tint): {surface}"
    );

    // Real motion durations (non-zero ⇒ tween/scroll motion runs).
    assert!(look["motion"]["duration"].as_f64().unwrap_or(0.0) > 0.0, "non-zero motion duration");

    // The rendered `jobs` facet reports live motion state: smooth scroll wired and
    // the selected row's cross-fade tracked (the row-highlight motion is exercised).
    let motion = &s["deck"]["facets"]["jobs"]["motion"];
    assert_eq!(motion["smooth"].as_bool(), Some(true), "jobs row list uses SmoothScroll");
    assert!(motion["scroll_target"].is_number(), "smooth-scroll offset state present");
    assert!(
        motion["sel_fades"].as_u64().unwrap_or(0) >= 1,
        "selected row cross-fade is tracked (motion exercised), got {}",
        motion["sel_fades"]
    );
}

#[test]
fn device_preset_degrades_the_showcase_to_opaque_crisp() {
    let mut demo = DemoState::new();
    demo.show_about = false;
    // The Device preset (effects off, §23) is the last in LookTheme::PRESETS.
    let device_idx = facett::LookTheme::preset_names().iter().position(|n| n == "device").expect("device preset");
    demo.set_look_preset(device_idx);
    assert!(demo.deck.set_active_by_title("jobs"));

    let mut harness = egui_kittest::Harness::builder()
        .with_size(egui::vec2(1100.0, 760.0))
        .build_ui_state(|ui, demo: &mut DemoState| demo.draw_app(ui), demo);
    harness.run_steps(3);
    let s = harness.state().state_json();

    let look = &s["look"];
    assert_eq!(look["preset"].as_str(), Some("device"));
    // Effects off: no transparency, no decorative motion, opaque surface — the
    // glass card degrades to a crisp opaque panel.
    assert_eq!(look["effects"].as_str(), Some("None"), "Device turns effects off");
    assert_eq!(look["allows_transparency"].as_bool(), Some(false), "no glass under Device");
    assert_eq!(look["surface"].as_str(), Some("Opaque"), "surface is opaque under Device");
    assert_eq!(look["motion"]["duration"].as_f64().unwrap_or(-1.0), 0.0, "no decorative motion under Device");
}