Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

test(editor): cover the vertical pan axis and the pan's own recovery

EtienneLescotf1a0201d94a8
diff --git a/src/components/ai-edition/RightPanes.layout.test.tsx b/src/components/ai-edition/RightPanes.layout.test.tsx
index 45d9efa9b..bf5077403 100644
--- a/src/components/ai-edition/RightPanes.layout.test.tsx
+++ b/src/components/ai-edition/RightPanes.layout.test.tsx
@@ -134,8 +134,14 @@ describe("LayoutPane camera availability", () => {
describe("LayoutPane webcam crop pan", () => {
const zoom = () => screen.getByRole("slider", { name: "Zoom" });
const panX = () => screen.getByRole("slider", { name: "Pan horizontally" });
+ const panY = () => screen.getByRole("slider", { name: "Pan vertically" });
const set = (slider: HTMLElement, value: number) =>
fireEvent.change(slider, { target: { value: String(value) } });
+ const storedCrop = () =>
+ useProjectStore.getState().document?.legacyEditor as unknown as {
+ webcamCropRegion: { x: number; y: number; width: number; height: number };
+ webcamCropPan: { x: number; y: number };
+ };
it("keeps the pan across a round trip through 100% zoom", () => {
renderLayout(seedProject(true));
@@ -167,6 +173,22 @@ describe("LayoutPane webcam crop pan", () => {
}
});
+ it("wires the vertical slider to the vertical axis", () => {
+ // The two sliders differ by one character in the handler they call. Without this,
+ // a Y slider wired to "x" would pass every other test in this block.
+ renderLayout(seedProject(true));
+
+ set(zoom(), 200);
+ set(panY(), 80);
+
+ expect(panY()).toHaveValue("80");
+ expect(storedCrop().webcamCropPan.y).toBeCloseTo(0.8);
+ expect(storedCrop().webcamCropRegion.y).toBeCloseTo(0.4);
+ // ...and it left the horizontal axis alone.
+ expect(panX()).toHaveValue("50");
+ expect(storedCrop().webcamCropRegion.x).toBeCloseTo(0.25);
+ });
+
it("puts the crop where the pan says, at any zoom", () => {
renderLayout(seedProject(true));
diff --git a/src/lib/ai-edition/store/editorSettings.test.ts b/src/lib/ai-edition/store/editorSettings.test.ts
index f341abfb0..07982f47a 100644
--- a/src/lib/ai-edition/store/editorSettings.test.ts
+++ b/src/lib/ai-edition/store/editorSettings.test.ts
@@ -201,4 +201,42 @@ describe("patchEditorSettings", () => {
expect(crop.y).toBeCloseTo(0.25);
expect(crop.width).toBeCloseTo(0.5);
});
+
+ it("clamps a stored pan that is out of range", () => {
+ const doc: AxcutDocument = {
+ ...baseDoc,
+ legacyEditor: {
+ webcamCropRegion: { x: 0, y: 0, width: 0.5, height: 0.5 },
+ webcamCropPan: { x: 5, y: -2 },
+ },
+ };
+
+ const snap = getEditorSettings(doc);
+ expect(snap.webcamCropPan).toEqual({ x: 1, y: 0 });
+ // And the rect that follows from it still sits inside the frame.
+ expect(snap.webcamCropRegion.x).toBeCloseTo(0.5);
+ expect(snap.webcamCropRegion.y).toBeCloseTo(0);
+ });
+
+ it("falls back per axis when only one of the pan's coordinates is usable", () => {
+ // A half-written or hand-edited pan must not drag the good axis down with it: each
+ // coordinate recovers from the rect on its own.
+ const doc: AxcutDocument = {
+ ...baseDoc,
+ legacyEditor: {
+ webcamCropRegion: { x: 0.375, y: 0.125, width: 0.5, height: 0.5 },
+ webcamCropPan: { x: "left", y: 0.9 } as unknown as { x: number; y: number },
+ },
+ };
+
+ const snap = getEditorSettings(doc);
+ // x is unusable, so it comes back from the rect: 0.375 of the 0.5 free is 0.75.
+ expect(snap.webcamCropPan.x).toBeCloseTo(0.75);
+ // y is a number, so it is kept — and 0.9 is deliberately NOT what the rect implies
+ // (0.125 of 0.5 free would be 0.25), so this fails if the axes are not independent.
+ expect(snap.webcamCropPan.y).toBeCloseTo(0.9);
+ // The rect then follows each axis from its own resolved pan.
+ expect(snap.webcamCropRegion.x).toBeCloseTo(0.375);
+ expect(snap.webcamCropRegion.y).toBeCloseTo(0.45);
+ });
});