2019-02-21 07:44:21 -06:00
|
|
|
import { PanelModel } from './PanelModel';
|
2019-03-24 09:56:32 -05:00
|
|
|
import { getPanelPlugin } from '../../plugins/__mocks__/pluginMocks';
|
2020-04-06 09:24:41 -05:00
|
|
|
import {
|
|
|
|
FieldConfigProperty,
|
|
|
|
PanelProps,
|
2020-04-08 12:21:26 -05:00
|
|
|
standardEditorsRegistry,
|
2020-04-06 09:24:41 -05:00
|
|
|
standardFieldConfigEditorRegistry,
|
2020-05-06 09:06:21 -05:00
|
|
|
PanelData,
|
2020-11-09 06:11:09 -06:00
|
|
|
FieldColorModeId,
|
|
|
|
FieldColorConfigSettings,
|
2020-12-15 06:29:37 -06:00
|
|
|
DataLinkBuiltInVars,
|
|
|
|
VariableModel,
|
2020-04-06 09:24:41 -05:00
|
|
|
} from '@grafana/data';
|
2020-03-12 04:22:33 -05:00
|
|
|
import { ComponentClass } from 'react';
|
2020-11-26 11:12:02 -06:00
|
|
|
import { PanelQueryRunner } from '../../query/state/PanelQueryRunner';
|
2020-12-15 06:29:37 -06:00
|
|
|
import { setTimeSrv } from '../services/TimeSrv';
|
|
|
|
import { TemplateSrv } from '../../templating/template_srv';
|
|
|
|
import { setTemplateSrv } from '@grafana/runtime';
|
|
|
|
import { variableAdapters } from '../../variables/adapters';
|
|
|
|
import { createQueryVariableAdapter } from '../../variables/query/adapter';
|
2020-12-17 02:20:47 -06:00
|
|
|
import { mockStandardFieldConfigOptions } from '../../../../test/helpers/fieldConfig';
|
2019-04-04 11:30:15 -05:00
|
|
|
|
2020-12-17 02:20:47 -06:00
|
|
|
standardFieldConfigEditorRegistry.setInit(() => mockStandardFieldConfigOptions());
|
|
|
|
standardEditorsRegistry.setInit(() => mockStandardFieldConfigOptions());
|
2018-12-05 00:33:21 -06:00
|
|
|
|
2020-12-15 06:29:37 -06:00
|
|
|
setTimeSrv({
|
|
|
|
timeRangeForUrl: () => ({
|
|
|
|
from: 1607687293000,
|
|
|
|
to: 1607687293100,
|
|
|
|
}),
|
|
|
|
} as any);
|
2020-04-06 09:24:41 -05:00
|
|
|
|
2020-12-15 06:29:37 -06:00
|
|
|
setTemplateSrv(
|
|
|
|
new TemplateSrv({
|
2020-04-06 09:24:41 -05:00
|
|
|
// @ts-ignore
|
2020-12-15 06:29:37 -06:00
|
|
|
getVariables: () => {
|
|
|
|
return variablesMock;
|
|
|
|
},
|
2020-04-06 09:24:41 -05:00
|
|
|
// @ts-ignore
|
2020-12-15 06:29:37 -06:00
|
|
|
getVariableWithName: (name: string) => {
|
|
|
|
return variablesMock.filter(v => v.name === name)[0];
|
|
|
|
},
|
|
|
|
})
|
|
|
|
);
|
2020-04-06 09:24:41 -05:00
|
|
|
|
2020-12-15 06:29:37 -06:00
|
|
|
variableAdapters.setInit(() => [createQueryVariableAdapter()]);
|
2020-04-06 09:24:41 -05:00
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
describe('PanelModel', () => {
|
|
|
|
describe('when creating new panel model', () => {
|
2019-07-30 08:49:32 -05:00
|
|
|
let model: any;
|
|
|
|
let modelJson: any;
|
2019-05-21 06:19:19 -05:00
|
|
|
let persistedOptionsMock;
|
2018-12-05 00:33:21 -06:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-05-21 06:19:19 -05:00
|
|
|
persistedOptionsMock = {
|
|
|
|
fieldOptions: {
|
|
|
|
thresholds: [
|
|
|
|
{
|
|
|
|
color: '#F2495C',
|
|
|
|
index: 1,
|
|
|
|
value: 50,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
color: '#73BF69',
|
|
|
|
index: 0,
|
|
|
|
value: null,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-11-08 02:46:53 -06:00
|
|
|
arrayWith2Values: [{ name: 'changed to only one value' }],
|
2019-05-21 06:19:19 -05:00
|
|
|
};
|
|
|
|
|
2019-03-15 02:49:41 -05:00
|
|
|
modelJson = {
|
2018-12-05 00:33:21 -06:00
|
|
|
type: 'table',
|
2020-05-11 15:03:43 -05:00
|
|
|
maxDataPoints: 100,
|
|
|
|
interval: '5m',
|
2018-12-05 00:33:21 -06:00
|
|
|
showColumns: true,
|
2019-02-13 04:14:53 -06:00
|
|
|
targets: [{ refId: 'A' }, { noRefId: true }],
|
2019-05-21 06:19:19 -05:00
|
|
|
options: persistedOptionsMock,
|
2020-03-19 05:50:31 -05:00
|
|
|
fieldConfig: {
|
|
|
|
defaults: {
|
|
|
|
unit: 'mpg',
|
2020-09-01 09:00:38 -05:00
|
|
|
thresholds: {
|
|
|
|
mode: 'absolute',
|
|
|
|
steps: [
|
|
|
|
{ color: 'green', value: null },
|
|
|
|
{ color: 'red', value: 80 },
|
|
|
|
],
|
|
|
|
},
|
2020-03-19 05:50:31 -05:00
|
|
|
},
|
|
|
|
overrides: [
|
|
|
|
{
|
|
|
|
matcher: {
|
|
|
|
id: '1',
|
|
|
|
options: {},
|
|
|
|
},
|
2020-09-01 09:00:38 -05:00
|
|
|
properties: [
|
|
|
|
{
|
|
|
|
id: 'thresholds',
|
|
|
|
value: {
|
|
|
|
mode: 'absolute',
|
|
|
|
steps: [
|
|
|
|
{ color: 'green', value: null },
|
|
|
|
{ color: 'red', value: 80 },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
],
|
2020-03-19 05:50:31 -05:00
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2019-03-15 02:49:41 -05:00
|
|
|
};
|
2019-05-21 06:19:19 -05:00
|
|
|
|
2019-03-15 02:49:41 -05:00
|
|
|
model = new PanelModel(modelJson);
|
2020-03-19 05:50:31 -05:00
|
|
|
|
2019-05-21 06:19:19 -05:00
|
|
|
const panelPlugin = getPanelPlugin(
|
|
|
|
{
|
|
|
|
id: 'table',
|
|
|
|
},
|
2020-03-12 04:22:33 -05:00
|
|
|
(null as unknown) as ComponentClass<PanelProps>, // react
|
2020-12-15 06:29:37 -06:00
|
|
|
{} // angular
|
2019-04-04 11:30:15 -05:00
|
|
|
);
|
2020-04-08 12:21:26 -05:00
|
|
|
|
|
|
|
panelPlugin.setPanelOptions(builder => {
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
name: 'Show thresholds',
|
|
|
|
path: 'showThresholds',
|
|
|
|
defaultValue: true,
|
|
|
|
description: '',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-06 09:24:41 -05:00
|
|
|
panelPlugin.useFieldConfig({
|
2020-11-09 06:11:09 -06:00
|
|
|
standardOptions: {
|
|
|
|
[FieldConfigProperty.Unit]: {
|
|
|
|
defaultValue: 'flop',
|
|
|
|
},
|
|
|
|
[FieldConfigProperty.Decimals]: {
|
|
|
|
defaultValue: 2,
|
|
|
|
},
|
2020-04-06 09:24:41 -05:00
|
|
|
},
|
2020-03-19 05:50:31 -05:00
|
|
|
});
|
2019-05-21 06:19:19 -05:00
|
|
|
model.pluginLoaded(panelPlugin);
|
2018-12-05 00:33:21 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply defaults', () => {
|
|
|
|
expect(model.gridPos.h).toBe(3);
|
|
|
|
});
|
|
|
|
|
2019-05-21 06:19:19 -05:00
|
|
|
it('should apply option defaults', () => {
|
|
|
|
expect(model.getOptions().showThresholds).toBeTruthy();
|
|
|
|
});
|
|
|
|
|
2020-09-01 09:00:38 -05:00
|
|
|
it('should change null thresholds to negative infinity', () => {
|
|
|
|
expect(model.fieldConfig.defaults.thresholds.steps[0].value).toBe(-Infinity);
|
|
|
|
expect(model.fieldConfig.overrides[0].properties[0].value.steps[0].value).toBe(-Infinity);
|
|
|
|
});
|
|
|
|
|
2019-11-08 02:46:53 -06:00
|
|
|
it('should apply option defaults but not override if array is changed', () => {
|
|
|
|
expect(model.getOptions().arrayWith2Values.length).toBe(1);
|
|
|
|
});
|
|
|
|
|
2020-03-19 05:50:31 -05:00
|
|
|
it('should apply field config defaults', () => {
|
|
|
|
// default unit is overriden by model
|
2020-04-06 09:24:41 -05:00
|
|
|
expect(model.getFieldOverrideOptions().fieldConfig.defaults.unit).toBe('mpg');
|
2020-03-19 05:50:31 -05:00
|
|
|
// default decimals are aplied
|
2020-04-06 09:24:41 -05:00
|
|
|
expect(model.getFieldOverrideOptions().fieldConfig.defaults.decimals).toBe(2);
|
2020-03-19 05:50:31 -05:00
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
it('should set model props on instance', () => {
|
|
|
|
expect(model.showColumns).toBe(true);
|
|
|
|
});
|
|
|
|
|
2019-01-21 13:35:24 -06:00
|
|
|
it('should add missing refIds', () => {
|
|
|
|
expect(model.targets[1].refId).toBe('B');
|
|
|
|
});
|
|
|
|
|
2019-03-15 02:49:41 -05:00
|
|
|
it("shouldn't break panel with non-array targets", () => {
|
|
|
|
modelJson.targets = {
|
|
|
|
0: { refId: 'A' },
|
|
|
|
foo: { bar: 'baz' },
|
|
|
|
};
|
|
|
|
model = new PanelModel(modelJson);
|
|
|
|
expect(model.targets[0].refId).toBe('A');
|
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
it('getSaveModel should remove defaults', () => {
|
|
|
|
const saveModel = model.getSaveModel();
|
|
|
|
expect(saveModel.gridPos).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
2019-09-24 05:15:35 -05:00
|
|
|
it('getSaveModel should not remove datasource default', () => {
|
|
|
|
const saveModel = model.getSaveModel();
|
|
|
|
expect(saveModel.datasource).toBe(null);
|
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
it('getSaveModel should remove nonPersistedProperties', () => {
|
|
|
|
const saveModel = model.getSaveModel();
|
|
|
|
expect(saveModel.events).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
2020-03-16 08:26:03 -05:00
|
|
|
describe('variables interpolation', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
model.scopedVars = {
|
|
|
|
aaa: { value: 'AAA', text: 'upperA' },
|
|
|
|
bbb: { value: 'BBB', text: 'upperB' },
|
|
|
|
};
|
|
|
|
});
|
|
|
|
it('should interpolate variables', () => {
|
|
|
|
const out = model.replaceVariables('hello $aaa');
|
|
|
|
expect(out).toBe('hello AAA');
|
|
|
|
});
|
|
|
|
|
2020-12-15 06:29:37 -06:00
|
|
|
it('should interpolate $__url_time_range variable', () => {
|
|
|
|
const out = model.replaceVariables(`/d/1?$${DataLinkBuiltInVars.keepTime}`);
|
|
|
|
expect(out).toBe('/d/1?from=1607687293000&to=1607687293100');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should interpolate $__all_variables variable', () => {
|
|
|
|
const out = model.replaceVariables(`/d/1?$${DataLinkBuiltInVars.includeVars}`);
|
|
|
|
expect(out).toBe('/d/1?var-test1=val1&var-test2=val2');
|
|
|
|
});
|
|
|
|
|
2020-03-16 08:26:03 -05:00
|
|
|
it('should prefer the local variable value', () => {
|
|
|
|
const extra = { aaa: { text: '???', value: 'XXX' } };
|
|
|
|
const out = model.replaceVariables('hello $aaa and $bbb', extra);
|
|
|
|
expect(out).toBe('hello XXX and BBB');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
describe('when changing panel type', () => {
|
|
|
|
beforeEach(() => {
|
2019-05-21 06:19:19 -05:00
|
|
|
const newPlugin = getPanelPlugin({ id: 'graph' });
|
2020-11-09 06:11:09 -06:00
|
|
|
|
|
|
|
newPlugin.useFieldConfig({
|
|
|
|
standardOptions: {
|
|
|
|
[FieldConfigProperty.Color]: {
|
|
|
|
settings: {
|
|
|
|
byThresholdsSupport: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2020-04-08 12:21:26 -05:00
|
|
|
newPlugin.setPanelOptions(builder => {
|
|
|
|
builder.addBooleanSwitch({
|
|
|
|
name: 'Show thresholds labels',
|
|
|
|
path: 'showThresholdLabels',
|
|
|
|
defaultValue: false,
|
|
|
|
description: '',
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-04-27 10:32:35 -05:00
|
|
|
model.editSourceId = 1001;
|
2019-05-21 06:19:19 -05:00
|
|
|
model.changePlugin(newPlugin);
|
2018-12-05 00:33:21 -06:00
|
|
|
model.alert = { id: 2 };
|
|
|
|
});
|
|
|
|
|
2020-04-27 10:32:35 -05:00
|
|
|
it('should keep editSourceId', () => {
|
|
|
|
expect(model.editSourceId).toBe(1001);
|
|
|
|
});
|
|
|
|
|
2020-05-11 15:03:43 -05:00
|
|
|
it('should keep maxDataPoints', () => {
|
|
|
|
expect(model.maxDataPoints).toBe(100);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should keep interval', () => {
|
|
|
|
expect(model.interval).toBe('5m');
|
|
|
|
});
|
|
|
|
|
2019-05-21 06:19:19 -05:00
|
|
|
it('should apply next panel option defaults', () => {
|
|
|
|
expect(model.getOptions().showThresholdLabels).toBeFalsy();
|
|
|
|
expect(model.getOptions().showThresholds).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
it('should remove table properties but keep core props', () => {
|
|
|
|
expect(model.showColumns).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should restore table properties when changing back', () => {
|
2019-04-04 11:30:15 -05:00
|
|
|
model.changePlugin(getPanelPlugin({ id: 'table' }));
|
2018-12-05 00:33:21 -06:00
|
|
|
expect(model.showColumns).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove alert rule when changing type that does not support it', () => {
|
2019-04-04 11:30:15 -05:00
|
|
|
model.changePlugin(getPanelPlugin({ id: 'table' }));
|
2018-12-05 00:33:21 -06:00
|
|
|
expect(model.alert).toBe(undefined);
|
|
|
|
});
|
2020-03-16 08:26:03 -05:00
|
|
|
});
|
|
|
|
|
2020-11-09 06:11:09 -06:00
|
|
|
describe('when changing panel type to one that does not support by value color mode', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
model.fieldConfig.defaults.color = { mode: FieldColorModeId.Thresholds };
|
|
|
|
|
|
|
|
const newPlugin = getPanelPlugin({ id: 'graph' });
|
|
|
|
newPlugin.useFieldConfig({
|
|
|
|
standardOptions: {
|
|
|
|
[FieldConfigProperty.Color]: {
|
|
|
|
settings: {
|
|
|
|
byValueSupport: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
model.editSourceId = 1001;
|
|
|
|
model.changePlugin(newPlugin);
|
|
|
|
model.alert = { id: 2 };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change color mode', () => {
|
|
|
|
expect(model.fieldConfig.defaults.color.mode).toBe(FieldColorModeId.PaletteClassic);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when changing panel type from one not supporting by value color mode to one that supports it', () => {
|
|
|
|
const prepareModel = (colorOptions?: FieldColorConfigSettings) => {
|
|
|
|
const newModel = new PanelModel(modelJson);
|
|
|
|
newModel.fieldConfig.defaults.color = { mode: FieldColorModeId.PaletteClassic };
|
|
|
|
|
|
|
|
const newPlugin = getPanelPlugin({ id: 'graph' });
|
|
|
|
newPlugin.useFieldConfig({
|
|
|
|
standardOptions: {
|
|
|
|
[FieldConfigProperty.Color]: {
|
|
|
|
settings: {
|
|
|
|
byValueSupport: true,
|
|
|
|
...colorOptions,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
newModel.editSourceId = 1001;
|
|
|
|
newModel.changePlugin(newPlugin);
|
|
|
|
newModel.alert = { id: 2 };
|
|
|
|
return newModel;
|
|
|
|
};
|
|
|
|
|
|
|
|
it('should keep supported mode', () => {
|
|
|
|
const testModel = prepareModel();
|
|
|
|
|
|
|
|
expect(testModel.fieldConfig.defaults.color!.mode).toBe(FieldColorModeId.PaletteClassic);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should change to thresholds mode when it prefers to', () => {
|
|
|
|
const testModel = prepareModel({ preferThresholdsMode: true });
|
|
|
|
expect(testModel.fieldConfig.defaults.color!.mode).toBe(FieldColorModeId.Thresholds);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-03-16 08:26:03 -05:00
|
|
|
describe('when changing to react panel from angular panel', () => {
|
|
|
|
let panelQueryRunner: any;
|
|
|
|
|
|
|
|
const onPanelTypeChanged = jest.fn();
|
|
|
|
const reactPlugin = getPanelPlugin({ id: 'react' }).setPanelChangeHandler(onPanelTypeChanged as any);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
model.changePlugin(reactPlugin);
|
|
|
|
panelQueryRunner = model.getQueryRunner();
|
|
|
|
});
|
2019-05-03 03:29:22 -05:00
|
|
|
|
2020-03-16 08:26:03 -05:00
|
|
|
it('should call react onPanelTypeChanged', () => {
|
|
|
|
expect(onPanelTypeChanged.mock.calls.length).toBe(1);
|
|
|
|
expect(onPanelTypeChanged.mock.calls[0][1]).toBe('table');
|
|
|
|
expect(onPanelTypeChanged.mock.calls[0][2].angular).toBeDefined();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getQueryRunner() should return same instance after changing to another react panel', () => {
|
|
|
|
model.changePlugin(getPanelPlugin({ id: 'react2' }));
|
|
|
|
const sameQueryRunner = model.getQueryRunner();
|
|
|
|
expect(panelQueryRunner).toBe(sameQueryRunner);
|
2019-05-03 03:29:22 -05:00
|
|
|
});
|
2018-12-05 00:33:21 -06:00
|
|
|
});
|
2019-02-18 04:41:14 -06:00
|
|
|
|
2020-03-16 08:26:03 -05:00
|
|
|
describe('variables interpolation', () => {
|
2019-05-06 12:35:10 -05:00
|
|
|
let panelQueryRunner: any;
|
|
|
|
|
2019-03-24 10:39:55 -05:00
|
|
|
const onPanelTypeChanged = jest.fn();
|
2019-05-01 00:36:46 -05:00
|
|
|
const reactPlugin = getPanelPlugin({ id: 'react' }).setPanelChangeHandler(onPanelTypeChanged as any);
|
2019-03-24 10:39:55 -05:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-05-01 00:36:46 -05:00
|
|
|
model.changePlugin(reactPlugin);
|
2019-05-06 12:35:10 -05:00
|
|
|
panelQueryRunner = model.getQueryRunner();
|
2019-03-24 10:39:55 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should call react onPanelTypeChanged', () => {
|
|
|
|
expect(onPanelTypeChanged.mock.calls.length).toBe(1);
|
|
|
|
expect(onPanelTypeChanged.mock.calls[0][1]).toBe('table');
|
2019-08-18 17:01:07 -05:00
|
|
|
expect(onPanelTypeChanged.mock.calls[0][2].angular).toBeDefined();
|
2019-03-24 10:39:55 -05:00
|
|
|
});
|
2019-05-06 12:35:10 -05:00
|
|
|
|
|
|
|
it('getQueryRunner() should return same instance after changing to another react panel', () => {
|
|
|
|
model.changePlugin(getPanelPlugin({ id: 'react2' }));
|
|
|
|
const sameQueryRunner = model.getQueryRunner();
|
|
|
|
expect(panelQueryRunner).toBe(sameQueryRunner);
|
|
|
|
});
|
2019-03-24 10:39:55 -05:00
|
|
|
});
|
2020-04-27 13:50:33 -05:00
|
|
|
|
|
|
|
describe('restoreModel', () => {
|
|
|
|
it('Should clean state and set properties from model', () => {
|
|
|
|
model.restoreModel({
|
|
|
|
title: 'New title',
|
|
|
|
options: { new: true },
|
|
|
|
});
|
|
|
|
expect(model.title).toBe('New title');
|
|
|
|
expect(model.options.new).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Should delete properties that are now gone on new model', () => {
|
|
|
|
model.someProperty = 'value';
|
|
|
|
model.restoreModel({
|
|
|
|
title: 'New title',
|
|
|
|
options: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(model.someProperty).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2020-10-07 05:29:30 -05:00
|
|
|
it('Should remove old angular panel specific props', () => {
|
2020-04-27 13:50:33 -05:00
|
|
|
model.axes = [{ prop: 1 }];
|
|
|
|
model.thresholds = [];
|
|
|
|
|
|
|
|
model.restoreModel({
|
|
|
|
title: 'New title',
|
|
|
|
options: {},
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(model.axes).toBeUndefined();
|
|
|
|
expect(model.thresholds).toBeUndefined();
|
|
|
|
});
|
2020-05-11 15:03:43 -05:00
|
|
|
|
|
|
|
it('Should be able to set defaults back to default', () => {
|
|
|
|
model.transparent = true;
|
|
|
|
|
|
|
|
model.restoreModel({});
|
|
|
|
expect(model.transparent).toBe(false);
|
|
|
|
});
|
2020-04-27 13:50:33 -05:00
|
|
|
});
|
2020-05-06 09:06:21 -05:00
|
|
|
|
|
|
|
describe('destroy', () => {
|
|
|
|
it('Should still preserve last query result', () => {
|
|
|
|
model.getQueryRunner().useLastResultFrom({
|
|
|
|
getLastResult: () => ({} as PanelData),
|
|
|
|
} as PanelQueryRunner);
|
|
|
|
|
|
|
|
model.destroy();
|
|
|
|
expect(model.getQueryRunner().getLastResult()).toBeDefined();
|
|
|
|
});
|
|
|
|
});
|
2018-12-05 00:33:21 -06:00
|
|
|
});
|
|
|
|
});
|
2020-12-15 06:29:37 -06:00
|
|
|
|
|
|
|
const variablesMock = [
|
|
|
|
{
|
|
|
|
type: 'query',
|
|
|
|
name: 'test1',
|
|
|
|
label: 'Test1',
|
|
|
|
hide: false,
|
|
|
|
current: { value: 'val1' },
|
|
|
|
skipUrlSync: false,
|
|
|
|
getValueForUrl: function() {
|
|
|
|
return 'val1';
|
|
|
|
},
|
|
|
|
} as VariableModel,
|
|
|
|
{
|
|
|
|
type: 'query',
|
|
|
|
name: 'test2',
|
|
|
|
label: 'Test2',
|
|
|
|
hide: false,
|
|
|
|
current: { value: 'val2' },
|
|
|
|
skipUrlSync: false,
|
|
|
|
getValueForUrl: function() {
|
|
|
|
return 'val2';
|
|
|
|
},
|
|
|
|
} as VariableModel,
|
|
|
|
];
|