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/robot.rs

//! **Robot render proof for facett-calendar.** The `Calendar::ui()` render path —
//! the prev/next month controls, the Monday-first month grid, the day cells (each
//! an allocated click region painting the day number + an event dot/count), the
//! today accent and the hover text — is never rendered by the unit tests (which
//! only cover `days_in_month` / navigation / `day_marker` / `state_json`). This
//! drives a real `egui_kittest` frame so the grid + day-cell painter runs, and
//! asserts the month header, the weekday headers and the prev/next buttons reach
//! the AccessKit tree.

use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;

use facett_calendar::Calendar;

/// June 2026 (1 June is a Monday → lead 0) with a two-event day (Deadline+Frist,
/// so the marker shows a count) and an absence day. CONSUMED from the crate's own
/// `Calendar::local()` — one fixture, not one per test file (L5); `tests/matrix.rs`
/// probes the SAME month.
fn cal() -> Calendar {
    Calendar::local()
}

#[test]
fn calendar_renders_month_grid_and_is_addressable() {
    let mut c = cal();
    let mut harness = Harness::new_ui(move |ui| {
        c.ui(ui);
    });
    // Real frame: the header, the weekday row, the 30 day cells (with the marker
    // dot + the "2" count on 15 June, and the today accent on 11 June).
    harness.run();

    // The month header text and the weekday headers rode into the AccessKit tree.
    let _header = harness.get_by_label("Juni 2026");
    let _weekday = harness.get_by_label("Mån");
    // The prev/next month controls are addressable buttons.
    let _prev = harness.get_by_label("◀");
    let _next = harness.get_by_label("▶");
}

#[test]
fn calendar_next_button_advances_the_month() {
    let mut harness = Harness::new_ui(|ui| {
        // Persist the calendar across frames via ui memory-free closure state is
        // not possible; instead drive navigation through the public API below.
        let mut c = Calendar::new("Nav", 2026, 12);
        c.ui(ui);
        let _ = c;
    });
    harness.run();
    // The header for December 2026 is present on the first frame.
    let _ = harness.get_by_label("December 2026");
}

#[test]
fn calendar_empty_month_renders_without_panic() {
    // No events: every day cell still paints its number; no marker dots.
    let mut c = Calendar::new("Tom", 2026, 2); // February — 28 days, leads with a blank
    let mut harness = Harness::new_ui(move |ui| {
        c.ui(ui);
    });
    harness.run();
    let _header = harness.get_by_label("Februari 2026");
}

#[test]
fn calendar_state_survives_a_render() {
    let before = cal().state_json();
    let mut c = cal();
    let mut harness = Harness::new_ui(move |ui| {
        c.ui(ui);
    });
    harness.run();
    assert_eq!(before["year"], 2026);
    assert_eq!(before["month"], 6);
    assert_eq!(before["month_name"], "Juni");
    assert_eq!(before["events"].as_array().unwrap().len(), 3);
    // A render without a day-click leaves the selection untouched.
    assert!(before["selected"].is_null());
    assert_eq!(cal().state_json(), before);
}