settingsBreadcrumbDropdown.spec.jsx 2.3 KB

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