areaChartWidget.spec.tsx 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import {AreaChartWidget} from './areaChartWidget';
  3. import sampleLatencyTimeSeries from './sampleLatencyTimeSeries.json';
  4. import sampleSpanDurationTimeSeries from './sampleSpanDurationTimeSeries.json';
  5. describe('AreaChartWidget', () => {
  6. describe('Layout', () => {
  7. it('Renders', () => {
  8. render(
  9. <AreaChartWidget
  10. title="eps()"
  11. description="Number of events per second"
  12. timeseries={[sampleLatencyTimeSeries, sampleSpanDurationTimeSeries]}
  13. />
  14. );
  15. });
  16. });
  17. describe('Visualization', () => {
  18. it('Explains missing data', () => {
  19. render(<AreaChartWidget />);
  20. expect(screen.getByText('No Data')).toBeInTheDocument();
  21. });
  22. });
  23. describe('State', () => {
  24. it('Shows a loading placeholder', () => {
  25. render(<AreaChartWidget isLoading />);
  26. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  27. });
  28. it('Loading state takes precedence over error state', () => {
  29. render(
  30. <AreaChartWidget isLoading error={new Error('Parsing error of old value')} />
  31. );
  32. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  33. });
  34. it('Shows an error message', () => {
  35. render(<AreaChartWidget error={new Error('Uh oh')} />);
  36. expect(screen.getByText('Error: Uh oh')).toBeInTheDocument();
  37. });
  38. it('Shows a retry button', async () => {
  39. const onRetry = jest.fn();
  40. render(<AreaChartWidget error={new Error('Oh no!')} onRetry={onRetry} />);
  41. await userEvent.click(screen.getByRole('button', {name: 'Retry'}));
  42. expect(onRetry).toHaveBeenCalledTimes(1);
  43. });
  44. it('Hides other actions if there is an error and a retry handler', () => {
  45. const onRetry = jest.fn();
  46. render(
  47. <AreaChartWidget
  48. error={new Error('Oh no!')}
  49. onRetry={onRetry}
  50. actions={[
  51. {
  52. key: 'Open in Discover',
  53. to: '/discover',
  54. },
  55. ]}
  56. />
  57. );
  58. expect(screen.getByRole('button', {name: 'Retry'})).toBeInTheDocument();
  59. expect(
  60. screen.queryByRole('link', {name: 'Open in Discover'})
  61. ).not.toBeInTheDocument();
  62. });
  63. });
  64. });