123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';
- import BreadcrumbDropdown from 'sentry/views/settings/components/settingsBreadcrumb/breadcrumbDropdown';
- jest.useFakeTimers();
- describe('Settings Breadcrumb Dropdown', () => {
- const selectMock = jest.fn();
- const items = [
- {value: '1', label: 'foo'},
- {value: '2', label: 'bar'},
- ];
- const createWrapper = () => {
- return render(
- <BreadcrumbDropdown items={items} name="Test" hasMenu onSelect={selectMock} />
- );
- };
- it('opens when hovered over crumb', () => {
- createWrapper();
- expect(screen.getByText('Test')).toBeInTheDocument();
- userEvent.hover(screen.getByText('Test'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- expect(screen.getByText('bar')).toBeInTheDocument();
- });
- it('closes after 200ms when mouse leaves crumb', () => {
- createWrapper();
- userEvent.hover(screen.getByText('Test'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- userEvent.unhover(screen.getByText('Test'));
- jest.advanceTimersByTime(10);
- expect(screen.queryByText('foo')).not.toBeInTheDocument();
- });
- it('closes immediately after selecting an item', () => {
- createWrapper();
- userEvent.hover(screen.getByText('Test'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- userEvent.click(screen.getByText('foo'));
- expect(screen.queryByText('foo')).not.toBeInTheDocument();
- });
- it('stays open when hovered over crumb and then into dropdown menu', () => {
- createWrapper();
- userEvent.hover(screen.getByText('Test'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- userEvent.hover(screen.getByText('foo'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- });
- it('closes after entering dropdown and then leaving dropdown', () => {
- createWrapper();
- userEvent.hover(screen.getByText('Test'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- userEvent.hover(screen.getByText('foo'));
- jest.runAllTimers();
- expect(screen.getByText('foo')).toBeInTheDocument();
- userEvent.unhover(screen.getByText('foo'));
- jest.runAllTimers();
- expect(screen.queryByText('foo')).not.toBeInTheDocument();
- });
- });
|