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

Open
wants to merge 23 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
23 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
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
14 changes: 10 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 @@ -102,12 +102,18 @@ export class PageController {

/**
* 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
* @param settings an object to specify desired snapshot properties, e.g., resolution.
* If it's not provided, default settings will be applied, e.g., page resolution.
* Limit for `largestAxisSize` is 1000 px
* @returns UInt8Array snapshot of the given page
*/
getSnapshot = async (pageId: Id) => {
getSnapshot = async (pageId?: Id, settings?: SnapshotSettings | null) => {
const res = await this.#blobAPI;
return res.getPageSnapshot(pageId).then((result) => (result as Uint8Array) ?? (result as EditorResponse<null>));
return res
.getPageSnapshotWithSettings(pageId, settings)
evan-mcgeek marked this conversation as resolved.
Show resolved Hide resolved
.then((result) => (result as Uint8Array) ?? (result as EditorResponse<null>));
};

/**
Expand Down
16 changes: 9 additions & 7 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 @@ -11,8 +12,7 @@ const mockEditorApi: EditorAPI = {
setPageHeight: async (id: unknown) => getEditorResponseData(castToEditorResponse(id)),
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])),
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 @@ -28,7 +28,7 @@ beforeEach(() => {
jest.spyOn(mockEditorApi, 'setPageHeight');
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 +83,13 @@ describe('PageController', () => {
expect(mockEditorApi.setPageHeight).toHaveBeenCalledWith('id', '4');
});

it('Should call the getSnapshot method', async () => {
await mockedPageController.getSnapshot('1');
expect(mockEditorApi.getPageSnapshot).toHaveBeenCalledTimes(1);
expect(mockEditorApi.getPageSnapshot).toHaveBeenCalledWith('1');
it('getSnapshot should call the getSnapshotWithSettings method', async () => {
const settings = { largestAxisSize: 5 } as SnapshotSettings;
await mockedPageController.getSnapshot('1', settings);
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledTimes(1);
expect(mockEditorApi.getPageSnapshotWithSettings).toHaveBeenCalledWith('1', settings);
});

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