PanelDataErrorView.test.tsx 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { render, screen } from '@testing-library/react';
  2. import { defaultsDeep } from 'lodash';
  3. import React from 'react';
  4. import { Provider } from 'react-redux';
  5. import { getDefaultTimeRange, LoadingState } from '@grafana/data';
  6. import { PanelDataErrorViewProps } from '@grafana/runtime';
  7. import { configureStore } from 'app/store/configureStore';
  8. import { PanelDataErrorView } from './PanelDataErrorView';
  9. describe('PanelDataErrorView', () => {
  10. it('show No data when there is no data', () => {
  11. renderWithProps();
  12. expect(screen.getByText('No data')).toBeInTheDocument();
  13. });
  14. it('show no value field config when there is no data', () => {
  15. renderWithProps({
  16. fieldConfig: {
  17. overrides: [],
  18. defaults: {
  19. noValue: 'Query returned nothing',
  20. },
  21. },
  22. });
  23. expect(screen.getByText('Query returned nothing')).toBeInTheDocument();
  24. });
  25. });
  26. function renderWithProps(overrides?: Partial<PanelDataErrorViewProps>) {
  27. const defaults: PanelDataErrorViewProps = {
  28. panelId: 1,
  29. data: {
  30. state: LoadingState.Done,
  31. series: [],
  32. timeRange: getDefaultTimeRange(),
  33. },
  34. };
  35. const props = defaultsDeep(overrides ?? {}, defaults);
  36. const store = configureStore();
  37. const stuff = render(
  38. <Provider store={store}>
  39. <PanelDataErrorView {...props} />
  40. </Provider>
  41. );
  42. return { ...stuff };
  43. }