|
|
|
@ -8,6 +8,7 @@ import { |
|
|
|
|
SceneVariableSet, |
|
|
|
|
TestVariable, |
|
|
|
|
VizPanel, |
|
|
|
|
SceneGridRow, |
|
|
|
|
} from '@grafana/scenes'; |
|
|
|
|
import { Dashboard } from '@grafana/schema'; |
|
|
|
|
import appEvents from 'app/core/app_events'; |
|
|
|
@ -25,6 +26,14 @@ import { DashboardScene, DashboardSceneState } from './DashboardScene'; |
|
|
|
|
|
|
|
|
|
jest.mock('../settings/version-history/HistorySrv'); |
|
|
|
|
jest.mock('../serialization/transformSaveModelToScene'); |
|
|
|
|
jest.mock('@grafana/runtime', () => ({ |
|
|
|
|
...jest.requireActual('@grafana/runtime'), |
|
|
|
|
getDataSourceSrv: () => { |
|
|
|
|
return { |
|
|
|
|
getInstanceSettings: jest.fn().mockResolvedValue({ uid: 'ds1' }), |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
})); |
|
|
|
|
|
|
|
|
|
describe('DashboardScene', () => { |
|
|
|
|
describe('DashboardSrv.getCurrent compatibility', () => { |
|
|
|
@ -112,6 +121,43 @@ describe('DashboardScene', () => { |
|
|
|
|
scene.exitEditMode({ skipConfirm: true }); |
|
|
|
|
expect(sceneGraph.getTimeRange(scene)!.state.timeZone).toBe(prevState); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Should throw an error when adding a panel to a layout that is not SceneGridLayout', () => { |
|
|
|
|
const scene = buildTestScene({ body: undefined }); |
|
|
|
|
|
|
|
|
|
expect(() => { |
|
|
|
|
scene.addPanel(new VizPanel({ title: 'Panel Title', key: 'panel-4', pluginId: 'timeseries' })); |
|
|
|
|
}).toThrow('Trying to add a panel in a layout that is not SceneGridLayout'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Should add a new panel to the dashboard', () => { |
|
|
|
|
const vizPanel = new VizPanel({ |
|
|
|
|
title: 'Panel Title', |
|
|
|
|
key: 'panel-4', |
|
|
|
|
pluginId: 'timeseries', |
|
|
|
|
$data: new SceneQueryRunner({ key: 'data-query-runner', queries: [{ refId: 'A' }] }), |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
scene.addPanel(vizPanel); |
|
|
|
|
|
|
|
|
|
const body = scene.state.body as SceneGridLayout; |
|
|
|
|
const gridItem = body.state.children[0] as SceneGridItem; |
|
|
|
|
|
|
|
|
|
expect(scene.state.isDirty).toBe(true); |
|
|
|
|
expect(body.state.children.length).toBe(5); |
|
|
|
|
expect(gridItem.state.body!.state.key).toBe('panel-4'); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
it('Should create and add a new panel to the dashboard', () => { |
|
|
|
|
scene.onCreateNewPanel(); |
|
|
|
|
|
|
|
|
|
const body = scene.state.body as SceneGridLayout; |
|
|
|
|
const gridItem = body.state.children[0] as SceneGridItem; |
|
|
|
|
|
|
|
|
|
expect(scene.state.isDirty).toBe(true); |
|
|
|
|
expect(body.state.children.length).toBe(5); |
|
|
|
|
expect(gridItem.state.body!.state.key).toBe('panel-4'); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -235,6 +281,18 @@ function buildTestScene(overrides?: Partial<DashboardSceneState>) { |
|
|
|
|
pluginId: 'table', |
|
|
|
|
}), |
|
|
|
|
}), |
|
|
|
|
new SceneGridRow({ |
|
|
|
|
key: 'gridrow-1', |
|
|
|
|
children: [ |
|
|
|
|
new SceneGridItem({ |
|
|
|
|
body: new VizPanel({ |
|
|
|
|
title: 'Panel C', |
|
|
|
|
key: 'panel-3', |
|
|
|
|
pluginId: 'table', |
|
|
|
|
}), |
|
|
|
|
}), |
|
|
|
|
], |
|
|
|
|
}), |
|
|
|
|
new SceneGridItem({ |
|
|
|
|
body: new VizPanel({ |
|
|
|
|
title: 'Panel B', |
|
|
|
|