diff --git a/src/components/Routing.test.tsx b/src/components/Routing.test.tsx index 694f997a7..002f743a9 100644 --- a/src/components/Routing.test.tsx +++ b/src/components/Routing.test.tsx @@ -2,13 +2,16 @@ 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(, 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}`, () => { @@ -16,6 +19,11 @@ describe('Only renders the unprovisioned setup page regardless of route when app 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', () => { @@ -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 @@ -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(); + }); });