#680: move the page clipboard test to its own module, check the error id

This commit is contained in:
bflatastic
2026-10-17 15:58:24 +07:00
parent 01ce23ca76
commit 5ea5590673
3 changed files with 38 additions and 17 deletions
+2
View File
@@ -1592,6 +1592,8 @@ mod open_issues_tests;
#[cfg(test)]
mod outline_options_tests;
#[cfg(test)]
mod page_clipboard_tests;
#[cfg(test)]
mod page_copy_navigation_tests;
#[cfg(test)]
mod page_target_tests;
+36
View File
@@ -0,0 +1,36 @@
//! `edit.copy` / `edit.cut` skip pages (they aren't layers and can't be pasted), and refuse a
//! selection of only pages under their own command id.
use serde_json::json;
use crate::{EngineError, Session};
#[test]
fn copy_and_cut_ignore_pages_so_paste_keeps_the_document_valid() {
for cmd in ["edit.copy", "edit.cut"] {
let mut s = Session::new();
let page = s.page().unwrap();
s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
match s.execute(cmd, &json!({"ids": [page.0]})) {
Err(EngineError::Disabled(id, _)) => assert_eq!(id, cmd),
r => panic!("{cmd} on a page: {r:?}"),
}
let _ = s.execute("edit.paste", &json!({}));
let doc = s.doc().unwrap();
assert!(doc.validate().is_empty(), "{cmd}: {:?}", doc.validate());
assert!(doc.node(page).is_some(), "{cmd} removed the page");
}
}
#[test]
fn cut_of_a_page_and_a_layer_moves_only_the_layer() {
let mut s = Session::new();
let page = s.page().unwrap();
let r = s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
let rect = crate::params::id_of(&r["id"]).unwrap();
s.execute("edit.cut", &json!({"ids": [page.0, rect.0]})).unwrap();
assert!(s.doc().unwrap().node(page).is_some());
assert!(s.doc().unwrap().node(rect).is_none());
s.execute("edit.paste", &json!({})).unwrap();
assert!(s.doc().unwrap().validate().is_empty());
}
-17
View File
@@ -621,20 +621,3 @@ fn find_replace_changing_only_the_case_replaces_every_occurrence() {
assert_eq!(s.doc().unwrap().node(t).unwrap().kind.text().unwrap().characters, "FigCraft and FigCraft, FigCraft");
assert_eq!(s.doc().unwrap().node(f).unwrap().name, "FigCraft / FigCraft");
}
#[test]
fn copy_and_cut_ignore_pages_so_paste_keeps_the_document_valid() {
for cmd in ["edit.copy", "edit.cut"] {
let mut s = sess();
let page = s.page().unwrap();
s.execute("shape.rectangle", &json!({"x": 0, "y": 0, "width": 10, "height": 10})).unwrap();
let r = s.execute(cmd, &json!({"ids": [page.0]}));
if let Ok(v) = &r {
assert!(v.get("deleted").is_none_or(|d| d == &json!([])), "{cmd} reported the page as deleted: {v}");
}
let _ = s.execute("edit.paste", &json!({}));
let doc = s.doc().unwrap();
assert!(doc.validate().is_empty(), "{cmd}: {:?}", doc.validate());
assert!(doc.node(page).is_some(), "{cmd} removed the page");
}
}