pluginMocks.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { ComponentType } from 'enzyme';
  2. import { defaultsDeep } from 'lodash';
  3. import { PanelPluginMeta, PluginMeta, PluginType, PanelPlugin, PanelProps } from '@grafana/data';
  4. export const getMockPlugins = (amount: number): PluginMeta[] => {
  5. const plugins = [];
  6. for (let i = 0; i <= amount; i++) {
  7. plugins.push({
  8. defaultNavUrl: 'some/url',
  9. enabled: false,
  10. hasUpdate: false,
  11. id: `${i}`,
  12. info: {
  13. author: {
  14. name: 'Grafana Labs',
  15. url: 'url/to/GrafanaLabs',
  16. },
  17. description: 'pretty decent plugin',
  18. links: ['one link'],
  19. logos: { small: 'small/logo', large: 'large/logo' },
  20. screenshots: [{ path: `screenshot/${i}` }],
  21. updated: '2018-09-26',
  22. version: '1',
  23. },
  24. latestVersion: `1.${i}`,
  25. name: `pretty cool plugin-${i}`,
  26. pinned: false,
  27. state: '',
  28. type: '',
  29. module: {},
  30. });
  31. }
  32. return plugins as any;
  33. };
  34. export function getPanelPlugin(
  35. options: Partial<PanelPluginMeta>,
  36. reactPanel?: ComponentType<PanelProps>,
  37. angularPanel?: any
  38. ): PanelPlugin {
  39. const plugin = new PanelPlugin(reactPanel!);
  40. plugin.angularPanelCtrl = angularPanel;
  41. plugin.meta = {
  42. id: options.id!,
  43. type: PluginType.panel,
  44. name: options.id!,
  45. sort: options.sort || 1,
  46. info: {
  47. author: {
  48. name: options.id + 'name',
  49. },
  50. description: '',
  51. links: [],
  52. logos: {
  53. large: '',
  54. small: '',
  55. },
  56. screenshots: [],
  57. updated: '',
  58. version: '',
  59. },
  60. hideFromList: options.hideFromList === true,
  61. module: '',
  62. baseUrl: '',
  63. };
  64. return plugin;
  65. }
  66. export function getMockPlugin(overrides?: Partial<PluginMeta>): PluginMeta {
  67. const defaults: PluginMeta = {
  68. defaultNavUrl: 'some/url',
  69. enabled: false,
  70. hasUpdate: false,
  71. id: '1',
  72. info: {
  73. author: {
  74. name: 'Grafana Labs',
  75. url: 'url/to/GrafanaLabs',
  76. },
  77. description: 'pretty decent plugin',
  78. links: [{ name: 'project', url: 'one link' }],
  79. logos: { small: 'small/logo', large: 'large/logo' },
  80. screenshots: [{ path: `screenshot`, name: 'test' }],
  81. updated: '2018-09-26',
  82. version: '1',
  83. },
  84. latestVersion: '1',
  85. name: 'pretty cool plugin 1',
  86. baseUrl: 'path/to/plugin',
  87. pinned: false,
  88. type: PluginType.panel,
  89. module: 'path/to/module',
  90. };
  91. return defaultsDeep(overrides || {}, defaults) as PluginMeta;
  92. }