Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EDT-1765] SnapshotSettings introduced #549

Merged
merged 25 commits into from
Feb 10, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
4af8044
[EDT-1765] SnapshotSettings introduced
evan-mcgeek Dec 19, 2024
a4ceae5
[EDT-1765] reverted old method
evan-mcgeek Dec 19, 2024
a17e866
Merge branch 'main' into feature/EDT-1765-major-axis-size
evan-mcgeek Dec 19, 2024
abad45c
Merge branch 'main' into feature/EDT-1765-major-axis-size
evan-mcgeek Jan 6, 2025
8229192
Merge branch 'main' into feature/EDT-1765-major-axis-size
evan-mcgeek Jan 16, 2025
cfa32cd
[EDT-1765] nullable SnapshotSettings instead of deprecation
evan-mcgeek Jan 16, 2025
b127c20
[EDT-1765] SnapshotSettings introduced
evan-mcgeek Dec 19, 2024
0ae9ff9
[EDT-1765] reverted old method
evan-mcgeek Dec 19, 2024
2fa7395
[Fix][EDT-1745] Fix missing configuration (#554)
NicolaVerbeeck Dec 30, 2024
5418ad3
CI: bumps version to 1.18.1-rc.4 [skip ci]
gh-action-bump-version Dec 30, 2024
6df0d5b
[FIX] Add smartCrop and manualCrop fitModes (#556)
abdelhalimkhouas Dec 30, 2024
79d086a
CI: bumps version to 1.18.1-rc.5 [skip ci]
gh-action-bump-version Dec 30, 2024
1d51bfe
[Feature][EDT-1762] layout display name (#553)
evan-mcgeek Jan 16, 2025
e85c4fc
CI: bumps version to 1.18.1-rc.6 [skip ci]
gh-action-bump-version Jan 16, 2025
0a39818
[EDT-1765] nullable SnapshotSettings instead of deprecation
evan-mcgeek Jan 16, 2025
c8a5f72
Merge remote-tracking branch 'origin/feature/EDT-1765-major-axis-size…
evan-mcgeek Jan 16, 2025
d9b4737
[EDT-1765] fix: a better comment
evan-mcgeek Feb 3, 2025
4819193
[EDT-1765] fix: even better comment
evan-mcgeek Feb 3, 2025
6387dd2
[EDT-1765] JSON.stringify
evan-mcgeek Feb 3, 2025
f33507d
Merge branch 'main' into feature/EDT-1765-major-axis-size
evan-mcgeek Feb 3, 2025
0bd9e50
[EDT-1765] comment on largestAxisSize property
evan-mcgeek Feb 6, 2025
8dc1416
Merge branch 'main' into feature/EDT-1765-major-axis-size
evan-mcgeek Feb 6, 2025
e5dbe94
[EDT-1765] feat: comment on largestAxisSize property
evan-mcgeek Feb 6, 2025
b5643de
[EDT-1765] not stringify null
evan-mcgeek Feb 10, 2025
72020f1
[EDT-1765] feat: not stringify null
evan-mcgeek Feb 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions packages/sdk/src/controllers/PageController.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { EditorAPI, EditorRawAPI, EditorResponse, Id } from '../types/CommonTypes';
import { getEditorResponseData } from '../utils/EditorResponseData';
import { Page } from '../types/PageTypes';
import { Page, SnapshotSettings } from '../types/PageTypes';
import { CallSender } from 'penpal';

/**
Expand Down Expand Up @@ -101,13 +101,31 @@ export class PageController {
};

/**
* @deprecated Use 'getSnapshotWithSettings' instead
* This method returns a UInt8Array containing a PNG encoded image of the page.
* @param pageId the id of a specific page
* @param pageId The id of a specific page.
* If not specified, selected page snapshot will be provided
* @returns UInt8Array snapshot of the given page
*/
getSnapshot = async (pageId?: Id) => {
const res = await this.#blobAPI;
return res
.getPageSnapshotWithSettings(pageId, null)
.then((result) => (result as Uint8Array) ?? (result as EditorResponse<null>));
};

/**
* This method returns a UInt8Array containing a PNG encoded image of the page.
* @param pageId The id of a specific page.
* If not specified, selected page snapshot will be provided
* @param settings an object to specify desired snapshot properties, e.g., resolution
* @returns UInt8Array snapshot of the given page
*/
getSnapshot = async (pageId: Id) => {
getSnapshotWithSettings = async (pageId?: Id, settings?: SnapshotSettings) => {
const res = await this.#blobAPI;
return res.getPageSnapshot(pageId).then((result) => (result as Uint8Array) ?? (result as EditorResponse<null>));
return res
.getPageSnapshotWithSettings(pageId, JSON.stringify(settings))
evan-mcgeek marked this conversation as resolved.
Show resolved Hide resolved
.then((result) => (result as Uint8Array) ?? (result as EditorResponse<null>));
};

/**
Expand Down
20 changes: 16 additions & 4 deletions packages/sdk/src/tests/controllers/PageController.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EditorAPI } from '../../types/CommonTypes';
import { PageController } from '../../controllers/PageController';
import { castToEditorResponse, getEditorResponseData } from '../../utils/EditorResponseData';
import { SnapshotSettings } from '../../types/PageTypes';

let mockedPageController: PageController;

Expand All @@ -12,7 +13,8 @@ const mockEditorApi: EditorAPI = {
addPage: async () => getEditorResponseData(castToEditorResponse('frameID')),
removePage: async (id: unknown) => getEditorResponseData(castToEditorResponse(id)),
// eslint-disable-next-line @typescript-eslint/no-unused-vars
getPageSnapshot: async (id: unknown) => getEditorResponseData(castToEditorResponse([1])),
getPageSnapshot: async () => getEditorResponseData(castToEditorResponse([1])),
getPageSnapshotWithSettings: async () => getEditorResponseData(castToEditorResponse([1])),
selectPage: async (id: unknown) => getEditorResponseData(castToEditorResponse(id)),
duplicatePage: async (id: unknown) => getEditorResponseData(castToEditorResponse(id)),
setPageIsVisible: async (id: unknown, isVisible: unknown) =>
Expand All @@ -29,6 +31,7 @@ beforeEach(() => {
jest.spyOn(mockEditorApi, 'addPage');
jest.spyOn(mockEditorApi, 'removePage');
jest.spyOn(mockEditorApi, 'getPageSnapshot');
jest.spyOn(mockEditorApi, 'getPageSnapshotWithSettings');
jest.spyOn(mockEditorApi, 'selectPage');
jest.spyOn(mockEditorApi, 'setPageIsVisible');
jest.spyOn(mockEditorApi, 'duplicatePage');
Expand Down Expand Up @@ -83,11 +86,20 @@ describe('PageController', () => {
expect(mockEditorApi.setPageHeight).toHaveBeenCalledWith('id', '4');
});

it('Should call the getSnapshot method', async () => {
it('Should call the getSnapshotWithSettings method', async () => {
const settings = { largestAxisSize: 5 } as SnapshotSettings;

await mockedPageController.getSnapshotWithSettings('1', settings);
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledTimes(1);
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledWith('1', JSON.stringify(settings));
});

it('getSnapshot should call the getSnapshotWithSettings method', async () => {
await mockedPageController.getSnapshot('1');
expect(mockEditorApi.getPageSnapshot).toHaveBeenCalledTimes(1);
expect(mockEditorApi.getPageSnapshot).toHaveBeenCalledWith('1');
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledTimes(2);
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledWith('1', null);
});

it('Should accept calculations for the pageHeight and pageWidth methods', async () => {
await mockedPageController.setHeight('id', '4+2');
expect(mockEditorApi.setPageHeight).toHaveBeenCalledTimes(2);
Expand Down
4 changes: 4 additions & 0 deletions packages/sdk/src/types/PageTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ export type PageSize = {
width: number;
height: number;
};

export interface SnapshotSettings {
largestAxisSize?: number | null;
evan-mcgeek marked this conversation as resolved.
Show resolved Hide resolved
}
Loading