Files
grafana/public/app/features/plugins/extensions/validateLink.test.ts
Marcus Andersson 8127ec5bfd Plugins: Fixed issue for plugin extensions in link validator (#64739)
fixed issue in validateLink.
2023-03-14 16:44:12 +01:00

64 lines
1.7 KiB
TypeScript

import type { AppPluginExtensionLink } from '@grafana/data';
import { createLinkValidator } from './validateLink';
describe('extension link validator', () => {
const pluginId = 'grafana-basic-app';
const validator = createLinkValidator({
pluginId,
title: 'Link to something',
logger: jest.fn(),
});
const context = {};
const extension: AppPluginExtensionLink = {
title: 'Go to page one',
description: 'Will navigate the user to page one',
path: `/a/${pluginId}/one`,
};
it('should return link configuration if path is valid', () => {
const configureWithValidation = validator(() => {
return {
path: `/a/${pluginId}/other`,
};
});
const configured = configureWithValidation(extension, context);
expect(configured).toEqual({
path: `/a/${pluginId}/other`,
});
});
it('should return link configuration if path is not specified', () => {
const configureWithValidation = validator(() => {
return {
title: 'Go to page two',
};
});
const configured = configureWithValidation(extension, context);
expect(configured).toEqual({ title: 'Go to page two' });
});
it('should return undefined if path is invalid', () => {
const configureWithValidation = validator(() => {
return {
path: `/other`,
};
});
const configured = configureWithValidation(extension, context);
expect(configured).toBeUndefined();
});
it('should return undefined if undefined is returned from inner configure', () => {
const configureWithValidation = validator(() => {
return undefined;
});
const configured = configureWithValidation(extension, context);
expect(configured).toBeUndefined();
});
});