pluginMocks.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { PanelPluginMeta, PluginMeta, PluginType, PanelDataFormat, 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;
  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. dataFormats: [PanelDataFormat.TimeSeries],
  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 const getMockPlugin = () => {
  67. return {
  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` }],
  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. } as PluginMeta;
  91. };