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

[Feature] Add default font #232

Merged
merged 2 commits into from
Jan 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 9 additions & 0 deletions src/controllers/FontController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ export class FontController {
return res.getFontById(fontId).then((result) => getEditorResponseData<DocumentFont>(result));
};

/**
* This method returns the default font.
* @returns
*/
Matthiee marked this conversation as resolved.
Show resolved Hide resolved
getDefaultFont = async () => {
const res = await this.#editorAPI;
return res.getDefaultFont().then((result) => getEditorResponseData<DocumentFont>(result));
};

/**
* This method removes a font
* @param id The ID of a specific font
Expand Down
14 changes: 14 additions & 0 deletions src/tests/__mocks__/MockEditorAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down Expand Up @@ -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,
Expand Down
69 changes: 69 additions & 0 deletions src/tests/controllers/FontController.test.ts
Original file line number Diff line number Diff line change
@@ -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);
});
});