chevronDividedList.spec.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import {render, screen} from 'sentry-test/reactTestingLibrary';
  2. import ChevronDividedList from './chevronDividedList';
  3. describe('ChevronDividedList', () => {
  4. it('should accept zero items and show an empty <List>', () => {
  5. const mockItems = [];
  6. render(<ChevronDividedList items={mockItems} />);
  7. expect(screen.queryByRole('listitem')).not.toBeInTheDocument();
  8. expect(screen.queryByRole('separator')).not.toBeInTheDocument();
  9. });
  10. it('should accept one item and show it in the <List>', () => {
  11. const mockItems = [<span key="1">first</span>];
  12. render(<ChevronDividedList items={mockItems} />);
  13. expect(screen.queryByRole('listitem')).toBeInTheDocument();
  14. expect(screen.queryByRole('separator')).not.toBeInTheDocument();
  15. expect(screen.getByText('first')).toBeInTheDocument();
  16. });
  17. it('should accept two items and show them both in the <List>', () => {
  18. const mockItems = [<span key="1">first</span>, <span key="2">second</span>];
  19. render(<ChevronDividedList items={mockItems} />);
  20. expect(screen.queryAllByRole('listitem')).toHaveLength(2);
  21. expect(screen.queryByRole('separator')).toBeInTheDocument();
  22. expect(screen.getByText('first')).toBeInTheDocument();
  23. expect(screen.getByText('second')).toBeInTheDocument();
  24. });
  25. it('should accept three items and show them all in the <List>', () => {
  26. const mockItems = [
  27. <span key="1">first</span>,
  28. <span key="2">second</span>,
  29. <span key="3">third</span>,
  30. ];
  31. render(<ChevronDividedList items={mockItems} />);
  32. expect(screen.queryAllByRole('listitem')).toHaveLength(3);
  33. expect(screen.queryAllByRole('separator')).toHaveLength(2);
  34. expect(screen.getByText('first')).toBeInTheDocument();
  35. expect(screen.getByText('second')).toBeInTheDocument();
  36. expect(screen.getByText('third')).toBeInTheDocument();
  37. });
  38. it('should accept many items and show them all in the <List>', () => {
  39. const mockItems = [
  40. <span key="1">first</span>,
  41. <span key="2">second</span>,
  42. <span key="3">third</span>,
  43. <span key="4">fourth</span>,
  44. <span key="5">fifth</span>,
  45. <span key="6">sixth</span>,
  46. ];
  47. render(<ChevronDividedList items={mockItems} />);
  48. expect(screen.queryAllByRole('listitem')).toHaveLength(6);
  49. expect(screen.queryAllByRole('separator')).toHaveLength(5);
  50. });
  51. });