breadcrumbDropdown.spec.jsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
  2. import BreadcrumbDropdown from 'sentry/views/settings/components/settingsBreadcrumb/breadcrumbDropdown';
  3. describe('Settings Breadcrumb Dropdown', () => {
  4. const selectMock = jest.fn();
  5. const items = [
  6. {value: '1', label: 'foo'},
  7. {value: '2', label: 'bar'},
  8. ];
  9. const createWrapper = () => {
  10. return render(
  11. <BreadcrumbDropdown items={items} name="Test" hasMenu onSelect={selectMock} />
  12. );
  13. };
  14. it('opens when hovered over crumb', async () => {
  15. createWrapper();
  16. expect(screen.getByText('Test')).toBeInTheDocument();
  17. await userEvent.hover(screen.getByText('Test'));
  18. expect(screen.getByText('foo')).toBeInTheDocument();
  19. expect(screen.getByText('bar')).toBeInTheDocument();
  20. });
  21. it('closes immediately after selecting an item', async () => {
  22. createWrapper();
  23. await userEvent.hover(screen.getByText('Test'));
  24. expect(screen.getByText('foo')).toBeInTheDocument();
  25. await userEvent.click(screen.getByText('foo'));
  26. expect(selectMock).toHaveBeenCalled();
  27. expect(screen.queryByText('foo')).not.toBeInTheDocument();
  28. });
  29. it('stays open when hovered over crumb and then into dropdown menu', async () => {
  30. createWrapper();
  31. await userEvent.hover(screen.getByText('Test'));
  32. expect(screen.getByText('foo')).toBeInTheDocument();
  33. await userEvent.hover(screen.getByText('foo'));
  34. expect(screen.getByText('foo')).toBeInTheDocument();
  35. });
  36. it('closes after entering dropdown and then leaving dropdown', async () => {
  37. createWrapper();
  38. await userEvent.hover(screen.getByText('Test'));
  39. expect(screen.getByText('foo')).toBeInTheDocument();
  40. await userEvent.hover(screen.getByText('foo'));
  41. expect(screen.getByText('foo')).toBeInTheDocument();
  42. await userEvent.unhover(screen.getByText('foo'));
  43. expect(screen.queryByText('foo')).not.toBeInTheDocument();
  44. });
  45. });