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

nordisk/facett

facett-file/tests/render.rs

//! **CPU render-proof for facett-file.** The inline tests cover `human_size`/icon
//! helpers + the remove-intent state; the `Files::ui()` render path (the drop zone, the
//! attachment rows with icon/name/size, and the 🗑 remove buttons) is never executed.
//! This drives real `egui_kittest` frames so the painter runs and the list rides into
//! the AccessKit tree — read-write **and** read-only.

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

use facett_file::{FileRef, Files};

fn populated() -> Files {
    let mut f = Files::new();
    f.set_files(vec![
        FileRef::new("ansökan.pdf", 12_800, "application/pdf"),
        FileRef::new("bild.png", 2_048, "image/png"),
    ]);
    f
}

#[test]
fn list_and_drop_zone_paint_with_remove_buttons() {
    let f = populated();
    // state_json is data: two files, summed size.
    let st = f.state_json();
    assert_eq!(st["count"], 2);
    assert_eq!(st["total_size"], 12_800 + 2_048);
    assert_eq!(st["read_only"], false);

    let mut f_ui = f;
    let mut harness = Harness::new_ui(move |ui| {
        f_ui.ui(ui);
    });
    harness.run();
    // The file names + the drop-zone prompt reached the tree; each row has a 🗑 button.
    assert!(harness.query_by_label("ansökan.pdf").is_some(), "the pdf row painted");
    assert!(harness.query_by_label("bild.png").is_some(), "the image row painted");
    assert!(harness.get_all_by_label("🗑").count() >= 2, "each file has a remove button");
}

#[test]
fn read_only_hides_the_drop_zone_and_remove_buttons() {
    let f = populated().read_only(true);
    assert_eq!(f.state_json()["read_only"], true);
    let mut f_ui = f;
    let mut harness = Harness::new_ui(move |ui| {
        f_ui.ui(ui);
    });
    harness.run();
    // Files still list, but there are no remove buttons in read-only mode.
    assert!(harness.query_by_label("ansökan.pdf").is_some());
    assert_eq!(harness.query_all_by_label("🗑").count(), 0, "read-only shows no remove buttons");
}

#[test]
fn empty_list_paints_the_placeholder() {
    let f = Files::new();
    assert_eq!(f.state_json()["count"], 0);
    let mut f_ui = f;
    let mut harness = Harness::new_ui(move |ui| {
        f_ui.ui(ui);
    });
    harness.run();
    assert!(harness.query_by_label("Inga bifogade filer").is_some(), "the empty placeholder painted");
}