Presets: the damaged-set test also covers Export As presets

a_damaged_preset_set_keeps_the_other_sets (#5602) checks that one
damaged set in the preferences file does not discard the others. It
left out export_presets, which #5344 added and #6906 put back into
load_presets_json, and recent_documents.

The test now saves an Export As preset and checks that it survives each
damaged set, recent_documents included. It also damages export_presets
and documents on their own, and gives a null set beside the Export As
presets. This is brandongunderson's change to the test in #6479,
unchanged.

Co-authored-by: brandongunderson <22452783+brandongunderson@users.noreply.github.com>
This commit is contained in:
dotCooCooandbrandongunderson committed 2026-10-17 07:57:59 -07:00
1 parent 351149f0df
commit 45e15036bf
1 file changed
+19 -2
+19 -2
View File
@@ -758,19 +758,36 @@ fn a_damaged_preset_set_keeps_the_other_sets() {
let mut s = Session::new();
let settings = json!({"width": 1600, "height": 900, "resolution": 144});
s.execute("document.presets.save", json!({"name": "Banner", "settings": settings})).unwrap();
s.execute("file.export.presets.save", json!({"name": "Web", "settings": {"format": "jpg", "quality": 70}})).unwrap();
let saved = s.presets.to_json(&s);
for key in ["gradients", "gradient", "styles", "shapes", "pattern_groups", "custom_shapes", "layer_defaults", "swatches"] {
for key in ["gradients", "gradient", "styles", "shapes", "pattern_groups", "recent_documents", "custom_shapes", "layer_defaults", "swatches"] {
let mut blob = saved.clone();
blob[key] = json!("not a preset set");
let mut next = Session::new();
next.load_presets_json(blob);
assert_eq!(next.presets.documents, s.presets.documents, "damaged `{key}`");
assert_eq!(next.presets.export_presets, s.presets.export_presets, "damaged `{key}`");
assert_eq!(next.presets.tool_presets.len(), Session::new().presets.tool_presets.len(), "damaged `{key}`");
}
let mut blob = saved.clone();
blob["export_presets"] = json!("not a preset set");
let mut next = Session::new();
next.load_presets_json(blob);
assert!(next.presets.export_presets.is_empty());
assert_eq!(next.presets.documents, s.presets.documents);
let mut blob = saved.clone();
blob["documents"] = json!("not a preset set");
let mut next = Session::new();
next.load_presets_json(blob);
assert!(next.presets.documents.is_empty());
assert_eq!(next.presets.export_presets, s.presets.export_presets);
// Null sets keep their defaults, as before.
let mut next = Session::new();
next.load_presets_json(json!({"tool_presets": null, "gradients": null, "documents": saved["documents"].clone()}));
next.load_presets_json(
json!({"tool_presets": null, "gradients": null, "documents": saved["documents"].clone(), "export_presets": saved["export_presets"].clone()}),
);
assert_eq!(next.presets.tool_presets.len(), Session::new().presets.tool_presets.len());
assert_eq!(next.presets.gradients.len(), Session::new().presets.gradients.len());
assert_eq!(next.presets.documents, s.presets.documents);
assert_eq!(next.presets.export_presets, s.presets.export_presets);
}