G12: confirm context-menu swatch deletion

Reuse the panel deletion helper so the clicked swatch is deleted only after confirmation. Cover confirmation text, cancellation, clicked-item targeting and Undo across all five views. All 39 Swatches tests and all 13 local CI gates pass; fresh deep CodeRabbit review reports zero findings.
This commit is contained in:
ruchirguitar
2026-11-15 23:25:36 +05:30
parent e9c57f06e4
commit 18bfc1239b
2 changed files with 32 additions and 2 deletions
+6 -2
View File
@@ -237,8 +237,12 @@ fn item_context_menu(app: &mut VectorcraftApp, ui: &Ui, resp: &Response, e: &Ent
None
};
if let Some(command) = command {
// run reports failures through the app's status message.
let _ = app.run(command, json!({"name": name}));
if command == "swatch.delete" {
actions::delete(app, vec![name.to_string()], false);
} else {
// run reports failures through the app's status message.
let _ = app.run(command, json!({"name": name}));
}
ui.close();
}
});
@@ -36,6 +36,27 @@ fn right_click(h: &mut Harness<'static, VectorcraftApp>, name: &str) {
h.run_steps(2);
}
fn cancel_then_confirm_delete(h: &mut Harness<'static, VectorcraftApp>) {
let before = h.state().session.doc().unwrap().doc.clone();
let undo = h.state().session.doc().unwrap().history.undo.len();
let dialog = h.state().ui.dialog.as_ref().expect("delete asks first");
assert_eq!(dialog.kind, crate::dialogs::confirm::KIND);
assert_eq!(dialog.str("message"), "Delete “Red”?");
assert_eq!(dialog.str("detail"), "Art using a deleted global swatch keeps its colour.");
assert_eq!(dialog.str("__command"), "swatch.delete");
assert_eq!(dialog.fields.get("__params"), Some(&json!({"names": ["Red"]})));
assert_eq!(h.state().session.doc().unwrap().doc, before);
assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo);
crate::dialogs::cancel(h.state_mut());
assert!(h.state().ui.dialog.is_none());
assert_eq!(h.state().session.doc().unwrap().doc, before);
assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo);
right_click(h, "Red");
h.get_by_label(" Delete Swatch").click();
h.run_steps(3);
crate::dialogs::confirm(h.state_mut()).unwrap();
}
#[test]
fn right_click_selects_without_painting_and_dispatches_item_commands() {
for (view, _) in View::ALL {
@@ -78,6 +99,9 @@ fn right_click_selects_without_painting_and_dispatches_item_commands() {
assert_eq!(h.state().session.doc().unwrap().doc, before);
}
"Delete Swatch" => {
assert_eq!(h.state().session.doc().unwrap().doc, before);
assert_eq!(h.state().session.doc().unwrap().history.undo.len(), undo);
cancel_then_confirm_delete(&mut h);
let doc = &h.state().session.doc().unwrap().doc;
assert!(doc.swatch("Red").is_none());
assert!(doc.swatch("Black").is_some());
@@ -123,6 +147,8 @@ fn right_clicking_the_active_panel_item_preserves_its_selection() {
assert_eq!(selected(&h.ctx), names);
h.get_by_label(" Delete Swatch").click();
h.run_steps(3);
assert_eq!(h.state().ui.dialog.as_ref().unwrap().fields.get("__params"), Some(&json!({"names": ["Red"]})));
crate::dialogs::confirm(h.state_mut()).unwrap();
let doc = &h.state().session.doc().unwrap().doc;
assert!(doc.swatch("Black").is_some(), "only the clicked item is deleted");
assert!(doc.swatch("Red").is_none());