facett-file/tests/matrix.rs
//! **The functional matrix cell for facett-file** — 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 through the shared generic-`Facet` probe (L5) — no bespoke harness.
use facett_file::{FileRef, Files};
#[test]
fn files_probe_emits_render_and_input_cells() {
let mut view = Files::local();
let script = [
r#"{"attach":{"name":"protokoll.docx","size":51200,"mime":"application/msword"}}"#,
r#"{"detach":"matningar.csv"}"#,
];
let probe = facett_core::testmatrix::probe_and_emit("facett-file", &mut view, &script);
assert!(probe.drew(), "the attachment list must tessellate to vertices");
assert!(probe.cardinality() > 0, "state_json reports the files");
assert!(probe.responded(), "update_json must drive state — a dead seam is a regression");
// EXACT counts AND the derived total-size contract (not "something changed").
assert_eq!(probe.initial_state["count"], 3);
assert_eq!(probe.initial_state["total_size"], 184_320 + 962_144 + 4_096);
assert_eq!(probe.steps[0].state["count"], 4);
assert_eq!(probe.steps[0].state["total_size"], 184_320 + 962_144 + 4_096 + 51_200);
assert_eq!(probe.steps[1].state["count"], 3);
assert_eq!(probe.steps[1].state["total_size"], 184_320 + 962_144 + 51_200);
// The headless attach/detach fed the SAME outboxes a real drop/✕ does.
assert_eq!(view.take_added().len(), 1);
assert_eq!(view.take_removed(), vec!["matningar.csv".to_string()]);
}
/// RED-when-broken: read-only must veto BOTH attach and detach, and a duplicate
/// name must not double-add — otherwise the outbox feeds the host a phantom edit.
#[test]
fn read_only_and_duplicates_are_vetoed() {
let mut ro = Files::local().read_only(true);
assert!(!ro.attach(FileRef::new("x.pdf", 1, "application/pdf")));
assert!(!ro.detach("ansokan.pdf"));
assert_eq!(ro.files().len(), 3);
assert!(ro.take_added().is_empty());
assert!(ro.take_removed().is_empty());
let mut rw = Files::local();
assert!(!rw.attach(FileRef::new("ansokan.pdf", 9, "application/pdf")), "duplicate name");
assert!(!rw.detach("no-such-file"));
assert_eq!(rw.files().len(), 3);
assert!(rw.take_added().is_empty());
}