The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/explore/extensions/getExploreExtensionConfigs....

60 lines
2.0 KiB

import { PluginExtensionPoints } from '@grafana/data';
import { contextSrv } from 'app/core/services/context_srv';
import { getExploreExtensionConfigs } from './getExploreExtensionConfigs';
jest.mock('app/core/services/context_srv');
const contextSrvMock = jest.mocked(contextSrv);
describe('getExploreExtensionConfigs', () => {
describe('configured items returned', () => {
it('should return array with core extensions added in explore', () => {
const extensions = getExploreExtensionConfigs();
expect(extensions).toEqual([
{
type: 'link',
title: 'Add to dashboard',
description: 'Use the query and panel from explore and create/add it to a dashboard',
extensionPointId: PluginExtensionPoints.ExploreToolbarAction,
icon: 'apps',
configure: expect.any(Function),
onClick: expect.any(Function),
category: 'Dashboards',
},
{
type: 'link',
title: 'Add correlation',
description: 'Create a correlation from this query',
extensionPointId: PluginExtensionPoints.ExploreToolbarAction,
icon: 'link',
configure: expect.any(Function),
onClick: expect.any(Function),
},
]);
});
});
describe('configure function for "add to dashboard" extension', () => {
afterEach(() => contextSrvMock.hasPermission.mockRestore());
it('should return undefined if insufficient permissions', () => {
contextSrvMock.hasPermission.mockReturnValue(false);
const extensions = getExploreExtensionConfigs();
const [extension] = extensions;
expect(extension?.configure?.()).toBeUndefined();
});
it('should return empty object if sufficient permissions', () => {
contextSrvMock.hasPermission.mockReturnValue(true);
const extensions = getExploreExtensionConfigs();
const [extension] = extensions;
expect(extension?.configure?.()).toEqual({});
});
});
});