Files
grafana/public/app/features/dashboard-scene/inspect/PanelInspectDrawer.test.tsx
Dominik Prokop 8e078315f0 Schema v2: Reason about new dashboard based on UID (#98879)
* Schema v2: Reason about new dashboard based on UID

* Fix test

* Alerting: respect isNew dashboard for legacy and new arch

* Translate untranslated strings

* Unify is new checks

* PanelInspectDrawer update

* typo fix

* on close test for panel inspect drawer

* Update public/app/features/alerting/unified/PanelAlertTabContent.tsx
2025-01-27 11:18:06 +01:00

77 lines
1.8 KiB
TypeScript

import { locationService } from '@grafana/runtime';
import { DashboardScene, DashboardSceneState } from '../scene/DashboardScene';
import { DefaultGridLayoutManager } from '../scene/layout-default/DefaultGridLayoutManager';
import { onPanelInspectClose } from './PanelInspectDrawer';
describe('onPanelInspectClose', () => {
test('when on default home dashboard page', async () => {
locationService.push('/');
const { scene } = await buildTestScene({
url: '',
slug: '',
});
onPanelInspectClose(scene);
expect(locationService.getLocation().pathname).toBe('/');
});
test('when on custom home dashboard page with uid defined', async () => {
locationService.push('/');
const { scene } = await buildTestScene(
{
url: '',
slug: '',
},
'home-dash '
);
onPanelInspectClose(scene);
expect(locationService.getLocation().pathname).toBe('/');
});
test('when on new dashboard page', async () => {
locationService.push('/dashboard/new');
const { scene } = await buildTestScene(
{
url: '',
slug: '',
},
''
);
onPanelInspectClose(scene);
expect(locationService.getLocation().pathname).toBe('/dashboard/new');
});
test('when on a dashboard page', async () => {
const { scene } = await buildTestScene(
{
slug: 'dash-slug',
url: '/d/dash-uid/dash-slug',
},
'dash-uid'
);
onPanelInspectClose(scene);
expect(locationService.getLocation().pathname).toBe('/d/dash-uid/dash-slug');
});
});
async function buildTestScene(metaOverride?: DashboardSceneState['meta'], uid = 'dash-1') {
const scene = new DashboardScene({
title: 'hello',
uid,
meta: {
canEdit: true,
...metaOverride,
},
body: DefaultGridLayoutManager.fromVizPanels([]),
});
return { scene };
}