From 0dd946bb520f1c8c69670e5fca8aa589c70de116 Mon Sep 17 00:00:00 2001 From: dotCooCoo Date: Thu, 26 Nov 2026 19:36:43 -0800 Subject: [PATCH] Reproduce Color Group Options renaming a restored group --- .../src/dialogs/color_group_options.rs | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/crates/ui-egui/src/dialogs/color_group_options.rs b/crates/ui-egui/src/dialogs/color_group_options.rs index 36fab4b2a1..c0fc59cc41 100644 --- a/crates/ui-egui/src/dialogs/color_group_options.rs +++ b/crates/ui-egui/src/dialogs/color_group_options.rs @@ -101,6 +101,42 @@ mod tests { app.session.active().unwrap().history.undo.len() } + #[test] + fn an_old_rename_draft_keeps_the_color_group_restored_by_revert() { + let (ctx, mut app) = app(); + let dir = vectorcraft_testkit::TempDir::new("color-group-options-revert"); + app.services.read = Some(Box::new(|path| std::fs::read(path).map_err(|err| err.to_string()))); + app.services.write = Some(Box::new(|path, bytes| std::fs::write(path, bytes).map_err(|err| err.to_string()))); + app.run("file.saveAs", json!({"path": dir.join("colors.vectorcraft")})).unwrap(); + let color = |app: &VectorcraftApp| app.session.active().unwrap().doc.swatch("Bright Red").unwrap().paint.color(); + let saved_color = color(&app); + let saved_groups = groups(&app); + let st = app.session.active().unwrap(); + let (uid, reverts) = (st.uid, st.reverts); + + app.run("swatch.edit", json!({"name": "Bright Red", "color": "#1784ca"})).unwrap(); + assert_ne!(color(&app), saved_color); + app.run("ui.colorGroupOptions", json!({"group": "Brights"})).unwrap(); + let id = dialog_id(KIND); + app.dialogs().unwrap().with(|h| h.set_json_field(&ctx, id, "name", json!("Old palette draft"))).unwrap(); + app.run("file.revert", json!({"confirmed": true})).unwrap(); + let restored = app.session.active().unwrap(); + assert_eq!((restored.uid, restored.reverts), (uid, reverts + 1)); + assert_eq!(color(&app), saved_color); + assert_eq!(groups(&app), saved_groups); + let undo = undo_len(&app); + + crate::tests::picks::answer_dialog(&mut app, id, &[], true); + assert_eq!(groups(&app), saved_groups, "old Color Group Options must leave the restored group named Brights"); + assert_eq!(color(&app), saved_color); + assert_eq!(undo_len(&app), undo); + + app.run("ui.colorGroupOptions", json!({"group": "Brights"})).unwrap(); + ok(&mut app, &ctx, "Restored palette"); + assert!(groups(&app).iter().any(|name| name == "Restored palette")); + assert_eq!(undo_len(&app), undo + 1); + } + /// Whether the dialog is still open. fn is_open(app: &VectorcraftApp) -> bool { app.dialogs().unwrap().with(|h| h.get_by_id::(dialog_id(KIND)).is_some())