lineChartWidget.spec.tsx 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. meta={{
  13. fields: {
  14. 'eps()': 'rate',
  15. },
  16. units: {
  17. 'eps()': '1/second',
  18. },
  19. }}
  20. />
  21. );
  22. });
  23. });
  24. describe('Visualization', () => {
  25. it('Explains missing data', () => {
  26. render(<LineChartWidget />);
  27. expect(screen.getByText('No Data')).toBeInTheDocument();
  28. });
  29. });
  30. describe('State', () => {
  31. it('Shows a loading placeholder', () => {
  32. render(<LineChartWidget isLoading />);
  33. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  34. });
  35. it('Loading state takes precedence over error state', () => {
  36. render(
  37. <LineChartWidget isLoading error={new Error('Parsing error of old value')} />
  38. );
  39. expect(screen.getByTestId('loading-indicator')).toBeInTheDocument();
  40. });
  41. it('Shows an error message', () => {
  42. render(<LineChartWidget error={new Error('Uh oh')} />);
  43. expect(screen.getByText('Error: Uh oh')).toBeInTheDocument();
  44. });
  45. it('Shows a retry button', async () => {
  46. const onRetry = jest.fn();
  47. render(<LineChartWidget error={new Error('Oh no!')} onRetry={onRetry} />);
  48. await userEvent.click(screen.getByRole('button', {name: 'Retry'}));
  49. expect(onRetry).toHaveBeenCalledTimes(1);
  50. });
  51. it('Hides other actions if there is an error and a retry handler', () => {
  52. const onRetry = jest.fn();
  53. render(
  54. <LineChartWidget
  55. error={new Error('Oh no!')}
  56. onRetry={onRetry}
  57. actions={[
  58. {
  59. key: 'Open in Discover',
  60. to: '/discover',
  61. },
  62. ]}
  63. />
  64. );
  65. expect(screen.getByRole('button', {name: 'Retry'})).toBeInTheDocument();
  66. expect(
  67. screen.queryByRole('link', {name: 'Open in Discover'})
  68. ).not.toBeInTheDocument();
  69. });
  70. });
  71. });