Warp: the smart-object preset tests follow main's transform session

After the merge with main, the open transform keeps its warp in `session.warp()` and the
shared `app_with_square` helper is private to the transform tests, so the test file reads the
warp through the session, changes Bend with `set_warp` and has its own square helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-11-29 23:06:02 +01:00
1 parent 5dd939013e
commit 57eb75a0fa
1 file changed
+21 -4
@@ -5,11 +5,26 @@
use serde_json::json;
use super::super::tests::app_with_square;
use super::super::warp::set_warp;
use super::super::*;
/// A `size` × `size` document with a new layer filled red over `fill`.
fn app_with_square(size: u32, fill: photocraft_geom::Rect) -> Box<PhotocraftApp> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
app.session.execute("file.new", json!({"width": size, "height": size})).unwrap();
app.sync_views();
app.session.execute("layer.new.layer", json!({})).unwrap();
app.session
.edit("paint", |doc, a| {
doc.layer_mut(a.unwrap()).unwrap().surface_mut().unwrap().fill_rect(fill, &[1.0, 0.0, 0.0, 1.0]);
Ok(())
})
.unwrap();
app
}
/// A 64 × 64 document whose red square 8,8 to 32,32 is a smart object warped with `params`.
fn warped(params: serde_json::Value) -> PhotocraftApp {
fn warped(params: serde_json::Value) -> Box<PhotocraftApp> {
let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 32, 32));
app.run("layer.smartObjects.convertToSmartObject", json!({})).unwrap();
app.run("layer.smartObjects.warp", params).unwrap();
@@ -17,7 +32,7 @@ fn warped(params: serde_json::Value) -> PhotocraftApp {
}
fn session_warp(app: &PhotocraftApp) -> Warp {
app.ui.transform.as_ref().and_then(|t| t.warp.clone()).expect("Warp mode")
app.ui.transform.as_ref().and_then(|t| t.session.warp()).map(|w| w.warp.clone()).expect("Warp mode")
}
fn stored(app: &PhotocraftApp) -> Warp {
@@ -50,7 +65,9 @@ fn a_changed_bend_commits_as_the_preset() {
let ctx = egui::Context::default();
let mut app = warped(json!({"style": "arc", "bend": 50, "rect": [8, 8, 32, 32]}));
begin_warp(&mut app, &ctx).unwrap();
app.ui.transform.as_mut().unwrap().warp.as_mut().unwrap().bend = 25.0;
let mut w = session_warp(&app);
w.bend = 25.0;
set_warp(&mut app, w);
commit(&mut app);
let w = stored(&app);
assert_eq!((w.style, w.bend), (WarpStyle::Arc, 25.0), "stored as Arc, not Custom");