mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Merge PR #8284: test(ui): cover tool memory persistence
This commit is contained in:
commit
487c449c5a
1 file changed
+47
@@ -263,3 +263,50 @@ fn nulls(v: &Value) -> usize {
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn selected_tool_and_non_default_options_roundtrip() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.ui.tool = Tool::Move;
|
||||
app.ui.tool_options.tolerance = 42.5;
|
||||
persist(&mut app, &egui::Context::default());
|
||||
|
||||
let saved = app.session.prefs();
|
||||
assert_eq!(saved.selected_tool, serde_json::to_value(Tool::Move).unwrap());
|
||||
assert_eq!(saved.tool_options["tolerance"], Value::from(42.5));
|
||||
assert!(saved.tool_options.get("contiguous").is_none(), "unchanged defaults are not written");
|
||||
|
||||
let mut restored = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
restored.session.prefs.edit(|p| {
|
||||
p.selected_tool = saved.selected_tool.clone();
|
||||
p.tool_options = saved.tool_options.clone();
|
||||
});
|
||||
restore(&mut restored);
|
||||
assert_eq!(restored.ui.tool, Tool::Move);
|
||||
assert_eq!(restored.ui.tool_options.tolerance, 42.5);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn restore_ignores_unknown_and_malformed_tool_options() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
let original_tool = app.ui.tool;
|
||||
let default_contiguous = ToolOptions::default().contiguous;
|
||||
app.session.prefs.edit(|p| {
|
||||
p.selected_tool = Value::from("not-a-tool");
|
||||
p.tool_options = serde_json::json!({
|
||||
"tolerance": 42.5,
|
||||
"contiguous": "not a boolean",
|
||||
"future_option": true
|
||||
});
|
||||
});
|
||||
|
||||
restore(&mut app);
|
||||
assert_eq!(app.ui.tool, original_tool, "an invalid selected tool leaves the current tool intact");
|
||||
assert_eq!(app.ui.tool_options.tolerance, 42.5, "valid fields still restore");
|
||||
assert_eq!(app.ui.tool_options.contiguous, default_contiguous, "a malformed field falls back to its default");
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user