pluginMocks.ts 2.3 KB

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