mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
PanelEditor: fixes save/apply for undefined props in restoreModel (#23939)
* PanelEditor: fixes save/apply for undefined props in restoreModel * Refactor: changes after PR comments * Refactor: changes sourcePanel refresh strategy * Added unit tests and minor refactoring of method, starting with cleanup, then setting properties from model * Update public/app/features/dashboard/state/PanelModel.test.ts Co-authored-by: Torkel Ödegaard <torkel@grafana.com> Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
@@ -290,5 +290,51 @@ describe('PanelModel', () => {
|
||||
expect(panelQueryRunner).toBe(sameQueryRunner);
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
||||
it('Should preserve must keep properties', () => {
|
||||
model.id = 10;
|
||||
model.gridPos = { x: 0, y: 0, h: 10, w: 10 };
|
||||
model.restoreModel({
|
||||
title: 'New title',
|
||||
options: {},
|
||||
});
|
||||
|
||||
expect(model.id).toBe(10);
|
||||
expect(model.gridPos.h).toBe(10);
|
||||
});
|
||||
|
||||
it('Should remove old angular panel specfic props', () => {
|
||||
model.axes = [{ prop: 1 }];
|
||||
model.thresholds = [];
|
||||
|
||||
model.restoreModel({
|
||||
title: 'New title',
|
||||
options: {},
|
||||
});
|
||||
|
||||
expect(model.axes).toBeUndefined();
|
||||
expect(model.thresholds).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user