mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
* Apply field overrides in PanelChrome * Move applyFieldOverrides to panel query runner * Review updates * Make sure overrides are applied back on souce panel when exiting the new edit mode * TS ignores in est * Make field display work in viz repeater * Review updates * Review and test updates * Change the way overrides and trransformations are retrieved in PQR * Minor updates after review * Fix null checks
128 lines
4.3 KiB
TypeScript
128 lines
4.3 KiB
TypeScript
import { thunkTester } from '../../../../../../test/core/thunk/thunkTester';
|
|
import { closeCompleted, initialState, PanelEditorStateNew } from './reducers';
|
|
import { initPanelEditor, panelEditorCleanUp } from './actions';
|
|
import { cleanUpEditPanel, panelModelAndPluginReady } from '../../../state/reducers';
|
|
import { DashboardModel, PanelModel } from '../../../state';
|
|
import { getPanelPlugin } from 'app/features/plugins/__mocks__/pluginMocks';
|
|
|
|
describe('panelEditor actions', () => {
|
|
describe('initPanelEditor', () => {
|
|
it('initPanelEditor should create edit panel model as clone', async () => {
|
|
const dashboard = new DashboardModel({
|
|
panels: [{ id: 12, type: 'graph' }],
|
|
});
|
|
const sourcePanel = new PanelModel({ id: 12, type: 'graph' });
|
|
|
|
const dispatchedActions = await thunkTester({
|
|
panelEditorNew: { ...initialState },
|
|
})
|
|
.givenThunk(initPanelEditor)
|
|
.whenThunkIsDispatched(sourcePanel, dashboard);
|
|
|
|
expect(dispatchedActions.length).toBe(1);
|
|
expect(dispatchedActions[0].payload.sourcePanel).toBe(sourcePanel);
|
|
expect(dispatchedActions[0].payload.panel).not.toBe(sourcePanel);
|
|
expect(dispatchedActions[0].payload.panel.id).not.toBe(sourcePanel.id);
|
|
});
|
|
});
|
|
|
|
describe('panelEditorCleanUp', () => {
|
|
it('should update source panel', async () => {
|
|
const sourcePanel = new PanelModel({ id: 12, type: 'graph' });
|
|
const dashboard = new DashboardModel({
|
|
panels: [{ id: 12, type: 'graph' }],
|
|
});
|
|
|
|
const panel = sourcePanel.getEditClone();
|
|
panel.updateOptions({ prop: true });
|
|
|
|
const state: PanelEditorStateNew = {
|
|
...initialState(),
|
|
getPanel: () => panel,
|
|
getSourcePanel: () => sourcePanel,
|
|
querySubscription: { unsubscribe: jest.fn() },
|
|
};
|
|
|
|
const dispatchedActions = await thunkTester({
|
|
panelEditorNew: state,
|
|
dashboard: {
|
|
getModel: () => dashboard,
|
|
},
|
|
})
|
|
.givenThunk(panelEditorCleanUp)
|
|
.whenThunkIsDispatched();
|
|
|
|
expect(dispatchedActions.length).toBe(2);
|
|
expect(dispatchedActions[0].type).toBe(cleanUpEditPanel.type);
|
|
expect(dispatchedActions[1].type).toBe(closeCompleted.type);
|
|
expect(sourcePanel.getOptions()).toEqual({ prop: true });
|
|
expect(sourcePanel.id).toEqual(12);
|
|
});
|
|
|
|
it('should dispatch panelModelAndPluginReady if type changed', async () => {
|
|
const sourcePanel = new PanelModel({ id: 12, type: 'graph' });
|
|
const dashboard = new DashboardModel({
|
|
panels: [{ id: 12, type: 'graph' }],
|
|
});
|
|
|
|
const panel = sourcePanel.getEditClone();
|
|
panel.type = 'table';
|
|
panel.plugin = getPanelPlugin({ id: 'table' });
|
|
panel.updateOptions({ prop: true });
|
|
|
|
const state: PanelEditorStateNew = {
|
|
...initialState(),
|
|
getPanel: () => panel,
|
|
getSourcePanel: () => sourcePanel,
|
|
querySubscription: { unsubscribe: jest.fn() },
|
|
};
|
|
|
|
const dispatchedActions = await thunkTester({
|
|
panelEditorNew: state,
|
|
dashboard: {
|
|
getModel: () => dashboard,
|
|
},
|
|
})
|
|
.givenThunk(panelEditorCleanUp)
|
|
.whenThunkIsDispatched();
|
|
|
|
expect(dispatchedActions.length).toBe(3);
|
|
expect(dispatchedActions[0].type).toBe(panelModelAndPluginReady.type);
|
|
});
|
|
|
|
it('should discard changes when shouldDiscardChanges is true', async () => {
|
|
const sourcePanel = new PanelModel({ id: 12, type: 'graph' });
|
|
sourcePanel.plugin = {
|
|
customFieldConfigs: {},
|
|
} as any;
|
|
|
|
const dashboard = new DashboardModel({
|
|
panels: [{ id: 12, type: 'graph' }],
|
|
});
|
|
|
|
const panel = sourcePanel.getEditClone();
|
|
panel.updateOptions({ prop: true });
|
|
|
|
const state: PanelEditorStateNew = {
|
|
...initialState(),
|
|
shouldDiscardChanges: true,
|
|
getPanel: () => panel,
|
|
getSourcePanel: () => sourcePanel,
|
|
querySubscription: { unsubscribe: jest.fn() },
|
|
};
|
|
|
|
const dispatchedActions = await thunkTester({
|
|
panelEditorNew: state,
|
|
dashboard: {
|
|
getModel: () => dashboard,
|
|
},
|
|
})
|
|
.givenThunk(panelEditorCleanUp)
|
|
.whenThunkIsDispatched();
|
|
|
|
expect(dispatchedActions.length).toBe(2);
|
|
expect(sourcePanel.getOptions()).toEqual({});
|
|
});
|
|
});
|
|
});
|