AngularMigration: Clear old angular panel props when auto migrating (#66719)

* AngularMigration: Clear old angular panel props when auto migrating

* Update test name
This commit is contained in:
Torkel Ödegaard
2023-04-19 13:47:55 +02:00
committed by GitHub
parent c13ec0fc15
commit ee247e33b4
3 changed files with 52 additions and 8 deletions

View File

@@ -352,6 +352,44 @@ describe('PanelModel', () => {
});
});
describe('when autoMigrateFrom angular to react', () => {
const onPanelTypeChanged = (panel: PanelModel, prevPluginId: string, prevOptions: Record<string, any>) => {
panel.fieldConfig = { defaults: { unit: 'bytes' }, overrides: [] };
return { name: prevOptions.angular.oldName };
};
const reactPlugin = getPanelPlugin({ id: 'timeseries' })
.setPanelChangeHandler(onPanelTypeChanged as any)
.useFieldConfig({
disableStandardOptions: [FieldConfigProperty.Thresholds],
})
.setPanelOptions((builder) => {
builder.addTextInput({
name: 'Name',
path: 'name',
});
});
beforeEach(() => {
model = new PanelModel({
autoMigrateFrom: 'graph',
oldName: 'old name',
type: 'timeseries',
});
model.pluginLoaded(reactPlugin);
});
it('should run panel changed handler and remove old model props', () => {
expect(model.options).toEqual({ name: 'old name' });
expect(model.fieldConfig).toEqual({ defaults: { unit: 'bytes' }, overrides: [] });
expect(model.autoMigrateFrom).toBe(undefined);
expect(model.oldName).toBe(undefined);
expect(model.plugin).toBe(reactPlugin);
expect(model.type).toBe('timeseries');
});
});
describe('variables interpolation', () => {
let panelQueryRunner: any;