Skip to content

Commit

Permalink
chore: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Conrad Chan committed Aug 5, 2021
1 parent 258df98 commit 48a02ed
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 13 deletions.
38 changes: 26 additions & 12 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import DocPreloader from '../DocPreloader';
import fullscreen from '../../../Fullscreen';
import {
ANNOTATOR_EVENT,
BROWSERS,
CLASS_ANNOTATIONS_DOCUMENT_FTUX_CURSOR_SEEN,
CLASS_BOX_PREVIEW_THUMBNAILS_CONTAINER,
CLASS_BOX_PREVIEW_THUMBNAILS_OPEN,
CLASS_HIDDEN,
DOCUMENT_FTUX_CURSOR_SEEN_KEY,
ENCODING_TYPES,
PERMISSION_DOWNLOAD,
STATUS_ERROR,
STATUS_PENDING,
STATUS_SUCCESS,
QUERY_PARAM_ENCODING,
ENCODING_TYPES,
SELECTOR_BOX_PREVIEW_CONTENT,
CLASS_ANNOTATIONS_DOCUMENT_FTUX_CURSOR_SEEN,
CLASS_BOX_PREVIEW_THUMBNAILS_CONTAINER,
CLASS_BOX_PREVIEW_THUMBNAILS_OPEN,
SELECTOR_BOX_PREVIEW,
STATUS_ERROR,
STATUS_PENDING,
STATUS_SUCCESS,
} from '../../../constants';
import { ICON_PRINT_CHECKMARK } from '../../../icons';
import { LOAD_METRIC, RENDER_EVENT, USER_DOCUMENT_THUMBNAIL_EVENTS, VIEWER_EVENT } from '../../../events';
Expand Down Expand Up @@ -598,11 +599,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
describe('load()', () => {
const loadFunc = BaseViewer.prototype.load;

afterEach(() => {
Object.defineProperty(BaseViewer.prototype, 'load', { value: loadFunc });
});

test('should load a document', () => {
beforeEach(() => {
jest.spyOn(stubs.api, 'get').mockImplementation();
jest.spyOn(docBase, 'setup').mockImplementation();
Object.defineProperty(BaseViewer.prototype, 'load', { value: sandbox.mock() });
Expand All @@ -611,14 +608,31 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
jest.spyOn(docBase, 'getRepStatus').mockReturnValue({ getPromise: () => Promise.resolve() });
jest.spyOn(docBase, 'loadAssets').mockImplementation();
jest.spyOn(docBase, 'loadBoxAnnotations').mockImplementation();
});

afterEach(() => {
Object.defineProperty(BaseViewer.prototype, 'load', { value: loadFunc });
});

test('should load a document', () => {
return docBase.load().then(() => {
expect(docBase.loadAssets).toBeCalled();
expect(docBase.setup).not.toBeCalled();
expect(docBase.createContentUrlWithAuthParams).toBeCalledWith('foo');
expect(docBase.handleAssetAndRepLoad).toBeCalled();
});
});

test('should show notification if file has excel extension and is internet explorer', () => {
const showNotification = jest.fn();
docBase.options.ui = { showNotification };
docBase.options.file.extension = 'xlsx';
jest.spyOn(Browser, 'getName').mockImplementation(() => BROWSERS.INTERNET_EXPLORER);

return docBase.load().then(() => {
expect(showNotification).toBeCalledWith(__('error_internet_explorer_office_online'), null, true);
});
});
});

describe('handleAssetAndRepLoad', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/viewers/office/__tests__/OfficeLoader-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import * as file from '../../../file';
import Browser from '../../../Browser';
import OfficeLoader from '../OfficeLoader';
import OfficeViewer from '../OfficeViewer';
import * as file from '../../../file';
import { BROWSERS } from '../../../constants';

const FIVE_MB = 5242880;

Expand Down Expand Up @@ -86,6 +88,12 @@ describe('lib/viewers/office/OfficeLoader', () => {
const viewer = OfficeLoader.determineViewer(editedFakeFile, [], viewerOptions);
expect(viewer).toBeDefined();
});

test('should not return a viewer if the browser is internet explorer', () => {
jest.spyOn(Browser, 'getName').mockImplementation(() => BROWSERS.INTERNET_EXPLORER);
const viewer = OfficeLoader.determineViewer(fakeFile, []);
expect(viewer).toBeUndefined();
});
});
});
});

0 comments on commit 48a02ed

Please sign in to comment.