mirror of
https://github.com/YuzuZensai/Pien-Studio.git
synced 2026-09-02 14:18:35 +00:00
♻️ refactor!: massive refactor
This commit is contained in:
@@ -10,7 +10,44 @@ function makeProject(): Project {
|
||||
updatedAt: "2024-01-01T00:00:00.000Z",
|
||||
aspectRatio: "1:1",
|
||||
canvas: { width: 100, height: 100, unit: "px" },
|
||||
layers: [{ id: "l1", type: "text", x: 0, y: 0, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true }],
|
||||
layers: [textLayer("l1")],
|
||||
};
|
||||
}
|
||||
|
||||
function textLayer(id: string) {
|
||||
return {
|
||||
id,
|
||||
type: "text" as const,
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 120,
|
||||
height: 48,
|
||||
scale: 1,
|
||||
rotation: 0,
|
||||
opacity: 1,
|
||||
effects: [],
|
||||
visible: true,
|
||||
text: "Text",
|
||||
fontFamily: "system-ui",
|
||||
fontSize: 24,
|
||||
color: "#000",
|
||||
};
|
||||
}
|
||||
|
||||
function rasterLayer(id: string) {
|
||||
return {
|
||||
id,
|
||||
type: "raster" as const,
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 120,
|
||||
height: 80,
|
||||
scale: 1,
|
||||
rotation: 0,
|
||||
opacity: 1,
|
||||
effects: [],
|
||||
visible: true,
|
||||
asset: null,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -31,18 +68,34 @@ describe("hasProjectChanged", () => {
|
||||
it("detects face blur region changes", () => {
|
||||
const a = makeProject();
|
||||
const b = makeProject();
|
||||
a.layers[0].type = "raster";
|
||||
b.layers[0].type = "raster";
|
||||
a.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 10, height: 10 }] }];
|
||||
b.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 11, height: 10 }] }];
|
||||
a.layers[0] = rasterLayer("l1");
|
||||
b.layers[0] = rasterLayer("l1");
|
||||
a.layers[0].effects = [
|
||||
{
|
||||
kind: "face-blur",
|
||||
enabled: true,
|
||||
method: "gaussian",
|
||||
amount: 14,
|
||||
regions: [{ x: 1, y: 1, width: 10, height: 10 }],
|
||||
},
|
||||
];
|
||||
b.layers[0].effects = [
|
||||
{
|
||||
kind: "face-blur",
|
||||
enabled: true,
|
||||
method: "gaussian",
|
||||
amount: 14,
|
||||
regions: [{ x: 1, y: 1, width: 11, height: 10 }],
|
||||
},
|
||||
];
|
||||
expect(hasProjectChanged(a, b)).toBe(true);
|
||||
});
|
||||
|
||||
it("detects layer order changes", () => {
|
||||
const a = makeProject();
|
||||
const b = makeProject();
|
||||
a.layers.push({ id: "l2", type: "text", x: 3, y: 4, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true });
|
||||
b.layers.push({ id: "l2", type: "text", x: 3, y: 4, scale: 1, rotation: 0, opacity: 1, effects: [], visible: true });
|
||||
a.layers.push({ ...textLayer("l2"), x: 3, y: 4 });
|
||||
b.layers.push({ ...textLayer("l2"), x: 3, y: 4 });
|
||||
b.layers = [b.layers[1], b.layers[0]];
|
||||
expect(hasProjectChanged(a, b)).toBe(true);
|
||||
});
|
||||
@@ -65,9 +118,17 @@ describe("hasProjectChanged", () => {
|
||||
it("detects face blur removal", () => {
|
||||
const a = makeProject();
|
||||
const b = makeProject();
|
||||
a.layers[0].type = "raster";
|
||||
b.layers[0].type = "raster";
|
||||
a.layers[0].effects = [{ kind: "face-blur", enabled: true, method: "gaussian", amount: 14, regions: [{ x: 1, y: 1, width: 10, height: 10 }] }];
|
||||
a.layers[0] = rasterLayer("l1");
|
||||
b.layers[0] = rasterLayer("l1");
|
||||
a.layers[0].effects = [
|
||||
{
|
||||
kind: "face-blur",
|
||||
enabled: true,
|
||||
method: "gaussian",
|
||||
amount: 14,
|
||||
regions: [{ x: 1, y: 1, width: 10, height: 10 }],
|
||||
},
|
||||
];
|
||||
expect(hasProjectChanged(a, b)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user