chore(react-router-v6): starting to move things to react-router-v6
This commit is contained in:
@@ -25,7 +25,7 @@
|
||||
"react": "^16.13.1",
|
||||
"react-dom": "^16.13.1",
|
||||
"react-markdown": "^4.3.1",
|
||||
"react-router-dom": "^5.2.0",
|
||||
"react-router-dom": "6.0.0-alpha.5",
|
||||
"react-use": "^14.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -22,7 +22,7 @@ jest.mock('react-router-dom', () => {
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
useHistory: jest.fn(() => mocks),
|
||||
useNavigate: jest.fn(() => mocks),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ import AuditList from '.';
|
||||
|
||||
import * as data from '../../__fixtures__/website-list-response.json';
|
||||
|
||||
const { useHistory } = jest.requireMock('react-router-dom');
|
||||
const { useNavigate } = jest.requireMock('react-router-dom');
|
||||
const websiteListResponse = data as WebsiteListResponse;
|
||||
|
||||
describe('AuditList', () => {
|
||||
@@ -145,7 +145,9 @@ describe('AuditList', () => {
|
||||
);
|
||||
const element = await rendered.findByLabelText(/Go to page 1/);
|
||||
fireEvent.click(element);
|
||||
expect(useHistory().replace).toHaveBeenCalledWith(`/lighthouse?page=1`);
|
||||
expect(useNavigate().replace).toHaveBeenCalledWith(
|
||||
`/lighthouse?page=1`,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
import React, { useState, useMemo, FC, ReactNode } from 'react';
|
||||
import { useLocalStorage, useAsync } from 'react-use';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Grid, Button } from '@material-ui/core';
|
||||
import Alert from '@material-ui/lab/Alert';
|
||||
import Pagination from '@material-ui/lab/Pagination';
|
||||
@@ -65,7 +65,7 @@ const AuditList: FC<{}> = () => {
|
||||
return 0;
|
||||
}, [value?.total, value?.limit]);
|
||||
|
||||
const history = useHistory();
|
||||
const history = useNavigate();
|
||||
|
||||
let content: ReactNode = null;
|
||||
if (value) {
|
||||
|
||||
@@ -22,7 +22,7 @@ jest.mock('react-router-dom', () => {
|
||||
};
|
||||
return {
|
||||
...actual,
|
||||
useHistory: jest.fn(() => mocks),
|
||||
useNavigate: jest.fn(() => mocks),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -41,7 +41,7 @@ import { lighthouseApiRef, LighthouseRestApi, Audit } from '../../api';
|
||||
import CreateAudit from '.';
|
||||
import * as data from '../../__fixtures__/create-audit-response.json';
|
||||
|
||||
const { useHistory }: { useHistory: jest.Mock } = jest.requireMock(
|
||||
const { useNavigate }: { useNavigate: jest.Mock } = jest.requireMock(
|
||||
'react-router-dom',
|
||||
);
|
||||
const createAuditResponse = data as Audit;
|
||||
@@ -115,7 +115,7 @@ describe('CreateAudit', () => {
|
||||
|
||||
describe('when the audit is successfully created', () => {
|
||||
it('triggers a location change to the table', async () => {
|
||||
useHistory().push.mockClear();
|
||||
useNavigate().push.mockClear();
|
||||
mockFetch.mockResponseOnce(JSON.stringify(createAuditResponse));
|
||||
|
||||
const rendered = render(
|
||||
@@ -140,7 +140,7 @@ describe('CreateAudit', () => {
|
||||
|
||||
await wait(() => expect(rendered.getByLabelText(/URL/)).toBeEnabled());
|
||||
|
||||
expect(useHistory().push).toHaveBeenCalledWith('/lighthouse');
|
||||
expect(useNavigate().push).toHaveBeenCalledWith('/lighthouse');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
import React, { useState, useCallback, FC } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import {
|
||||
makeStyles,
|
||||
Grid,
|
||||
@@ -40,7 +40,7 @@ import { lighthouseApiRef } from '../../api';
|
||||
import { useQuery } from '../../utils';
|
||||
import LighthouseSupportButton from '../SupportButton';
|
||||
|
||||
const useStyles = makeStyles((theme) => ({
|
||||
const useStyles = makeStyles(theme => ({
|
||||
input: {
|
||||
minWidth: 300,
|
||||
},
|
||||
@@ -58,7 +58,7 @@ const CreateAudit: FC<{}> = () => {
|
||||
const lighthouseApi = useApi(lighthouseApiRef);
|
||||
const classes = useStyles();
|
||||
const query = useQuery();
|
||||
const history = useHistory();
|
||||
const history = useNavigate();
|
||||
const [submitting, setSubmitting] = useState(false);
|
||||
const [url, setUrl] = useState<string>(query.get('url') || '');
|
||||
const [emulatedFormFactor, setEmulatedFormFactor] = useState('mobile');
|
||||
@@ -113,7 +113,7 @@ const CreateAudit: FC<{}> = () => {
|
||||
<Grid item xs={12} sm={6}>
|
||||
<InfoCard>
|
||||
<form
|
||||
onSubmit={(ev) => {
|
||||
onSubmit={ev => {
|
||||
ev.preventDefault();
|
||||
triggerAudit();
|
||||
}}
|
||||
@@ -128,7 +128,7 @@ const CreateAudit: FC<{}> = () => {
|
||||
helperText="The target URL for Lighthouse to use."
|
||||
required
|
||||
disabled={submitting}
|
||||
onChange={(ev) => setUrl(ev.target.value)}
|
||||
onChange={ev => setUrl(ev.target.value)}
|
||||
value={url}
|
||||
inputProps={{ 'aria-label': 'URL' }}
|
||||
/>
|
||||
@@ -142,7 +142,7 @@ const CreateAudit: FC<{}> = () => {
|
||||
select
|
||||
required
|
||||
disabled={submitting}
|
||||
onChange={(ev) => setEmulatedFormFactor(ev.target.value)}
|
||||
onChange={ev => setEmulatedFormFactor(ev.target.value)}
|
||||
value={emulatedFormFactor}
|
||||
inputProps={{ 'aria-label': 'Emulated form factor' }}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user