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/packages/grafana-data/test/helpers/pluginMocks.ts

102 lines
2.6 KiB

import { defaultsDeep } from 'lodash';
import { ComponentType } from 'react';
import { PanelPluginMeta, PluginMeta, PluginType, PanelPlugin, PanelProps } from '../../';
7 years ago
export const getMockPlugins = (amount: number): PluginMeta[] => {
const plugins: PluginMeta[] = [];
7 years ago
for (let i = 0; i <= amount; i++) {
plugins.push({
defaultNavUrl: 'some/url',
enabled: false,
hasUpdate: false,
id: `${i}`,
info: {
author: {
name: 'Grafana Labs',
url: 'url/to/GrafanaLabs',
},
description: 'pretty decent plugin',
links: [{ name: 'one link', url: 'one link' }],
7 years ago
logos: { small: 'small/logo', large: 'large/logo' },
screenshots: [{ path: `screenshot/${i}`, name: 'test' }],
7 years ago
updated: '2018-09-26',
version: '1',
},
latestVersion: `1.${i}`,
name: `pretty cool plugin-${i}`,
pinned: false,
state: undefined,
type: PluginType.panel,
module: '',
baseUrl: '',
7 years ago
});
}
return plugins;
7 years ago
};
export function getPanelPlugin(
options: Partial<PanelPluginMeta>,
reactPanel?: ComponentType<PanelProps>,
angularPanel?: any
): PanelPlugin {
const plugin = new PanelPlugin(reactPanel!);
plugin.angularPanelCtrl = angularPanel;
plugin.meta = {
id: options.id!,
type: PluginType.panel,
name: options.id!,
sort: options.sort || 1,
info: {
author: {
name: options.id + 'name',
},
description: '',
links: [],
logos: {
large: '',
small: '',
},
screenshots: [],
updated: '',
version: '1',
},
hideFromList: options.hideFromList === true,
module: options.module ?? '',
baseUrl: '',
skipDataQuery: options.skipDataQuery,
};
return plugin;
}
export function getMockPlugin(overrides?: Partial<PluginMeta>): PluginMeta {
const defaults: PluginMeta = {
7 years ago
defaultNavUrl: 'some/url',
enabled: false,
hasUpdate: false,
id: '1',
info: {
author: {
name: 'Grafana Labs',
url: 'url/to/GrafanaLabs',
},
description: 'pretty decent plugin',
links: [{ name: 'project', url: 'one link' }],
7 years ago
logos: { small: 'small/logo', large: 'large/logo' },
screenshots: [{ path: `screenshot`, name: 'test' }],
7 years ago
updated: '2018-09-26',
version: '1',
},
latestVersion: '1',
name: 'pretty cool plugin 1',
baseUrl: 'path/to/plugin',
7 years ago
pinned: false,
type: PluginType.panel,
module: 'path/to/module',
};
return defaultsDeep(overrides || {}, defaults) as PluginMeta;
}