Skip to content

Commit

Permalink
[Feature] Remove multiple frames (#392)
Browse files Browse the repository at this point in the history
* [EDT-1187] new method added to remove multiple frames at once
  • Loading branch information
evan-mcgeek authored Jan 18, 2024
1 parent 50b17bd commit b8e6ebf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
12 changes: 11 additions & 1 deletion packages/sdk/src/controllers/FrameController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,17 @@ export class FrameController {
*/
remove = async (id: Id) => {
const res = await this.#editorAPI;
return res.removeFrame(id).then((result) => getEditorResponseData<null>(result));
return res.removeFrames([id]).then((result) => getEditorResponseData<null>(result));
};

/**
* This method will remove frames with the given ids.
* @param ids an array of ids of the frames to be removed.
* @returns
*/
removeFrames = async (ids: Id[]) => {
const res = await this.#editorAPI;
return res.removeFrames(ids).then((result) => getEditorResponseData<null>(result));
};

/**
Expand Down
13 changes: 10 additions & 3 deletions packages/sdk/src/tests/controllers/FrameController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const mockedEditorApi: EditorAPI = {
setFrameRotation: async () => getEditorResponseData(castToEditorResponse(null)),
setFrameIsVisible: async () => getEditorResponseData(castToEditorResponse(null)),
removeFrame: async () => getEditorResponseData(castToEditorResponse(null)),
removeFrames: async () => getEditorResponseData(castToEditorResponse(null)),
resetFrame: async () => getEditorResponseData(castToEditorResponse(null)),
resetFrameX: async () => getEditorResponseData(castToEditorResponse(null)),
resetFrameY: async () => getEditorResponseData(castToEditorResponse(null)),
Expand Down Expand Up @@ -89,7 +90,7 @@ beforeEach(() => {
jest.spyOn(mockedEditorApi, 'setFrameY');
jest.spyOn(mockedEditorApi, 'setFrameRotation');
jest.spyOn(mockedEditorApi, 'setFrameIsVisible');
jest.spyOn(mockedEditorApi, 'removeFrame');
jest.spyOn(mockedEditorApi, 'removeFrames');
jest.spyOn(mockedEditorApi, 'resetFrame');
jest.spyOn(mockedEditorApi, 'resetFrameX');
jest.spyOn(mockedEditorApi, 'resetFrameY');
Expand Down Expand Up @@ -249,8 +250,14 @@ describe('FrameController', () => {

it('Should be possible to remove a frame', async () => {
await mockedFrameController.remove(id);
expect(mockedEditorApi.removeFrame).toHaveBeenCalledTimes(1);
expect(mockedEditorApi.removeFrame).toHaveBeenCalledWith(id);
expect(mockedEditorApi.removeFrames).toHaveBeenCalledTimes(1);
expect(mockedEditorApi.removeFrames).toHaveBeenCalledWith([id]);
});

it('Should be possible to remove frames', async () => {
await mockedFrameController.removeFrames([id]);
expect(mockedEditorApi.removeFrames).toHaveBeenCalledTimes(2);
expect(mockedEditorApi.removeFrames).toHaveBeenCalledWith([id]);
});

it('Should be possible to reset a frame', async () => {
Expand Down

0 comments on commit b8e6ebf

Please sign in to comment.