grafana/public/app/features/scenes/dashboard/DashboardScene.test.tsx
Torkel Ödegaard e7797ac439
SceneDashboard: Adds menu to panels, a start for inspect drawer state (#71194)
* Began work on panel menu

* SceneDashboard: Basic state handling for inspect panel

* Switched to using scene url sync instead

* Updated

* Update comment on hack

* Fixed url synnc issues and more / better DashboardsLoader tests

* Progress on test

* Updates

* Progress

* Progress

* Update

* Update

* Update

* Update

* Update scenes lib

* Update

* Update

---------

Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
2023-07-12 13:37:26 +02:00

52 lines
1.4 KiB
TypeScript

import { SceneGridItem, SceneGridLayout, VizPanel } from '@grafana/scenes';
import { DashboardScene } from './DashboardScene';
describe('DashboardScene', () => {
describe('Given a standard scene', () => {
it('Should set inspectPanelKey when url has inspect key', () => {
const scene = buildTestScene();
scene.urlSync?.updateFromUrl({ inspect: 'panel-2' });
expect(scene.state.inspectPanelKey).toBe('panel-2');
});
it('Should handle inspect key that is not found', () => {
const scene = buildTestScene();
scene.urlSync?.updateFromUrl({ inspect: '12321' });
expect(scene.state.inspectPanelKey).toBe(undefined);
});
it('Should set viewPanelKey when url has viewPanel', () => {
const scene = buildTestScene();
scene.urlSync?.updateFromUrl({ viewPanel: 'panel-2' });
expect(scene.state.viewPanelKey).toBe('panel-2');
});
});
});
function buildTestScene() {
const scene = new DashboardScene({
title: 'hello',
body: new SceneGridLayout({
children: [
new SceneGridItem({
body: new VizPanel({
title: 'Panel A',
key: 'panel-1',
pluginId: 'table',
}),
}),
new SceneGridItem({
body: new VizPanel({
title: 'Panel B',
key: 'panel-2',
pluginId: 'table',
}),
}),
],
}),
});
return scene;
}