runQueriesEpic.test.ts 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import { mockExploreState } from 'test/mocks/mockExploreState';
  2. import { epicTester } from 'test/core/redux/epicTester';
  3. import { runQueriesAction, stateSaveAction, runQueriesBatchAction, clearQueriesAction } from '../actionTypes';
  4. import { runQueriesEpic } from './runQueriesEpic';
  5. describe('runQueriesEpic', () => {
  6. describe('when runQueriesAction is dispatched', () => {
  7. describe('and there is no datasourceError', () => {
  8. describe('and we have non empty queries', () => {
  9. describe('and explore is not live', () => {
  10. it('then runQueriesBatchAction and stateSaveAction are dispatched', () => {
  11. const queries = [{ refId: 'A', key: '123456', expr: '{__filename__="some.log"}' }];
  12. const { exploreId, state, datasourceInterval, containerWidth } = mockExploreState({ queries });
  13. epicTester(runQueriesEpic, state)
  14. .whenActionIsDispatched(runQueriesAction({ exploreId }))
  15. .thenResultingActionsEqual(
  16. runQueriesBatchAction({
  17. exploreId,
  18. queryOptions: { interval: datasourceInterval, maxDataPoints: containerWidth, live: false },
  19. })
  20. );
  21. });
  22. });
  23. describe('and explore is live', () => {
  24. it('then runQueriesBatchAction and stateSaveAction are dispatched', () => {
  25. const queries = [{ refId: 'A', key: '123456', expr: '{__filename__="some.log"}' }];
  26. const { exploreId, state, datasourceInterval, containerWidth } = mockExploreState({
  27. queries,
  28. isLive: true,
  29. streaming: true,
  30. });
  31. epicTester(runQueriesEpic, state)
  32. .whenActionIsDispatched(runQueriesAction({ exploreId }))
  33. .thenResultingActionsEqual(
  34. runQueriesBatchAction({
  35. exploreId,
  36. queryOptions: { interval: datasourceInterval, maxDataPoints: containerWidth, live: true },
  37. })
  38. );
  39. });
  40. });
  41. });
  42. describe('and we have no queries', () => {
  43. it('then clearQueriesAction and stateSaveAction are dispatched', () => {
  44. const queries: any[] = [];
  45. const { exploreId, state } = mockExploreState({ queries });
  46. epicTester(runQueriesEpic, state)
  47. .whenActionIsDispatched(runQueriesAction({ exploreId }))
  48. .thenResultingActionsEqual(clearQueriesAction({ exploreId }), stateSaveAction());
  49. });
  50. });
  51. });
  52. describe('and there is a datasourceError', () => {
  53. it('then no actions are dispatched', () => {
  54. const { exploreId, state } = mockExploreState({
  55. datasourceError: { message: 'Some error' },
  56. });
  57. epicTester(runQueriesEpic, state)
  58. .whenActionIsDispatched(runQueriesAction({ exploreId }))
  59. .thenNoActionsWhereDispatched();
  60. });
  61. });
  62. });
  63. });