panels: fix loading panels with non-array targets (add tests)

pull/16014/head
Alexander Zobnin 7 years ago
parent fe798239b2
commit c028d410ec
No known key found for this signature in database
GPG Key ID: E17E9ABACEFA59EB
  1. 15
      public/app/features/dashboard/state/PanelModel.test.ts

@ -3,9 +3,10 @@ import { PanelModel } from './PanelModel';
describe('PanelModel', () => { describe('PanelModel', () => {
describe('when creating new panel model', () => { describe('when creating new panel model', () => {
let model; let model;
let modelJson;
beforeEach(() => { beforeEach(() => {
model = new PanelModel({ modelJson = {
type: 'table', type: 'table',
showColumns: true, showColumns: true,
targets: [{ refId: 'A' }, { noRefId: true }], targets: [{ refId: 'A' }, { noRefId: true }],
@ -23,7 +24,8 @@ describe('PanelModel', () => {
}, },
], ],
}, },
}); };
model = new PanelModel(modelJson);
}); });
it('should apply defaults', () => { it('should apply defaults', () => {
@ -38,6 +40,15 @@ describe('PanelModel', () => {
expect(model.targets[1].refId).toBe('B'); expect(model.targets[1].refId).toBe('B');
}); });
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');
});
it('getSaveModel should remove defaults', () => { it('getSaveModel should remove defaults', () => {
const saveModel = model.getSaveModel(); const saveModel = model.getSaveModel();
expect(saveModel.gridPos).toBe(undefined); expect(saveModel.gridPos).toBe(undefined);

Loading…
Cancel
Save