45 lines
1.8 KiB
TypeScript
45 lines
1.8 KiB
TypeScript
import { describe, expect, test } from "bun:test";
|
|
import { createInitialAppState } from "@editor/initial-state";
|
|
import { documentAddArtboardCommand } from "./document";
|
|
import { transformBeginCommand, transformEndCommand, transformUpdateCommand } from "./transform";
|
|
|
|
function artboardState() {
|
|
return documentAddArtboardCommand.execute(
|
|
{ state: createInitialAppState("Test") },
|
|
{ id: "a1", name: "Artboard", bounds: { x: 0, y: 0, w: 100, h: 80 } },
|
|
);
|
|
}
|
|
|
|
describe("transform commands", () => {
|
|
test("moves artboard transform target", () => {
|
|
const started = transformBeginCommand.execute(
|
|
{ state: artboardState() },
|
|
{ target: { type: "artboard", id: "a1" }, handle: "body", point: { x: 0, y: 0 }, initialBounds: { x: 0, y: 0, w: 100, h: 80 } },
|
|
);
|
|
const updated = transformUpdateCommand.execute({ state: started }, { point: { x: 10, y: 20 } });
|
|
|
|
expect(updated.document.artboards[0]?.bounds).toEqual({ x: 10, y: 20, w: 100, h: 80 });
|
|
});
|
|
|
|
test("resizes artboard from southeast handle", () => {
|
|
const started = transformBeginCommand.execute(
|
|
{ state: artboardState() },
|
|
{ target: { type: "artboard", id: "a1" }, handle: "se", point: { x: 0, y: 0 }, initialBounds: { x: 0, y: 0, w: 100, h: 80 } },
|
|
);
|
|
const updated = transformUpdateCommand.execute({ state: started }, { point: { x: 10, y: 20 } });
|
|
|
|
expect(updated.document.artboards[0]?.bounds).toEqual({ x: 0, y: 0, w: 110, h: 100 });
|
|
});
|
|
|
|
test("ends transform session", () => {
|
|
const started = transformBeginCommand.execute(
|
|
{ state: artboardState() },
|
|
{ target: { type: "artboard", id: "a1" }, handle: "body", point: { x: 0, y: 0 }, initialBounds: { x: 0, y: 0, w: 100, h: 80 } },
|
|
);
|
|
|
|
const ended = transformEndCommand.execute({ state: started }, undefined);
|
|
|
|
expect(ended.editor.transformSession).toBeUndefined();
|
|
});
|
|
});
|