mockExploreState.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import { DataSourceApi } from '@grafana/ui/src/types/datasource';
  2. import { ExploreId, ExploreItemState, ExploreState } from 'app/types/explore';
  3. import { makeExploreItemState } from 'app/features/explore/state/reducers';
  4. import { StoreState } from 'app/types';
  5. export const mockExploreState = (options: any = {}) => {
  6. const isLive = options.isLive || false;
  7. const history = [];
  8. const eventBridge = {
  9. emit: jest.fn(),
  10. };
  11. const streaming = options.streaming || undefined;
  12. const datasourceInterval = options.datasourceInterval || '';
  13. const refreshInterval = options.refreshInterval || '';
  14. const containerWidth = options.containerWidth || 1980;
  15. const queries = options.queries || [];
  16. const datasourceError = options.datasourceError || null;
  17. const scanner = options.scanner || jest.fn();
  18. const scanning = options.scanning || false;
  19. const datasourceId = options.datasourceId || '1337';
  20. const exploreId = ExploreId.left;
  21. const datasourceInstance: DataSourceApi<any> = options.datasourceInstance || {
  22. id: 1337,
  23. query: jest.fn(),
  24. name: 'test',
  25. testDatasource: jest.fn(),
  26. meta: {
  27. id: datasourceId,
  28. streaming,
  29. },
  30. interval: datasourceInterval,
  31. };
  32. const urlReplaced = options.urlReplaced || false;
  33. const left: ExploreItemState = options.left || {
  34. ...makeExploreItemState(),
  35. containerWidth,
  36. datasourceError,
  37. datasourceInstance,
  38. eventBridge,
  39. history,
  40. isLive,
  41. queries,
  42. refreshInterval,
  43. scanner,
  44. scanning,
  45. urlReplaced,
  46. };
  47. const right: ExploreItemState = options.right || {
  48. ...makeExploreItemState(),
  49. containerWidth,
  50. datasourceError,
  51. datasourceInstance,
  52. eventBridge,
  53. history,
  54. isLive,
  55. queries,
  56. refreshInterval,
  57. scanner,
  58. scanning,
  59. urlReplaced,
  60. };
  61. const split: boolean = options.split || false;
  62. const explore: ExploreState = {
  63. left,
  64. right,
  65. split,
  66. };
  67. const state: Partial<StoreState> = {
  68. explore,
  69. };
  70. return {
  71. containerWidth,
  72. datasourceId,
  73. datasourceInstance,
  74. datasourceInterval,
  75. eventBridge,
  76. exploreId,
  77. history,
  78. queries,
  79. refreshInterval,
  80. state,
  81. scanner,
  82. };
  83. };