UNPKG

@navinc/base-react-components

Version:
62 lines (57 loc) 2.21 kB
import React from 'react' import { render, fireEvent, screen } from '../tests/with-app-context.js' import Banner from './banner.js' describe('Banner', () => { it('renders BannerContainer', () => { const { getByText } = render(<Banner>My Banner</Banner>) expect(getByText(/my banner/i)).toBeTruthy() }) it('renders the supplied icon', () => { render(<Banner icon="actions/minus">My Banner</Banner>) screen.findByTestId('banner-icon').then((icon) => expect(icon).toBeInTheDocument()) }) it('renders an actionIcon with onClick of onDismiss if there is onDismiss', () => { const onDismiss = jest.fn() render(<Banner onDismiss={onDismiss}>My Banner</Banner>) screen.findByTestId('banner-dismiss').then((icon) => { fireEvent.click(icon) expect(onDismiss).toHaveBeenCalled() }) }) it('renders the supplied actionIcon', () => { render( <Banner actionIcon="actions/close" actionHref="/asdf"> My Banner </Banner> ) screen.findByTestId('action-icon').then((icon) => { expect(icon).toBeInTheDocument() }) }) it('renders the title and Copy component', () => { const { getByText } = render( <Banner actionIcon="actions/close" title="my title"> My Banner </Banner> ) expect(getByText(/my title/i)).toBeTruthy() }) it('renders the copy and Copy component', () => { const { getByText } = render(<Banner actionIcon="actions/close" copy="my copy" />) expect(getByText(/my copy/i)).toBeTruthy() }) it('renders a Link if there is an actionLabel and action', () => { const { getByText } = render(<Banner actionLabel="action label" action={jest.fn()} />) expect(getByText(/action label/i)).toBeTruthy() }) it('renders a Link if there is an actionHref and action', () => { const { getByRole } = render(<Banner actionHref="/action-href" />) expect(getByRole('link')).toBeTruthy() }) it('passes action props to underlying links', () => { const { getByText } = render( <Banner actionTarget="_blank" actionHref="/home" actionLabel="action label" actionTrackingContext={{}} /> ) expect(getByText(/action label/i).target).toBe('_blank') }) })