2018-12-05 00:33:21 -06:00
|
|
|
import _ from 'lodash';
|
2019-01-31 01:56:17 -06:00
|
|
|
import { PanelModel } from '../state/PanelModel';
|
2018-12-05 00:33:21 -06:00
|
|
|
|
|
|
|
describe('PanelModel', () => {
|
|
|
|
describe('when creating new panel model', () => {
|
|
|
|
let model;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
model = new PanelModel({
|
|
|
|
type: 'table',
|
|
|
|
showColumns: true,
|
2019-02-13 04:14:53 -06:00
|
|
|
targets: [{ refId: 'A' }, { noRefId: true }],
|
2018-12-05 00:33:21 -06:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should apply defaults', () => {
|
|
|
|
expect(model.gridPos.h).toBe(3);
|
|
|
|
});
|
|
|
|
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2018-12-05 00:33:21 -06:00
|
|
|
it('getSaveModel should remove defaults', () => {
|
|
|
|
const saveModel = model.getSaveModel();
|
|
|
|
expect(saveModel.gridPos).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('getSaveModel should remove nonPersistedProperties', () => {
|
|
|
|
const saveModel = model.getSaveModel();
|
|
|
|
expect(saveModel.events).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('when changing panel type', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
model.changeType('graph', true);
|
|
|
|
model.alert = { id: 2 };
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove table properties but keep core props', () => {
|
|
|
|
expect(model.showColumns).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should restore table properties when changing back', () => {
|
|
|
|
model.changeType('table', true);
|
|
|
|
expect(model.showColumns).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove alert rule when changing type that does not support it', () => {
|
|
|
|
model.changeType('table', true);
|
|
|
|
expect(model.alert).toBe(undefined);
|
|
|
|
});
|
|
|
|
});
|
2019-02-18 04:41:14 -06:00
|
|
|
|
|
|
|
describe('get panel options', () => {
|
|
|
|
it('should apply defaults', () => {
|
|
|
|
model.options = { existingProp: 10 };
|
|
|
|
const options = model.getOptions({
|
|
|
|
defaultProp: true,
|
|
|
|
existingProp: 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
expect(options.defaultProp).toBe(true);
|
|
|
|
expect(options.existingProp).toBe(10);
|
|
|
|
expect(model.options).toBe(options);
|
|
|
|
});
|
|
|
|
});
|
2018-12-05 00:33:21 -06:00
|
|
|
});
|
|
|
|
});
|