ResponseErrorContainer.test.tsx 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { render, screen } from '@testing-library/react';
  2. import React from 'react';
  3. import { Provider } from 'react-redux';
  4. import { DataQueryError, LoadingState } from '@grafana/data';
  5. import { selectors } from '@grafana/e2e-selectors';
  6. import { configureStore } from '../../store/configureStore';
  7. import { ExploreId } from '../../types';
  8. import { ResponseErrorContainer } from './ResponseErrorContainer';
  9. describe('ResponseErrorContainer', () => {
  10. it('shows error message if it does not contain refId', async () => {
  11. const errorMessage = 'test error';
  12. setup({
  13. message: errorMessage,
  14. });
  15. const errorEl = screen.getByTestId(selectors.components.Alert.alertV2('error'));
  16. expect(errorEl).toBeInTheDocument();
  17. expect(errorEl).toHaveTextContent(errorMessage);
  18. });
  19. it('do not show error if there is a refId', async () => {
  20. const errorMessage = 'test error';
  21. setup({
  22. refId: 'someId',
  23. message: errorMessage,
  24. });
  25. const errorEl = screen.queryByTestId(selectors.components.Alert.alertV2('error'));
  26. expect(errorEl).not.toBeInTheDocument();
  27. });
  28. it('shows error.data.message if error.message does not exist', async () => {
  29. const errorMessage = 'test error';
  30. setup({
  31. data: {
  32. message: 'test error',
  33. },
  34. });
  35. const errorEl = screen.getByTestId(selectors.components.Alert.alertV2('error'));
  36. expect(errorEl).toBeInTheDocument();
  37. expect(errorEl).toHaveTextContent(errorMessage);
  38. });
  39. });
  40. function setup(error: DataQueryError) {
  41. const store = configureStore();
  42. store.getState().explore[ExploreId.left].queryResponse = {
  43. timeRange: {} as any,
  44. series: [],
  45. state: LoadingState.Error,
  46. error,
  47. graphFrames: [],
  48. logsFrames: [],
  49. tableFrames: [],
  50. traceFrames: [],
  51. nodeGraphFrames: [],
  52. graphResult: null,
  53. logsResult: null,
  54. tableResult: null,
  55. };
  56. render(
  57. <Provider store={store}>
  58. <ResponseErrorContainer exploreId={ExploreId.left} />
  59. </Provider>
  60. );
  61. }