import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; import Breadcrumbs from 'sentry/components/breadcrumbs'; describe('Breadcrumbs', () => { const routerContext = TestStubs.routerContext(); afterEach(() => { jest.resetAllMocks(); }); function createWrapper() { return render( , {context: routerContext} ); } it('returns null when 0 crumbs', () => { const empty = render(); expect(empty.container).toBeEmptyDOMElement(); }); it('renders crumbs with icon', () => { const wrapper = createWrapper(); expect(wrapper.container).toSnapshot(); }); it('generates correct links', () => { createWrapper(); userEvent.click(screen.getByText('Test 1')); expect(routerContext.context.router.push).toHaveBeenCalledWith('/test1'); userEvent.click(screen.getByText('Test 2')); expect(routerContext.context.router.push).toHaveBeenCalledWith('/test2'); }); it('does not make links where no `to` is provided', () => { createWrapper(); userEvent.click(screen.getByText('Test 3')); expect(routerContext.context.router.push).not.toHaveBeenCalled(); }); it('renders a crumb dropdown', async () => { const onSelect = jest.fn(); render( , {context: routerContext} ); userEvent.hover(screen.getByText('dropdown crumb')); const item3 = await screen.findByText('item3'); expect(item3).toBeInTheDocument(); userEvent.click(item3); expect(onSelect).toHaveBeenCalledWith( expect.objectContaining({label: 'item3'}), expect.anything(), expect.anything() ); }); });