Skip to content

Commit d3b529a

Browse files
implemented tests
1 parent 08d8cd1 commit d3b529a

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

packages/url-loader/tests/plugins/cropping.spec.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,4 +411,60 @@ describe("Cropping plugin", () => {
411411
`image/upload/c_${options.crop.type},w_${options.width},h_${options.height},x_${options.crop.x},y_${options.crop.y}`,
412412
);
413413
});
414+
415+
it("should apply auto_pad crop mode with explicit gravity auto", () => {
416+
const cldImage = cld.image(TEST_PUBLIC_ID);
417+
const options = {
418+
src: TEST_PUBLIC_ID,
419+
width: 960,
420+
aspectRatio: "16:9",
421+
crop: "auto_pad",
422+
gravity: "auto",
423+
} as const;
424+
const result = CroppingPlugin.apply(cldImage, options);
425+
426+
if (result.options?.resize === undefined)
427+
throw new Error(`Expected result.options.resize to not be undefined`);
428+
429+
expect(result.options?.resize).toBe(
430+
`c_auto_pad,ar_16:9,w_960,g_auto`,
431+
);
432+
});
433+
434+
it("should apply auto_pad crop mode with auto gravity by default", () => {
435+
const cldImage = cld.image(TEST_PUBLIC_ID);
436+
const options = {
437+
src: TEST_PUBLIC_ID,
438+
width: 960,
439+
aspectRatio: "16:9",
440+
crop: "auto_pad",
441+
} as const;
442+
const result = CroppingPlugin.apply(cldImage, options);
443+
444+
if (result.options?.resize === undefined)
445+
throw new Error(`Expected result.options.resize to not be undefined`);
446+
447+
expect(result.options?.resize).toBe(
448+
`c_auto_pad,ar_16:9,w_960,g_auto`,
449+
);
450+
});
451+
452+
it("should apply auto_pad crop mode with width and height", () => {
453+
const cldImage = cld.image(TEST_PUBLIC_ID);
454+
const options = {
455+
src: TEST_PUBLIC_ID,
456+
width: 960,
457+
height: 540,
458+
crop: "auto_pad",
459+
gravity: "auto",
460+
} as const;
461+
const result = CroppingPlugin.apply(cldImage, options);
462+
463+
if (result.options?.resize === undefined)
464+
throw new Error(`Expected result.options.resize to not be undefined`);
465+
466+
expect(result.options?.resize).toBe(
467+
`c_auto_pad,w_960,h_540,g_auto`,
468+
);
469+
});
414470
});

0 commit comments

Comments
 (0)