-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from cloudinary/ME-6260-gen-remove
Add support for Generative Remove effect
- Loading branch information
Showing
6 changed files
with
454 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))", | ||
]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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], | ||
}); | ||
} | ||
}); | ||
}); |
Oops, something went wrong.