processQueryErrorsEpic.test.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { mockExploreState } from 'test/mocks/mockExploreState';
  2. import { epicTester } from 'test/core/redux/epicTester';
  3. import { processQueryErrorsAction, queryFailureAction } from '../actionTypes';
  4. import { processQueryErrorsEpic } from './processQueryErrorsEpic';
  5. describe('processQueryErrorsEpic', () => {
  6. let originalConsoleError = console.error;
  7. beforeEach(() => {
  8. originalConsoleError = console.error;
  9. console.error = jest.fn();
  10. });
  11. afterEach(() => {
  12. console.error = originalConsoleError;
  13. });
  14. describe('when processQueryErrorsAction is dispatched', () => {
  15. describe('and datasourceInstance is the same', () => {
  16. describe('and the response is not cancelled', () => {
  17. it('then queryFailureAction is dispatched', () => {
  18. const { datasourceId, exploreId, state, eventBridge } = mockExploreState();
  19. const response = { message: 'Something went terribly wrong!' };
  20. epicTester(processQueryErrorsEpic, state)
  21. .whenActionIsDispatched(processQueryErrorsAction({ exploreId, datasourceId, response }))
  22. .thenResultingActionsEqual(queryFailureAction({ exploreId, response }));
  23. expect(console.error).toBeCalledTimes(1);
  24. expect(console.error).toBeCalledWith(response);
  25. expect(eventBridge.emit).toBeCalledTimes(1);
  26. expect(eventBridge.emit).toBeCalledWith('data-error', response);
  27. });
  28. });
  29. describe('and the response is cancelled', () => {
  30. it('then no actions are dispatched', () => {
  31. const { datasourceId, exploreId, state, eventBridge } = mockExploreState();
  32. const response = { cancelled: true, message: 'Something went terribly wrong!' };
  33. epicTester(processQueryErrorsEpic, state)
  34. .whenActionIsDispatched(processQueryErrorsAction({ exploreId, datasourceId, response }))
  35. .thenNoActionsWhereDispatched();
  36. expect(console.error).not.toBeCalled();
  37. expect(eventBridge.emit).not.toBeCalled();
  38. });
  39. });
  40. });
  41. describe('and datasourceInstance is not the same', () => {
  42. describe('and the response is not cancelled', () => {
  43. it('then no actions are dispatched', () => {
  44. const { exploreId, state, eventBridge } = mockExploreState();
  45. const response = { message: 'Something went terribly wrong!' };
  46. epicTester(processQueryErrorsEpic, state)
  47. .whenActionIsDispatched(processQueryErrorsAction({ exploreId, datasourceId: 'other id', response }))
  48. .thenNoActionsWhereDispatched();
  49. expect(console.error).not.toBeCalled();
  50. expect(eventBridge.emit).not.toBeCalled();
  51. });
  52. });
  53. });
  54. });
  55. });