diff --git a/src/controllers/FontController.ts b/src/controllers/FontController.ts index 4ba0072f..5d846257 100644 --- a/src/controllers/FontController.ts +++ b/src/controllers/FontController.ts @@ -38,6 +38,17 @@ export class FontController { return res.getFontById(fontId).then((result) => getEditorResponseData(result)); }; + /** + * This method returns the default font. + * Be aware that the default font will not change during the entire lifetime of the SDK session. + * It is not necessary to call this more than once in an integration, this value can be safely stored during the lifetime of this SDK session. + * @returns + */ + getDefaultFont = async () => { + const res = await this.#editorAPI; + return res.getDefaultFont().then((result) => getEditorResponseData(result)); + }; + /** * This method removes a font * @param id The ID of a specific font diff --git a/src/tests/__mocks__/MockEditorAPI.ts b/src/tests/__mocks__/MockEditorAPI.ts index ac3e23c9..6c376475 100644 --- a/src/tests/__mocks__/MockEditorAPI.ts +++ b/src/tests/__mocks__/MockEditorAPI.ts @@ -110,6 +110,14 @@ export const mockUpdateCharacterStyle = jest.fn().mockResolvedValue({ success: t export const mockDuplicateCharacterStyle = jest.fn().mockResolvedValue({ success: true, status: 0 }); export const mockRenameCharacterStyle = jest.fn().mockResolvedValue({ success: true, status: 0 }); export const mockRemoveCharacterStyle = jest.fn().mockResolvedValue({ success: true, status: 0 }); + +export const mockGetFonts = jest.fn().mockResolvedValue({ success: true, status: 0 }); +export const mockGetFontById = jest.fn().mockResolvedValue({ success: true, status: 0 }); +export const mockGetDefaultFont = jest.fn().mockResolvedValue({ success: true, status: 0 }); +export const mockRemoveFont = jest.fn().mockResolvedValue({ success: true, status: 0 }); +export const mockAddFont = jest.fn().mockResolvedValue({ success: true, status: 0 }); +export const mockIsFontUsed = jest.fn().mockResolvedValue({ success: true, status: 0 }); + export const mockMediaConnectorQuery = jest.fn().mockResolvedValue({ success: true, status: 0 }); export const mockMediaConnectorDownload = jest.fn().mockResolvedValue({ success: true, status: 0 }); export const mockMediaConnectorRemove = jest.fn().mockResolvedValue({ success: true, status: 0 }); @@ -280,6 +288,12 @@ const MockEditorAPI = { removeCharacterStyle: mockRemoveCharacterStyle, renameCharacterStyle: mockRenameCharacterStyle, duplicateCharacterStyle: mockDuplicateCharacterStyle, + getFonts: mockGetFonts, + getFontById: mockGetFontById, + getDefaultFont: mockGetDefaultFont, + removeFont: mockRemoveFont, + addFont: mockAddFont, + isFontUsed: mockIsFontUsed, mediaConnectorCopy: mockMediaConnectorCopy, mediaConnectorQuery: mockMediaConnectorQuery, mediaConnectorDownload: mockMediaConnectorDownload, diff --git a/src/tests/controllers/FontController.test.ts b/src/tests/controllers/FontController.test.ts new file mode 100644 index 00000000..6daa1ea9 --- /dev/null +++ b/src/tests/controllers/FontController.test.ts @@ -0,0 +1,69 @@ +import MockEditorAPI from '../__mocks__/MockEditorAPI'; +import { FontController } from '../../controllers/FontController'; +import { AddDocumentFont } from '../../../types/FontTypes'; + +let mockedFontController: FontController; + +beforeEach(() => { + mockedFontController = new FontController(MockEditorAPI); + jest.spyOn(mockedFontController, 'getFonts'); + jest.spyOn(mockedFontController, 'getFontById'); + jest.spyOn(mockedFontController, 'getDefaultFont'); + jest.spyOn(mockedFontController, 'removeFont'); + jest.spyOn(mockedFontController, 'addFont'); + jest.spyOn(mockedFontController, 'isFontUsed'); +}); + +afterAll(() => { + jest.restoreAllMocks(); +}); + +describe('Font Controller', () => { + it('calls getFonts', () => { + mockedFontController.getFonts(); + expect(mockedFontController.getFonts).toHaveBeenCalledTimes(1); + }); + + it('calls getFontById', () => { + const fontId = 'fontId'; + mockedFontController.getFontById(fontId); + expect(mockedFontController.getFontById).toHaveBeenCalledTimes(1); + expect(mockedFontController.getFontById).toHaveBeenCalledWith(fontId); + }); + + it('calls getDefaultFont', () => { + mockedFontController.getDefaultFont(); + expect(mockedFontController.getDefaultFont).toHaveBeenCalledTimes(1); + }); + + it('calls removeFont', () => { + const fontId = 'fontId'; + mockedFontController.removeFont(fontId); + expect(mockedFontController.removeFont).toHaveBeenCalledTimes(1); + expect(mockedFontController.removeFont).toHaveBeenCalledWith(fontId); + }); + + it('calls addFont', () => { + const fontAddModel: AddDocumentFont = { + fontFamily: 'family', + fontId: 'fontId', + fontStyle: 'fontStyle', + name: 'fontName', + }; + const connectorId = 'connectorId'; + + mockedFontController.addFont(connectorId, fontAddModel); + + expect(mockedFontController.addFont).toHaveBeenCalledTimes(1); + expect(mockedFontController.addFont).toHaveBeenCalledWith(connectorId, fontAddModel); + }); + + it('calls isFontUsed', () => { + const fontId = 'fontId'; + + mockedFontController.isFontUsed(fontId); + + expect(mockedFontController.isFontUsed).toHaveBeenCalledTimes(1); + expect(mockedFontController.isFontUsed).toHaveBeenCalledWith(fontId); + }); +});