Files
grafana/public/app/plugins/panel/text/textPanelMigrationHandler.test.ts
sam boyer 33fd83f7e3 kindsys: Adapt to new PanelCfg schema interface (#65297)
* kindsys: Adapt to new PanelCfg schema interface

* building locally

* Remove Panel prefix in cue files

* Regenerate

* Update imports

* fixup! Merge branch 'remove-panel-prefix' into sdboyer/redundant-panelcfg-prefixes

* Fix formatting

---------

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
Co-authored-by: Tania B <yalyna.ts@gmail.com>
2023-05-15 23:07:54 -04:00

90 lines
2.6 KiB
TypeScript

import { FieldConfigSource, PanelModel } from '@grafana/data';
import { TextMode, Options } from './panelcfg.gen';
import { textPanelMigrationHandler } from './textPanelMigrationHandler';
describe('textPanelMigrationHandler', () => {
describe('when invoked and previous version was old Angular text panel', () => {
it('then should migrate options', () => {
const panel = {
content: '<span>Hello World<span>',
mode: 'html',
options: {},
};
const result = textPanelMigrationHandler(panel as unknown as PanelModel);
expect(result.content).toEqual('<span>Hello World<span>');
expect(result.mode).toEqual('html');
expect(panel.content).toBeUndefined();
expect(panel.mode).toBeUndefined();
});
});
describe('when invoked and previous version 7.1 or later', () => {
it('then not migrate options', () => {
const panel = {
content: '<span>Hello World<span>',
mode: 'html',
options: { content: 'New content' },
pluginVersion: '7.1.0',
};
const result = textPanelMigrationHandler(panel as unknown as PanelModel);
expect(result.content).toEqual('New content');
});
});
describe('when invoked and previous version was not old Angular text panel', () => {
it('then should just pass options through', () => {
const panel: PanelModel<Options> = {
id: 1,
type: 'text',
fieldConfig: {} as unknown as FieldConfigSource,
options: {
content: `# Title
For markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)
`,
mode: TextMode.Markdown,
},
};
const result = textPanelMigrationHandler(panel);
expect(result.content).toEqual(`# Title
For markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)
`);
expect(result.mode).toEqual('markdown');
});
});
describe('when invoked and previous version was using text mode', () => {
it('then should switch to markdown', () => {
const mode = 'text' as unknown as TextMode;
const panel: PanelModel<Options> = {
id: 1,
type: 'text',
fieldConfig: {} as unknown as FieldConfigSource,
options: {
content: `# Title
For markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)
`,
mode,
},
};
const result = textPanelMigrationHandler(panel);
expect(result.content).toEqual(`# Title
For markdown syntax help: [commonmark.org/help](https://commonmark.org/help/)
`);
expect(result.mode).toEqual('markdown');
});
});
});