fix: use '../' instead of '../../' for relative paths

With `../../audit/<id>` we navigate from `/<base-url>/audit/<id>` to `/audit/<id>` but this is wrong because the base path is missing. Therefore we use `../audit/<id>` and this will navigate to the right url with respect to the base path.

Signed-off-by: Salih Candir <salih@live.at>
This commit is contained in:
Salih Candir
2022-12-14 11:27:47 +01:00
committed by Salih Candir
parent b8aa070dc4
commit ef795700d6
2 changed files with 24 additions and 2 deletions
@@ -149,6 +149,28 @@ describe('AuditView', () => {
).toHaveAttribute('href', `/audit/${a.id}`);
});
});
it('navigates to the next report with respect to the base path', async () => {
// TODO: I would need help here. How to set the base path for the test?
const basePath = `/lighthouse`;
const rendered = render(
wrapInTestApp(
<ApiProvider apis={apis}>
<AuditView />
</ApiProvider>,
{ routeEntries: [basePath] },
),
);
await rendered.findByTestId('audit-sidebar');
websiteResponse.audits.forEach(a => {
expect(
rendered.getByText(formatTime(a.timeCreated)).parentElement
?.parentElement,
).toHaveAttribute('href', `${basePath}/audits/${a.id}`);
});
});
});
describe('when the request for the website by id is pending', () => {
@@ -80,7 +80,7 @@ const AuditLinkList = ({ audits = [], selectedId }: AuditLinkListProps) => (
button
component={Link}
replace
to={resolvePath(generatePath('audit/:id', { id: audit.id }), '../../')}
to={resolvePath(generatePath('audit/:id', { id: audit.id }), '../')}
>
<ListItemIcon>
<AuditStatusIcon audit={audit} />
@@ -178,7 +178,7 @@ export const AuditViewContent = () => {
<Button
variant="contained"
color="primary"
onClick={() => navigate(`../../${createAuditButtonUrl}`)}
onClick={() => navigate(`../${createAuditButtonUrl}`)}
>
Create New Audit
</Button>