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

nordisk/facett

facett-calendar/tests/matrix.rs

//! **The functional matrix cell for facett-calendar** — the pane emitted NO
//! testmatrix row of either aspect before this file (see
//! `.nornir/docs/test-matrix-inventory-history.md`, "~10 panes emit no cell").
//!
//! ONE call: the shared generic-`Facet` probe in `facett_core::harness`
//! headless-renders the month grid, drives the JSON robot seam and
//! `facett_core::testmatrix::probe_and_emit` turns the result into the
//! `headless_render` + `responds_to_input` rows. No bespoke harness, no twinned
//! sink (L5).

use facett_calendar::Calendar;

#[test]
fn calendar_probe_emits_render_and_input_cells() {
    let mut view = Calendar::local();

    let script = [
        r#"{"select":"2026-06-15"}"#, // the two-event day (headless cell click)
        r#""next_month""#,            // walk forward — and the selection leaves the month
        r#""prev_month""#,            // back to June
    ];
    let probe = facett_core::testmatrix::probe_and_emit("facett-calendar", &mut view, &script);

    assert!(probe.drew(), "the month grid must tessellate to vertices");
    assert!(probe.cardinality() > 0, "state_json reports the events");
    assert!(probe.responded(), "update_json must drive state — a dead seam is a regression");

    // EXACT transitions, not "something moved".
    assert_eq!(probe.initial_state["month"], 6);
    assert_eq!(probe.initial_state["year"], 2026);
    assert_eq!(probe.initial_state["events"].as_array().unwrap().len(), 3);
    assert_eq!(probe.steps[0].state["selected"], "2026-06-15");
    assert_eq!(probe.steps[1].state["month"], 7, "next_month advances");
    assert_eq!(probe.steps[2].state["month"], 6, "prev_month returns");
}

/// RED-when-broken: `select_date` must reject a date outside the displayed month
/// (and garbage), so a robot script cannot fake `responds_to_input` with a date
/// the grid does not even paint.
#[test]
fn select_date_rejects_off_month_and_garbage() {
    let mut c = Calendar::local();
    assert!(!c.select_date("not-a-date"));
    assert!(!c.select_date("2026-07-01"), "July is not the displayed month");
    assert_eq!(c.selected_date(), None);
    assert!(c.select_date("2026-06-15"));
    assert_eq!(c.selected_date().map(|d| d.to_string()).as_deref(), Some("2026-06-15"));
}

/// The December→January rollover crosses the year boundary in both directions.
#[test]
fn month_navigation_wraps_the_year_in_both_directions() {
    let mut c = Calendar::new("Nav", 2026, 12);
    c.next_month();
    assert_eq!(c.displayed(), (2027, 1));
    c.prev_month();
    assert_eq!(c.displayed(), (2026, 12));
    let mut c = Calendar::new("Nav", 2026, 1);
    c.prev_month();
    assert_eq!(c.displayed(), (2025, 12));
}