import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary'; import Tag from 'sentry/components/tag'; import {IconFire} from 'sentry/icons'; describe('Tag', () => { it('basic', () => { render(Text); expect(screen.getByText('Text')).toBeInTheDocument(); }); it('with icon', () => { render( } type="error"> Error ); expect(screen.getByText('Error')).toBeInTheDocument(); expect(screen.getByTestId('icon-fire')).toBeInTheDocument(); }); it('with tooltip', async () => { render( Tooltip ); expect(screen.getByText('Tooltip')).toBeInTheDocument(); expect(screen.queryByText('lorem ipsum')).not.toBeInTheDocument(); userEvent.hover(screen.getByText('Tooltip')); expect(await screen.findByText('lorem ipsum')).toBeInTheDocument(); }); it('with dismiss', () => { const mockCallback = jest.fn(); render( Dismissable ); expect(screen.getByText('Dismissable')).toBeInTheDocument(); expect(screen.getByRole('button', {name: 'Dismiss'})).toBeInTheDocument(); expect(mockCallback).toHaveBeenCalledTimes(0); userEvent.click(screen.getByRole('button', {name: 'Dismiss'})); expect(mockCallback).toHaveBeenCalledTimes(1); }); it('with internal link', () => { const to = '/organizations/sentry/issues/'; render( Internal link ); expect(screen.getByText('Internal link')).toBeInTheDocument(); expect(screen.getByRole('link', {name: 'Internal link'})).toBeInTheDocument(); expect(screen.getByRole('link', {name: 'Internal link'})).toHaveAttribute('href', to); }); it('with external link', () => { const href = 'https://sentry.io/'; render( External link ); expect(screen.getByText('External link')).toBeInTheDocument(); const link = screen.getByRole('link', {name: 'External link'}); expect(link).toBeInTheDocument(); expect(link).toHaveAttribute('href', href); expect(link).toHaveAttribute('target', '_blank'); }); it('overrides a link default icon', () => { render( }> 3 ); expect(screen.getByTestId('icon-fire')).toBeInTheDocument(); }); });