lineChartWidget.spec.tsx 2.1 KB

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