-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
106 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import { screen } from '@testing-library/react'; | ||
import { type CustomRenderOptions, render } from 'test/render'; | ||
|
||
import { ROUTES } from 'types'; | ||
import { PLUGIN_URL_PATH } from 'routing/constants'; | ||
import { UninitialisedRouter } from 'routing/UninitialisedRouter'; | ||
import { getRoute } from 'routing/utils'; | ||
|
||
function renderUninitialisedRouting(options?: CustomRenderOptions) { | ||
render(<UninitialisedRouter />, options); | ||
} | ||
|
||
const notaRoute = `${PLUGIN_URL_PATH}/404`; | ||
|
||
describe('Renders specific welcome pages when app is not initializd', () => { | ||
test(`Route Home`, async () => { | ||
renderUninitialisedRouting({ path: getRoute(ROUTES.Home) }); | ||
const text = await screen.findByText('Up and running in seconds, no instrumentation required'); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
test(`Route Probes`, async () => { | ||
renderUninitialisedRouting({ path: getRoute(ROUTES.Probes) }); | ||
const text = await screen.findByText( | ||
'Click the See Probes button to initialize the plugin and see a list of public probes', | ||
{ exact: false } | ||
); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
test(`Route Alerts`, async () => { | ||
renderUninitialisedRouting({ path: getRoute(ROUTES.Alerts) }); | ||
const text = await screen.findByText( | ||
'Click the See Alerting button to initialize the plugin and see a list of default alerts', | ||
{ exact: false } | ||
); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
test(`Route Checks`, async () => { | ||
renderUninitialisedRouting({ path: getRoute(ROUTES.Checks) }); | ||
const text = await screen.findByText('Click the Create a Check button to initialize the plugin and create checks', { | ||
exact: false, | ||
}); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
test(`Route Config`, async () => { | ||
renderUninitialisedRouting({ path: getRoute(ROUTES.Config) }); | ||
|
||
const text = await screen.findByText('Synthetic Monitoring is not yet initialized'); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
|
||
test('Non-existent route (404)', async () => { | ||
renderUninitialisedRouting({ path: notaRoute }); | ||
const text = await screen.findByText('Up and running in seconds, no instrumentation required'); | ||
expect(text).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React from 'react'; | ||
import { Navigate, Route, Routes } from 'react-router-dom-v5-compat'; | ||
|
||
import { ROUTES } from 'types'; | ||
import { useMeta } from 'hooks/useMeta'; | ||
import { AlertingWelcomePage } from 'page/AlertingWelcomePage'; | ||
import { ChecksWelcomePage } from 'page/ChecksWelcomePage'; | ||
import { ConfigPageLayout } from 'page/ConfigPageLayout'; | ||
import { UninitializedTab } from 'page/ConfigPageLayout/tabs/UninitializedTab'; | ||
import { ProbesWelcomePage } from 'page/ProbesWelcomePage'; | ||
import { UnprovisionedSetup } from 'page/UnprovisionedSetup'; | ||
import { WelcomePage } from 'page/WelcomePage'; | ||
|
||
export const UninitialisedRouter = () => { | ||
const meta = useMeta(); | ||
const provisioned = Boolean(meta.jsonData?.metrics?.grafanaName); | ||
|
||
// todo: is this the correct check for provisioning? | ||
// todo: is this state even possible in Grafana v11? | ||
if (!provisioned) { | ||
return <UnprovisionedSetup />; | ||
} | ||
|
||
return ( | ||
<Routes> | ||
<Route path={ROUTES.Home} element={<WelcomePage />} /> | ||
<Route path={ROUTES.Scene} element={<WelcomePage />} /> | ||
<Route path={ROUTES.Checks} element={<ChecksWelcomePage />} /> | ||
<Route path={ROUTES.Probes} element={<ProbesWelcomePage />} /> | ||
<Route path={ROUTES.Alerts} element={<AlertingWelcomePage />} /> | ||
<Route path={ROUTES.Config} Component={ConfigPageLayout}> | ||
<Route index element={<UninitializedTab />} /> | ||
<Route path="*" element={<UninitializedTab />} /> | ||
</Route> | ||
|
||
{/* TODO: Create 404 instead of navigating to home(?) */} | ||
<Route path="*" element={<Navigate to={ROUTES.Home} />} /> | ||
</Routes> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { InitialisedRouter, UninitialisedRouter } from './Routers'; | ||
export { InitialisedRouter } from './InitialisedRouter'; | ||
export { UninitialisedRouter } from './UninitialisedRouter'; |