Skip to content

Commit

Permalink
10472: address final feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
JayFlexy committed Dec 20, 2024
1 parent 935bf70 commit c21a605
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { applicationContextForClient as applicationContext } from '@web-client/test/createClientTestApplicationContext';
import { loadPdfForTabAction } from '../PDFPreviewTab/loadPdfForTabAction';
import { openUrlInNewTab } from '@web-client/presenter/utilities/openUrlInNewTab';
import { presenter } from '../../presenter-mock';
import { runAction } from '@web-client/presenter/test.cerebral';
import { testPdfDoc } from '../../../../../shared/src/business/test/getFakeFile';

jest.mock('@web-client/presenter/utilities/openUrlInNewTab');

describe('loadPdfForTabAction', () => {
let originalWindowOpen;

Expand Down Expand Up @@ -52,11 +55,13 @@ describe('loadPdfForTabAction', () => {
createObjectURL: jest.fn().mockReturnValue('some url'),
};
originalWindowOpen = window.open;
(openUrlInNewTab as jest.Mock).mockImplementation(jest.fn());
window.open = jest.fn();
});

afterAll(() => {
window.open = originalWindowOpen;
jest.restoreAllMocks();
});

it('should call window.open with correcturl for pdf file', async () => {
Expand All @@ -67,7 +72,7 @@ describe('loadPdfForTabAction', () => {
props: { file: fakeFile },
});

expect(window.open).toHaveBeenCalledWith('some url', '_blank');
expect(openUrlInNewTab).toHaveBeenCalledWith({ url: 'some url' });
});

it('should detect binary (not base64-encoded) pdf data and read it successfully', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { openUrlInNewTab } from '../../utilities/openUrlInNewTab';
export const loadPdfForTabAction = ({
applicationContext,
props,
Expand All @@ -23,7 +24,7 @@ export const loadPdfForTabAction = ({
// @ts-ignore
new Blob([binaryFile], { type: 'application/pdf' }),
);
window.open(pdfDataUri, '_blank');
openUrlInNewTab({ url: pdfDataUri });
resolve();
} catch (err) {
reject(err);
Expand Down

0 comments on commit c21a605

Please sign in to comment.