Files
photocraft/crates/engine/tests/it/current_affinity_artboards.rs
T
aiongg a6428d3dfb Build each crate's integration tests as one binary
Every tests/*.rs file is its own executable that links the whole crate
graph. Move each crate's test files into tests/it/ as modules of one
tests/it/main.rs; helper modules under tests/common move with them.

These keep their own binary (own process):
- engine panic_hunt: a process-wide panic hook counts every panic.
- engine text_gamma: changes the process-wide text gamma.
- engine smart_filter_stages, mask_cache_purge: assert on global caches.
- codecs pnm_peak_memory: reads the process's peak RSS.
- photocraft mac_menu_appkit: harness = false.
2026-10-22 16:55:34 +00:00

48 lines
2.2 KiB
Rust

//! Artboards recognized from current .af properties move with their children and undo together.
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
#[path = "../../../io/tests/support/current_affinity.rs"]
mod fixture;
use fixture::{Marker, document};
use photocraft_affinity::synth::Method;
use photocraft_doc::{LayerContent, LayerId};
use photocraft_engine::{Session, file_cmds::open_bytes_as};
use photocraft_geom::{Point, Rect};
use serde_json::json;
fn state(s: &Session, id: LayerId) -> (Rect, Point) {
let layer = s.active().unwrap().doc.layer(id).unwrap();
let LayerContent::Group(group) = &layer.content else { panic!("not an artboard group") };
let LayerContent::Shape(child) = &group.children[0].content else { panic!("not an editable child") };
(group.artboard.as_ref().unwrap().rect, child.path.subpaths[0].knots[0].anchor)
}
#[test]
fn imported_current_boards_move_with_their_art_and_undo_without_moving_the_other_board() {
for marker in [Marker::Legacy, Marker::Current, Marker::OtherProperties] {
let mut s = Session::new();
let bytes = document(marker, false, Method::Zlib);
open_bytes_as(&mut s, "synthetic.af", &bytes, None, None).unwrap();
let ids: Vec<_> = s.active().unwrap().doc.artboards().into_iter().map(|(id, _, _)| id).collect();
if matches!(marker, Marker::OtherProperties) {
assert!(ids.is_empty());
assert!(!s.is_enabled("file.export.artboardsToFiles"));
continue;
}
assert_eq!(ids.len(), 2);
let before = state(&s, ids[0]);
let other = state(&s, ids[1]);
s.execute("layer.artboard.set", json!({"layer": ids[0].0, "x": 3, "y": 5})).unwrap();
let (board, child) = state(&s, ids[0]);
assert_eq!(board, Rect::new(3, 5, 19, 21));
assert_eq!(child, Point::new(before.1.x + 3.0, before.1.y + 5.0));
assert_eq!(state(&s, ids[1]), other);
s.execute("edit.undo", json!({})).unwrap();
assert_eq!(state(&s, ids[0]), before);
assert_eq!(state(&s, ids[1]), other);
s.execute("edit.redo", json!({})).unwrap();
assert_eq!(state(&s, ids[0]), (board, child));
}
}