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

nordisk/facett

facett-markdown/tests/render.rs

//! **CPU render-proof for facett-markdown.** The inline tests cover mention/tag
//! extraction + `state_json`; the `Markdown::ui()` render path (the Edit/Preview
//! toggle, the mention/tag chips, the multiline editor, and the pragmatic Preview
//! renderer) is never executed. This drives real `egui_kittest` frames in **both**
//! modes so the painter runs and the controls ride into the AccessKit tree.

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

use facett_markdown::{Markdown, Mode};

const SRC: &str = "# Release notes\n\n- ping @alice about #overdue\n- **bold** and `code`\n";

#[test]
fn edit_mode_paints_toggle_and_mention_chips() {
    let md = Markdown::new("notes").with_text(SRC);
    // state_json reflects the parsed mentions/tags as data.
    let st = md.state_json();
    assert_eq!(st["mode"], "Edit");
    assert!(st["chars"].as_u64().unwrap() > 30);
    assert_eq!(st["mentions"][0], "alice");
    assert_eq!(st["tags"][0], "overdue");

    let mut md_ui = md;
    let mut harness = Harness::new_ui(move |ui| {
        md_ui.ui(ui);
    });
    harness.run();
    // The mode toggle + the mention/tag chips reached the tree.
    assert!(harness.query_by_label("✎ Edit").is_some(), "the Edit toggle painted");
    assert!(harness.query_by_label("👁 Preview").is_some(), "the Preview toggle painted");
    assert!(harness.query_by_label("@alice").is_some(), "the mention chip painted");
    assert!(harness.query_by_label("#overdue").is_some(), "the tag chip painted");
}

#[test]
fn preview_mode_renders_without_panicking() {
    let mut md = Markdown::new("notes").with_text(SRC);
    md.set_mode(Mode::Preview);
    assert_eq!(md.state_json()["mode"], "Preview");
    let mut harness = Harness::new_ui(move |ui| {
        md.ui(ui);
    });
    harness.run(); // the pragmatic Preview renderer must paint headings/bullets safely
}

#[test]
fn empty_markdown_renders_cleanly() {
    let md = Markdown::new("empty");
    assert_eq!(md.state_json()["chars"], 0);
    assert!(md.state_json()["mentions"].as_array().unwrap().is_empty());
    let mut md_ui = md;
    let mut harness = Harness::new_ui(move |ui| {
        md_ui.ui(ui);
    });
    harness.run();
    assert!(harness.query_by_label("✎ Edit").is_some());
}