From 47766635b67c52be748d68aa1631780fa5388142 Mon Sep 17 00:00:00 2001 From: blam Date: Thu, 11 Jun 2020 20:20:58 +0200 Subject: [PATCH] chore(react-router-v6): Fixing navigation in the lighthouse plugin --- .../src/components/AuditList/index.test.tsx | 12 ++++-------- .../lighthouse/src/components/AuditView/index.tsx | 2 +- .../src/components/CreateAudit/index.test.tsx | 11 ++++------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/plugins/lighthouse/src/components/AuditList/index.test.tsx b/plugins/lighthouse/src/components/AuditList/index.test.tsx index 612bed4635..076bb5819a 100644 --- a/plugins/lighthouse/src/components/AuditList/index.test.tsx +++ b/plugins/lighthouse/src/components/AuditList/index.test.tsx @@ -16,13 +16,10 @@ jest.mock('react-router-dom', () => { const actual = jest.requireActual('react-router-dom'); - const mocks = { - replace: jest.fn(), - push: jest.fn(), - }; + const mockNavigation = jest.fn(); return { ...actual, - useNavigate: jest.fn(() => mocks), + useNavigate: jest.fn(() => mockNavigation), }; }); @@ -145,9 +142,8 @@ describe('AuditList', () => { ); const element = await rendered.findByLabelText(/Go to page 1/); fireEvent.click(element); - expect(useNavigate().replace).toHaveBeenCalledWith( - `/lighthouse?page=1`, - ); + + expect(useNavigate()).toHaveBeenCalledWith(`/lighthouse?page=1`); }); }); }); diff --git a/plugins/lighthouse/src/components/AuditView/index.tsx b/plugins/lighthouse/src/components/AuditView/index.tsx index 06ab812cf4..d323b1a005 100644 --- a/plugins/lighthouse/src/components/AuditView/index.tsx +++ b/plugins/lighthouse/src/components/AuditView/index.tsx @@ -21,6 +21,7 @@ import { Grid, List, ListItem, + Button, ListItemIcon, ListItemText, } from '@material-ui/core'; @@ -32,7 +33,6 @@ import { Header, Page, Content, - Button, ContentHeader, HeaderLabel, Progress, diff --git a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx index 39c109788f..ee0404fc22 100644 --- a/plugins/lighthouse/src/components/CreateAudit/index.test.tsx +++ b/plugins/lighthouse/src/components/CreateAudit/index.test.tsx @@ -16,13 +16,10 @@ jest.mock('react-router-dom', () => { const actual = jest.requireActual('react-router-dom'); - const mocks = { - replace: jest.fn(), - push: jest.fn(), - }; + const mockNavigate = jest.fn(); return { ...actual, - useNavigate: jest.fn(() => mocks), + useNavigate: jest.fn(() => mockNavigate), }; }); @@ -115,7 +112,7 @@ describe('CreateAudit', () => { describe('when the audit is successfully created', () => { it('triggers a location change to the table', async () => { - useNavigate().push.mockClear(); + useNavigate.mockClear(); mockFetch.mockResponseOnce(JSON.stringify(createAuditResponse)); const rendered = render( @@ -140,7 +137,7 @@ describe('CreateAudit', () => { await wait(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled()); - expect(useNavigate().push).toHaveBeenCalledWith('/lighthouse'); + expect(useNavigate()).toHaveBeenCalledWith('/lighthouse'); }); });