ab3f82f171
Info card (name, kind, size, modified, path, open with the system) for audio, video, PDF and other files; code_view highlighter (rust, js/ts, py, json, toml, yaml, sh, css, html) with line caps, not wired into tabs yet. Moves [ui.file-card] out of [ui.settings-view-calendar] (my earlier commit split it, which broke two calendar settings tests) and updates the Explorer test for show-all-types. Built by GLM 5.3 Flash via Pi; verified from a clean checkout of the staged files: lib tests 856 pass. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
51 lines
2.4 KiB
Rust
51 lines
2.4 KiB
Rust
//! The file viewers' info card, drawn headless: the card of a binary file shows its name and size
|
|
//! and hands the file to the shell's Open-with-the-system action when its button is clicked.
|
|
|
|
use egui_kittest::kittest::Queryable;
|
|
use notescraft_engine::Session;
|
|
use notescraft_themes::builtin;
|
|
use notescraft_ui_egui::file_card::show_info;
|
|
use notescraft_ui_egui::theme::Tokens;
|
|
|
|
/// A temp vault whose `blob.bin` is exactly 1 KiB, opened by a `Session`.
|
|
fn session_with_blob() -> Session {
|
|
let root = std::env::temp_dir().join(format!("notescraft-file-viewers-basic-{}", std::process::id()));
|
|
let _ = std::fs::remove_dir_all(&root);
|
|
let _ = std::fs::create_dir_all(&root);
|
|
let _ = std::fs::write(root.join("blob.bin"), 0_u8.to_le_bytes().repeat(1024));
|
|
Session::open(&root).expect("a temp vault opens")
|
|
}
|
|
|
|
#[test]
|
|
fn the_info_card_of_a_bin_file_shows_its_name_size_and_action() {
|
|
let session = session_with_blob();
|
|
let tokens = Tokens::new(builtin("catppuccin-mocha").expect("theme"));
|
|
let mut harness = egui_kittest::Harness::builder().with_size(egui::Vec2::new(800.0, 600.0)).build_ui_state(
|
|
|ui, opened: &mut (Option<String>, bool)| {
|
|
let (opened, warmed) = opened;
|
|
if !*warmed {
|
|
// Fonts bind one pass after installing; the first pass warms only.
|
|
notescraft_ui_egui::fonts::install(ui.ctx());
|
|
*warmed = true;
|
|
return;
|
|
}
|
|
// The card answers once per frame; the state keeps a click past later repaints.
|
|
if let Some(shown) = show_info(ui, &tokens, &session, "blob.bin") {
|
|
*opened = Some(shown);
|
|
}
|
|
},
|
|
(None, false),
|
|
);
|
|
harness.run();
|
|
assert!(harness.get_all_by_label_contains("blob.bin").count() >= 1, "the name is shown");
|
|
assert!(harness.get_all_by_label_contains("1 KB").count() >= 1, "the size is shown");
|
|
assert!(harness.get_all_by_label_contains("Other").count() >= 1, "the kind is shown");
|
|
assert_eq!(harness.get_all_by_label("Open with the system").count(), 1, "one action button");
|
|
assert_eq!(harness.get_all_by_label("Path").count(), 1, "the path row is labelled");
|
|
|
|
harness.get_by_label("Open with the system").click();
|
|
harness.run();
|
|
let (opened, _) = harness.into_state();
|
|
assert_eq!(opened, Some(String::from("blob.bin")), "the card hands the path to the shell");
|
|
}
|