snora 0.28.0

iced engine for the Snora GUI framework. Consumes snora-core vocabulary.
Documentation
//! Tests for RFC-046's width exposure.
//!
//! - **Width reaches the closure**: a layout built through
//!   [`responsive_render`] receives a plausible width, checked against a
//!   [`Simulator`] constructed at a known, explicit window size.
//! - **Composition matches**: the z-stack produced through
//!   [`responsive_render`] behaves identically to [`crate::render::render`]
//!   for an equivalent layout — proven by exercising the *same*
//!   `render_semantics.rs`-style interaction (a body button click reaches
//!   its message) through the `Responsive`-wrapped path. This is possible
//!   because [`responsive_render`] calls [`crate::render::render`]
//!   directly (see the module documentation) — there is only one z-stack
//!   implementation to test.
//!
//! On coverage: `iced_test`'s simulator can exercise the closure being
//! called with a real width (both tests below prove this), but it cannot
//! exercise an *actual resize event* changing that width mid-session —
//! `Simulator` builds a `UserInterface` once, at a fixed size, and does
//! not simulate `window::Event::Resized`. That property (does the layout
//! actually rebuild when the window resizes) is demonstrated instead by
//! the runnable example under `examples/responsive/`, observable by
//! resizing the window — not asserted here, since asserting it would
//! require a capability this harness does not have. Stated explicitly per
//! the Handoff's coverage-honesty requirement, rather than claimed.

use super::*;
use iced::widget::{button, text};
use iced_test::{Simulator, simulator};
use std::sync::{Arc, Mutex};

#[derive(Debug, Clone, PartialEq, Eq)]
enum Msg {
    Pressed,
}

#[test]
fn width_reaches_the_closure() {
    let captured: Arc<Mutex<Option<f32>>> = Arc::new(Mutex::new(None));
    let captured_for_closure = Arc::clone(&captured);

    let element = responsive_render(move |width: f32| {
        *captured_for_closure.lock().unwrap() = Some(width);
        AppLayout::new(text("body").into())
    });

    // Fixed, known window size so the assertion is precise rather than
    // "some positive number."
    let _sim: Simulator<'_, Msg> =
        Simulator::with_size(iced::Settings::default(), Size::new(800.0, 600.0), element);

    let width = captured
        .lock()
        .unwrap()
        .expect("responsive_render's closure must be called during layout");
    assert!(
        (0.0..=800.0).contains(&width),
        "width should be a plausible fraction of the 800px window, got {width}"
    );
}

#[test]
fn composition_matches_render_for_an_equivalent_layout() {
    let btn = |label: &'static str| -> Element<'static, Msg> {
        button(text(label)).on_press(Msg::Pressed).into()
    };

    let element = responsive_render(move |_width| AppLayout::new(btn("body")));

    let mut sim = simulator(element);
    sim.click("body").expect("body button should be reachable through responsive_render, exactly as through render() directly");
    let msgs: Vec<Msg> = sim.into_messages().collect();

    assert_eq!(
        msgs,
        vec![Msg::Pressed],
        "responsive_render must produce the same interactive z-stack as render()"
    );
}