breadcrumbDropdown.spec.tsx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. {index: 0, value: '1', label: 'foo'},
  7. {index: 1, value: '2', label: 'bar'},
  8. ];
  9. const createWrapper = () => {
  10. return render(
  11. <BreadcrumbDropdown
  12. route={{path: '/', name: 'root'}}
  13. items={items}
  14. name="Test"
  15. hasMenu
  16. onSelect={selectMock}
  17. />
  18. );
  19. };
  20. it('opens when hovered over crumb', async () => {
  21. createWrapper();
  22. expect(screen.getByText('Test')).toBeInTheDocument();
  23. await userEvent.hover(screen.getByText('Test'));
  24. expect(screen.getByText('foo')).toBeInTheDocument();
  25. expect(screen.getByText('bar')).toBeInTheDocument();
  26. });
  27. it('closes immediately after selecting an item', async () => {
  28. createWrapper();
  29. await userEvent.hover(screen.getByText('Test'));
  30. expect(screen.getByText('foo')).toBeInTheDocument();
  31. await userEvent.click(screen.getByText('foo'));
  32. expect(selectMock).toHaveBeenCalled();
  33. expect(screen.queryByText('foo')).not.toBeInTheDocument();
  34. });
  35. it('stays open when hovered over crumb and then into dropdown menu', async () => {
  36. createWrapper();
  37. await userEvent.hover(screen.getByText('Test'));
  38. expect(screen.getByText('foo')).toBeInTheDocument();
  39. await userEvent.hover(screen.getByText('foo'));
  40. expect(screen.getByText('foo')).toBeInTheDocument();
  41. });
  42. it('closes after entering dropdown and then leaving dropdown', async () => {
  43. createWrapper();
  44. await userEvent.hover(screen.getByText('Test'));
  45. expect(screen.getByText('foo')).toBeInTheDocument();
  46. await userEvent.hover(screen.getByText('foo'));
  47. expect(screen.getByText('foo')).toBeInTheDocument();
  48. await userEvent.unhover(screen.getByText('foo'));
  49. expect(screen.queryByText('foo')).not.toBeInTheDocument();
  50. });
  51. });