Skip to content

Commit

Permalink
feat: add 404 tests to routing
Browse files Browse the repository at this point in the history
  • Loading branch information
ckbedwell committed Oct 13, 2023
1 parent 4d2131f commit 269743a
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/components/Routing.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,28 @@ import React from 'react';
import { screen } from '@testing-library/react';

import { type CustomRenderOptions, createInstance, render } from 'test/render';
import { getRoute, Routing } from './Routing';
import { ROUTES } from 'types';
import { PLUGIN_URL_PATH } from './constants';
import { getRoute, Routing } from './Routing';

function renderRouting(options?: CustomRenderOptions) {
return render(<Routing onNavChanged={jest.fn} />, options);
}

const notaRoute = `${PLUGIN_URL_PATH}/404`;

describe('Only renders the unprovisioned setup page regardless of route when app is not provisioned', () => {
Object.entries(ROUTES).map(([key, route]) => {
test(`Route ${key}`, () => {
renderRouting({ path: getRoute(route), meta: { jsonData: undefined } });
screen.getByText('Provisioning is required for Synthetic Monitoring.');
});
});

test('Non-existent route (404)', () => {
renderRouting({ path: notaRoute, meta: { jsonData: undefined } });
screen.getByText('Provisioning is required for Synthetic Monitoring.');
});
});

describe('Only renders the welcome page regardless of route when app is not initializd', () => {
Expand All @@ -26,6 +34,12 @@ describe('Only renders the welcome page regardless of route when app is not init
screen.getByText('Ready to start using synthetic monitoring?');
});
});

test('Non-existent route (404)', () => {
const instance = createInstance({ api: undefined });
renderRouting({ instance, path: notaRoute });
screen.getByText('Ready to start using synthetic monitoring?');
});
});

// Would like to have asserted on the h1s but rendering the Grafana pluginpage is tricky
Expand Down Expand Up @@ -61,4 +75,10 @@ describe('Routes to pages correctly', () => {
);
expect(configText).toBeInTheDocument();
});

test('Non-existent route redirects to homepage', async () => {
renderRouting({ path: notaRoute });
const homePageText = await screen.findByText('What you can do', { selector: 'h2' });
expect(homePageText).toBeInTheDocument();
});
});

0 comments on commit 269743a

Please sign in to comment.