import React from 'react'; import { fireEvent, render, screen } from '../../../test-utils'; import { NavLink } from '.'; import { useLocation } from './useLocation'; jest.mock( './useLocation', () => ({ useLocation: jest.fn(), }) as unknown, ); jest.mock('react-tiny-popover', () => ({ Popover: (props: Record) =>
, })); describe('', () => { it('renders the correct link text', () => { (useLocation as jest.Mock).mockReturnValueOnce({ pathname: '/some-link' }); render( Some Link , ); expect(screen.getByText('Some Link')).toBeInTheDocument(); }); it('renders the new link indicator when isNew is true', () => { (useLocation as jest.Mock).mockReturnValueOnce({ pathname: '/some-link' }); render( Some Link , ); expect(screen.getByTestId('AttentionIndicator-error100')).toBeInTheDocument(); }); it('renders the ActiveNavLinkButton when the link is active', () => { (useLocation as jest.Mock).mockReturnValueOnce({ pathname: '/some-link' }); render( Some Link , ); expect(screen.getByTestId('ActiveNavLinkButton')).toBeInTheDocument(); }); it('renders the NavLinkPopover when it has subLinks', () => { (useLocation as jest.Mock).mockReturnValue({ pathname: '/some-link' }); render( Some Link , ); fireEvent.click(screen.getByText('Some Link')); expect(screen.getByTestId('NavLinkPopover')).toBeInTheDocument(); }); });