Files
notescraft/crates/ui-egui/tests/settings_environment.rs

56 lines
2.2 KiB
Rust

//! The config environment override is exercised in a child process without unsafe mutation.
use std::process::Command;
use notescraft_ui_egui::{
app::NotesApp,
sidebar_tabs::SidebarTab,
tabs::{GRAPH_PATH, SETTINGS_PATH},
};
#[test]
fn environment_override_roundtrips_ui_blob() {
let config = std::env::temp_dir().join(format!("notescraft-ui-env-{}", std::process::id()));
let result = Command::new(std::env::current_exe().expect("test binary"))
.args(["--exact", "isolated_settings_child", "--test-threads=1"])
.env("NOTESCRAFT_CONFIG_DIR", &config)
.env("NOTESCRAFT_SETTINGS_CHILD", "1")
.output()
.expect("child");
assert!(result.status.success(), "{}\n{}", String::from_utf8_lossy(&result.stdout), String::from_utf8_lossy(&result.stderr));
}
#[test]
fn isolated_settings_child() {
if std::env::var_os("NOTESCRAFT_SETTINGS_CHILD").is_none() {
return;
}
let config = std::path::PathBuf::from(std::env::var_os("NOTESCRAFT_CONFIG_DIR").expect("override"));
let root = config.join("vault");
std::fs::create_dir_all(&root).expect("vault");
std::fs::write(root.join("note.md"), "# Note\n").expect("note");
let session = notescraft_engine::Session::open(&root).expect("session");
let theme = notescraft_themes::builtin("catppuccin-mocha").expect("theme");
let mut app = NotesApp::new(session, theme.clone());
app.open_note("note.md");
app.open_note(GRAPH_PATH);
app.open_note(SETTINGS_PATH);
app.state.sidebar_width = 285.0;
app.state.right_width = 310.0;
app.state.sidebar_tab = SidebarTab::Tags;
app.state.ui_scale = 1.5;
app.state.sound = false;
app.state.volume = 0.25;
app.state.animations = false;
app.persist_ui();
assert!(config.join("config.toml").is_file());
let expected = app.state.clone();
drop(app);
let restored = NotesApp::new(notescraft_engine::Session::open(&root).expect("session"), theme);
assert_eq!(restored.state, expected);
assert_eq!(restored.tabs.open, expected.tabs);
assert!(restored.session.buffer(GRAPH_PATH).is_none());
assert!(restored.session.buffer(SETTINGS_PATH).is_none());
assert!(!root.join("notescraft:").exists());
}