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

nordisk/facett

facett-korp/tests/timeline_render.rs

//! Real `egui_kittest` render + click proof for the korp **TimelinePane** — the
//! visible (watch-on-DISPLAY) leg of the robot scenario the headless `update_json`
//! drive covers. The pane paints its histogram + readout, and a real click on the
//! *Clear brush* button drives the Elm loop to emit a `ClearWindow` effect.

use std::sync::{Arc, Mutex};

use egui_kittest::kittest::Queryable;
use egui_kittest::Harness;
use facett_core::{Elm, Panel};
use facett_korp::{TimelineBar, TimelineEffect, TimelinePane};

fn seeded(window: Option<(i64, i64)>, in_window: u64, subjects: usize) -> TimelinePane {
    let mut p = TimelinePane::new("Timeline");
    p.sync(
        vec![
            TimelineBar::new(0, 100, 3),
            TimelineBar::new(100, 200, 5),
            TimelineBar::new(200, 300, 1),
        ],
        Some((0, 300)),
        window,
        in_window,
        subjects,
    );
    p
}

#[test]
fn timeline_pane_paints_the_histogram_and_readout() {
    let mut pane = seeded(None, 9, 4);
    let mut harness = Harness::builder().with_size(egui::vec2(560.0, 320.0)).build_ui(move |ui| {
        Panel::ui(&mut pane, ui);
    });
    harness.run();
    assert!(harness.query_by_label("korp · Timeline").is_some(), "the heading painted");
    assert!(
        harness.query_by_label("9 events in window · 4 subjects").is_some(),
        "the readout painted the in-window count + subject payload size",
    );
}

#[test]
fn clicking_clear_brush_emits_a_clear_window_effect() {
    let effects: Arc<Mutex<Vec<TimelineEffect>>> = Arc::new(Mutex::new(Vec::new()));
    let sink = Arc::clone(&effects);
    // A brushed pane shows the "Clear brush" button.
    let mut pane = seeded(Some((100, 200)), 5, 2);
    let mut harness = Harness::builder().with_size(egui::vec2(560.0, 320.0)).build_ui(move |ui| {
        let msgs = pane.view(ui);
        for m in msgs {
            for e in pane.update(m) {
                sink.lock().unwrap().push(e);
            }
        }
    });
    harness.run();
    harness.get_by_label("⤢ Clear brush").click();
    harness.run();

    let got = effects.lock().unwrap();
    assert!(
        matches!(got.first(), Some(TimelineEffect::ClearWindow)),
        "a real click on Clear brush drove the Elm loop to emit ClearWindow, got {got:?}",
    );
}

#[test]
fn timeline_pane_paints_after_json_brush() {
    let mut pane = seeded(None, 9, 4);
    Panel::update_json(&mut pane, r#"{"brush_bucket":1}"#);
    assert_eq!(Panel::state_json(&pane)["last_action"], "brush bucket [100, 200]");
    let mut harness = Harness::builder().with_size(egui::vec2(560.0, 320.0)).build_ui(move |ui| {
        Panel::ui(&mut pane, ui);
    });
    harness.run();
    assert!(harness.query_by_label("korp · Timeline").is_some());
}