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:
@@ -7,16 +7,18 @@ function makeImageLayer(overrides: Partial<Layer> = {}): Layer {
|
||||
return {
|
||||
id: "layer-1",
|
||||
type: "raster",
|
||||
sourceUri: "data:image/png;base64,abc",
|
||||
asset: { kind: "inline", uri: "data:image/png;base64,abc" },
|
||||
x: 0,
|
||||
y: 0,
|
||||
width: 100,
|
||||
height: 100,
|
||||
scale: 1,
|
||||
rotation: 0,
|
||||
opacity: 1,
|
||||
effects: [],
|
||||
visible: true,
|
||||
...overrides,
|
||||
};
|
||||
} as Layer;
|
||||
}
|
||||
|
||||
describe("useFaceBlurWorkflow", () => {
|
||||
@@ -25,8 +27,24 @@ describe("useFaceBlurWorkflow", () => {
|
||||
const removeLayerEffect = vi.fn();
|
||||
const selectedLayer = makeImageLayer();
|
||||
const faceDetections = [
|
||||
{ x: 1, y: 2, width: 10, height: 12, label: "a", sourceWidth: 100, sourceHeight: 100 },
|
||||
{ x: 5, y: 8, width: 7, height: 9, label: "b", sourceWidth: 100, sourceHeight: 100 },
|
||||
{
|
||||
x: 1,
|
||||
y: 2,
|
||||
width: 10,
|
||||
height: 12,
|
||||
label: "a",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
},
|
||||
{
|
||||
x: 5,
|
||||
y: 8,
|
||||
width: 7,
|
||||
height: 9,
|
||||
label: "b",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
},
|
||||
];
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
@@ -41,8 +59,14 @@ describe("useFaceBlurWorkflow", () => {
|
||||
|
||||
await waitFor(() => {
|
||||
expect(result.current.selectedFaceIndices).toEqual([0, 1]);
|
||||
const faceBlurEffect = result.current.faceBlurPreview?.effects.find((e) => e.kind === "face-blur");
|
||||
expect(faceBlurEffect?.kind === "face-blur" ? faceBlurEffect.regions : undefined).toHaveLength(2);
|
||||
const faceBlurEffect = result.current.faceBlurPreview?.effects.find(
|
||||
(e) => e.kind === "face-blur",
|
||||
);
|
||||
expect(
|
||||
faceBlurEffect?.kind === "face-blur"
|
||||
? faceBlurEffect.regions
|
||||
: undefined,
|
||||
).toHaveLength(2);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -62,7 +86,17 @@ describe("useFaceBlurWorkflow", () => {
|
||||
useFaceBlurWorkflow({
|
||||
selectedLayer,
|
||||
faceDetectionsLayerId: "layer-1",
|
||||
faceDetections: [{ x: 1, y: 2, width: 10, height: 12, label: "a", sourceWidth: 100, sourceHeight: 100 }],
|
||||
faceDetections: [
|
||||
{
|
||||
x: 1,
|
||||
y: 2,
|
||||
width: 10,
|
||||
height: 12,
|
||||
label: "a",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
},
|
||||
],
|
||||
setLayerEffect,
|
||||
removeLayerEffect,
|
||||
}),
|
||||
@@ -79,8 +113,24 @@ describe("useFaceBlurWorkflow", () => {
|
||||
const removeLayerEffect = vi.fn();
|
||||
const selectedLayer = makeImageLayer();
|
||||
const faceDetections = [
|
||||
{ x: 1, y: 2, width: 10, height: 12, label: "a", sourceWidth: 100, sourceHeight: 100 },
|
||||
{ x: 50, y: 60, width: 20, height: 22, label: "b", sourceWidth: 100, sourceHeight: 100 },
|
||||
{
|
||||
x: 1,
|
||||
y: 2,
|
||||
width: 10,
|
||||
height: 12,
|
||||
label: "a",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
},
|
||||
{
|
||||
x: 50,
|
||||
y: 60,
|
||||
width: 20,
|
||||
height: 22,
|
||||
label: "b",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
},
|
||||
];
|
||||
|
||||
const { result } = renderHook(() =>
|
||||
@@ -115,7 +165,15 @@ describe("useFaceBlurWorkflow", () => {
|
||||
method: "gaussian",
|
||||
amount: 14,
|
||||
regions: expect.arrayContaining([
|
||||
expect.objectContaining({ x: 1, y: 2, width: 10, height: 12, censorColor: "#111111", sourceWidth: 100, sourceHeight: 100 }),
|
||||
expect.objectContaining({
|
||||
x: 1,
|
||||
y: 2,
|
||||
width: 10,
|
||||
height: 12,
|
||||
censorColor: "#111111",
|
||||
sourceWidth: 100,
|
||||
sourceHeight: 100,
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user