Skip to content

Commit

Permalink
tests(topbar): remove testdouble
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine committed May 26, 2022
1 parent c55da8b commit 516d192
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
12 changes: 10 additions & 2 deletions flow-report/src/topbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ import {saveFile} from '../../report/renderer/api';
function saveHtml(flowResult: LH.FlowResult, htmlStr: string) {
const blob = new Blob([htmlStr], {type: 'text/html'});
const filename = getFlowResultFilenamePrefix(flowResult) + '.html';
saveFile(blob, filename);
saveHtml.saveFile(blob, filename);
}

// Store `saveFile` here so we can do dependency injection.
saveHtml.saveFile = saveFile;

/* eslint-disable max-len */
const Logo: FunctionComponent = () => {
return (
Expand Down Expand Up @@ -68,7 +71,7 @@ const TopbarButton: FunctionComponent<{
);
};

export const Topbar: FunctionComponent<{onMenuClick: JSX.MouseEventHandler<HTMLButtonElement>}> =
const Topbar: FunctionComponent<{onMenuClick: JSX.MouseEventHandler<HTMLButtonElement>}> =
({onMenuClick}) => {
const flowResult = useFlowResult();
const strings = useLocalizedStrings();
Expand Down Expand Up @@ -118,3 +121,8 @@ export const Topbar: FunctionComponent<{onMenuClick: JSX.MouseEventHandler<HTMLB
</div>
);
};

export {
Topbar,
saveHtml,
};
16 changes: 5 additions & 11 deletions flow-report/test/topbar-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,15 @@
*/

import jestMock from 'jest-mock';
import * as td from 'testdouble';
import {FunctionComponent} from 'preact';
import {act, render} from '@testing-library/preact';

import {FlowResultContext, OptionsContext} from '../src/util';
import {I18nProvider} from '../src/i18n/i18n';
import {Topbar, saveHtml} from '../src/topbar';

const mockSaveFile = jestMock.fn();
td.replace('../../../report/renderer/api.js', {
saveFile: mockSaveFile,
});

let Topbar: typeof import('../src/topbar').Topbar;
before(async () => {
Topbar = (await import('../src/topbar')).Topbar;
});
const defaultSaveFile = saveHtml.saveFile;

const flowResult = {
name: 'User flow',
Expand All @@ -36,6 +29,7 @@ let options: LH.FlowReportOptions;

describe('Topbar', () => {
beforeEach(() => {
saveHtml.saveFile = defaultSaveFile;
mockSaveFile.mockReset();
options = {};
wrapper = ({children}) => (
Expand All @@ -49,9 +43,9 @@ describe('Topbar', () => {
);
});

// TODO(mocha): can't get esbuild loader and testdouble loader to work at same time
it.skip('save button opens save dialog for HTML file', async () => {
it('save button opens save dialog for HTML file', async () => {
options = {getReportHtml: () => '<html></html>'};
saveHtml.saveFile = mockSaveFile;
const root = render(<Topbar onMenuClick={() => {}}/>, {wrapper});

const saveButton = root.getByText('Save');
Expand Down

0 comments on commit 516d192

Please sign in to comment.