diff --git a/app/component-library/components/Banners/Banner/Banner.test.tsx b/app/component-library/components/Banners/Banner/Banner.test.tsx new file mode 100644 index 00000000000..94ba52874eb --- /dev/null +++ b/app/component-library/components/Banners/Banner/Banner.test.tsx @@ -0,0 +1,95 @@ +import React from 'react'; + +import { render } from '@testing-library/react-native'; +import Banner from './Banner'; +import Text from '../../Texts/Text/Text'; +import { BannerAlertSeverity } from './variants/BannerAlert/BannerAlert.types'; +import { BannerVariant } from './Banner.types'; +import { ButtonVariants } from '../../Buttons/Button'; +import { IconName } from '../../Icons/Icon'; +import { ButtonIconSizes, ButtonIconVariants } from '../../Buttons/ButtonIcon'; +import { TESTID_BANNER_CLOSE_BUTTON_ICON } from './foundation/BannerBase/BannerBase.constants'; + +describe('Banner', () => { + it('should render correctly', () => { + const wrapper = render( + , + ); + expect(wrapper).toMatchSnapshot(); + }); + + it('should render correctly with a start accessory', async () => { + const wrapper = render( + Test Start accessory} + />, + ); + + expect(wrapper).toMatchSnapshot(); + expect(await wrapper.findByText('Test Start accessory')).toBeDefined(); + }); + + it('should render correctly with an action button', async () => { + const wrapper = render( + jest.fn(), + variant: ButtonVariants.Secondary, + }} + />, + ); + + expect(wrapper).toMatchSnapshot(); + expect(await wrapper.findByText('Test Action Button')).toBeDefined(); + }); + + it('should render correctly with a close button', async () => { + const wrapper = render( + jest.fn(), + variant: ButtonVariants.Secondary, + }} + closeButtonProps={{ + onPress: () => jest.fn(), + iconName: IconName.Close, + variant: ButtonIconVariants.Primary, + size: ButtonIconSizes.Sm, + }} + />, + ); + + expect(wrapper).toMatchSnapshot(); + expect(await wrapper.findByText('Test Action Button')).toBeDefined(); + expect( + await wrapper.queryByTestId(TESTID_BANNER_CLOSE_BUTTON_ICON), + ).toBeDefined(); + }); +}); diff --git a/app/component-library/components/Banners/Banner/README.md b/app/component-library/components/Banners/Banner/README.md index a2e2beeeeab..a8e5ce7e2dd 100644 --- a/app/component-library/components/Banners/Banner/README.md +++ b/app/component-library/components/Banners/Banner/README.md @@ -114,6 +114,14 @@ Optional prop to control the close button's props. | :-------------------------------------------------- | :------------------------------------------------------ | | [ButtonIconProps](../../../../Buttons/ButtonIcon/ButtonIcon.types.ts) | No | +### `children` + +Optional prop to add children components to the Banner + +| TYPE | REQUIRED | +| :-------------------------------------------------- | :------------------------------------------------------ | +| React.ReactNode | No | + ## Usage ```javascript diff --git a/app/component-library/components/Banners/Banner/__snapshots__/Banner.test.tsx.snap b/app/component-library/components/Banners/Banner/__snapshots__/Banner.test.tsx.snap new file mode 100644 index 00000000000..11e7d17f6e3 --- /dev/null +++ b/app/component-library/components/Banners/Banner/__snapshots__/Banner.test.tsx.snap @@ -0,0 +1,412 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Banner should render correctly 1`] = ` + + + + + + + Hello Error Banner World + + + This is nothing but a test of the emergency broadcast system. + + + +`; + +exports[`Banner should render correctly with a close button 1`] = ` + + + + + + + Hello Error Banner World + + + This is nothing but a test of the emergency broadcast system. + + + + Test Action Button + + + + + + + + + +`; + +exports[`Banner should render correctly with a start accessory 1`] = ` + + + + Test Start accessory + + + + + Hello Error Banner World + + + This is nothing but a test of the emergency broadcast system. + + + +`; + +exports[`Banner should render correctly with an action button 1`] = ` + + + + + + + Hello Error Banner World + + + This is nothing but a test of the emergency broadcast system. + + + + Test Action Button + + + + +`; diff --git a/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.constants.tsx b/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.constants.tsx index bf13358249d..b1ae89b3eaa 100644 --- a/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.constants.tsx +++ b/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.constants.tsx @@ -17,6 +17,9 @@ import { SAMPLE_ICON_PROPS } from '../../../../Icons/Icon/Icon.constants'; // Internal dependencies. import { BannerBaseProps } from './BannerBase.types'; +// Test IDs +export const TESTID_BANNER_CLOSE_BUTTON_ICON = 'banner-close-button-icon'; + // Defaults export const DEFAULT_BANNERBASE_TITLE_TEXTVARIANT = TextVariant.BodyLGMedium; export const DEFAULT_BANNERBASE_DESCRIPTION_TEXTVARIANT = TextVariant.BodyMD; diff --git a/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.tsx b/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.tsx index 3e2954266b9..ea46b42f796 100644 --- a/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.tsx +++ b/app/component-library/components/Banners/Banner/foundation/BannerBase/BannerBase.tsx @@ -22,6 +22,7 @@ import { DEFAULT_BANNERBASE_CLOSEBUTTON_BUTTONICONVARIANT, DEFAULT_BANNERBASE_CLOSEBUTTON_BUTTONICONSIZE, DEFAULT_BANNERBASE_CLOSEBUTTON_ICONNAME, + TESTID_BANNER_CLOSE_BUTTON_ICON, } from './BannerBase.constants'; const BannerBase: React.FC = ({ @@ -32,6 +33,7 @@ const BannerBase: React.FC = ({ actionButtonProps, onClose, closeButtonProps, + children, ...props }) => { const { styles } = useStyles(styleSheet, { style }); @@ -63,10 +65,12 @@ const BannerBase: React.FC = ({ {...actionButtonProps} /> )} + {children} {(onClose || closeButtonProps) && (