grafana/packages/grafana-data/test/__mocks__/pluginMocks.ts
Dominik Prokop 6968f4d6ff
DashboardScene: Share snapshot (#76132)
* Dashboard snapshot creation logic and tests

* Add variable type to serialized json, add refresh prop to datasource var

* WIP Snapshots tab UI

* Use Grafana snapshot query for a generated snapshot

* Make anno snapshots backwards compatible

* Share snapshot tab UI

* Single panel snapshot

* Remove unused param

* Snap update

* Ts fix

* One more snap fix

* Basic rows support

* Add tests for basic rows

* Bettererupdate
2023-10-11 04:24:18 -07:00

102 lines
2.6 KiB
TypeScript

import { defaultsDeep } from 'lodash';
import { ComponentType } from 'react';
import { PanelPluginMeta, PluginMeta, PluginType, PanelPlugin, PanelProps } from '../../src';
export const getMockPlugins = (amount: number): PluginMeta[] => {
const plugins: PluginMeta[] = [];
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' }],
logos: { small: 'small/logo', large: 'large/logo' },
screenshots: [{ path: `screenshot/${i}`, name: 'test' }],
updated: '2018-09-26',
version: '1',
},
latestVersion: `1.${i}`,
name: `pretty cool plugin-${i}`,
pinned: false,
state: undefined,
type: PluginType.panel,
module: '',
baseUrl: '',
});
}
return plugins;
};
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 = {
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' }],
logos: { small: 'small/logo', large: 'large/logo' },
screenshots: [{ path: `screenshot`, name: 'test' }],
updated: '2018-09-26',
version: '1',
},
latestVersion: '1',
name: 'pretty cool plugin 1',
baseUrl: 'path/to/plugin',
pinned: false,
type: PluginType.panel,
module: 'path/to/module',
};
return defaultsDeep(overrides || {}, defaults) as PluginMeta;
}