Skip to content

Commit

Permalink
Merge pull request #22 from cloudinary/ME-6260-gen-remove
Browse files Browse the repository at this point in the history
Add support for Generative Remove effect
  • Loading branch information
mckomo-cl authored Jul 14, 2023
2 parents 99a7ab6 + f31b5c5 commit 9aec36d
Show file tree
Hide file tree
Showing 6 changed files with 454 additions and 206 deletions.
42 changes: 42 additions & 0 deletions __TESTS__/unit/fromJson/generativeRemove.fromJson.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { fromJson } from "../../../src/internal/fromJson";

describe("generativeRemove.fromJson", () => {
it("should generate a url with e_gen_remove", function () {
const transformation = fromJson({
actions: [
{ actionType: "generativeRemove", prompts: ["dog"] },
{
actionType: "generativeRemove",
prompts: ["dog"],
detectMultiple: true,
},
{ actionType: "generativeRemove", prompts: ["dog", "cat"] },
{
actionType: "generativeRemove",
prompts: ["dog", "cat"],
detectMultiple: true,
}, // "detectMultiple" should be omitted from TX string for multiple prompts
{
actionType: "generativeRemove",
regions: [{ x: 10, y: 10, width: 100, height: 100 }],
},
{
actionType: "generativeRemove",
regions: [
{ x: 10, y: 10, width: 100, height: 100 },
{ x: 500, y: 500, width: 200, height: 200 },
],
},
],
});

expect(transformation.toString().split("/")).toStrictEqual([
"e_gen_remove:prompt_dog",
"e_gen_remove:prompt_dog;multiple_true",
"e_gen_remove:prompt_(dog;cat)",
"e_gen_remove:prompt_(dog;cat)",
"e_gen_remove:region_(x_10;y_10;w_100;h_100)",
"e_gen_remove:region_((x_10;y_10;w_100;h_100);(x_500;y_500;w_200;h_200))",
]);
});
});
59 changes: 59 additions & 0 deletions __TESTS__/unit/toJson/generativeRemove.toJson.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import { Transformation } from "../../../src";
import { Effect } from "../../../src/actions/effect";
import { GenerativeRemove } from "../../../src/actions/effect/GenerativeRemove";

describe("GenerativeRemove.toJson()", () => {
it("produces correct action JSON", () => {
const testCases: Array<[GenerativeRemove, unknown]> = [
[
Effect.generativeRemove().prompt("dog"),
{ actionType: "generativeRemove", prompts: ["dog"] },
],
[
Effect.generativeRemove().prompt("dog").detectMultiple(),
{
actionType: "generativeRemove",
prompts: ["dog"],
detectMultiple: true,
},
],
[
Effect.generativeRemove().prompts(["dog", "cat"]),
{ actionType: "generativeRemove", prompts: ["dog", "cat"] },
],
[
Effect.generativeRemove().region({
x: 100,
y: 200,
width: 600,
height: 400,
}),
{
actionType: "generativeRemove",
regions: [{ x: 100, y: 200, width: 600, height: 400 }],
},
],
[
Effect.generativeRemove().regions([
{ x: 100, y: 200, width: 600, height: 400 },
{ x: 300, y: 400, width: 50, height: 60 },
]),
{
actionType: "generativeRemove",
regions: [
{ x: 100, y: 200, width: 600, height: 400 },
{ x: 300, y: 400, width: 50, height: 60 },
],
},
],
];

for (const [action, expectedProps] of testCases) {
const transformation = new Transformation().addAction(action);

expect(transformation.toJson()).toStrictEqual({
actions: [expectedProps],
});
}
});
});
Loading

0 comments on commit 9aec36d

Please sign in to comment.