mirror of
https://github.com/storytold/figcraft.git
synced 2026-10-30 05:16:56 -06:00
Reject non-page ids in page.duplicate
Found while testing crates/engine/src/cmd/page.rs:96 (page.duplicate, `let src = id(p, "id").unwrap_or(s.page()?)`) Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
90054a89c4
commit
877ac1fd5e
@@ -93,7 +93,7 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
ok()
|
||||
}),
|
||||
spec!("page.duplicate", "Duplicate page", "{id?}", true, |s, p| {
|
||||
let src = id(p, "id").unwrap_or(s.page()?);
|
||||
let src = page_target(s, "page.duplicate", p)?;
|
||||
let doc = s.doc_mut()?;
|
||||
let name = format!("Copy of {}", doc.get(src)?.name);
|
||||
let np = doc.add_page(&name);
|
||||
|
||||
@@ -61,3 +61,13 @@ fn page_commands_still_work_on_pages() {
|
||||
assert!(!s.doc().unwrap().contains(second));
|
||||
assert!(s.execute("page.delete", &json!({"id": first})).is_err(), "the last ordinary page stays");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn page_duplicate_rejects_a_frame() {
|
||||
let mut s = Session::new();
|
||||
let f = id_of(&ex(&mut s, "frame.create", json!({"x": 0, "y": 0, "width": 100, "height": 100})));
|
||||
let pages = s.doc().unwrap().pages.clone();
|
||||
let err = s.execute("page.duplicate", &json!({"id": f})).expect_err("duplicate refuses a layer");
|
||||
assert!(err.to_string().contains("is not a page"), "{err}");
|
||||
assert_eq!(s.doc().unwrap().pages, pages, "no page was added");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user