mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
07abc53cce
* BannerBase to TS * snapshot updates * more snapshot updates * addressing type definition error * updating eth-sign-modal snapshot * Updates to stories, types and adding data-testid * Updating snapshots * updating snapshot of blockaid-banner-alert and adding unit test for childrenWrapperProps * BannerBase updates to stories, adding locale for close button, removing static data-testid in favor of using it at the instance, updating snapshots associated with those changes * Removing incorrect arg from storybook file * Updating html element in security provider e2e test to match BannerBase. Also updating snapshot of ConfirmTransaction page * Fixing e2e tests --------- Co-authored-by: georgewrmarshall <george.marshall@consensys.net>
104 lines
3.3 KiB
JavaScript
104 lines
3.3 KiB
JavaScript
/* eslint-disable jest/require-top-level-describe */
|
|
import { render } from '@testing-library/react';
|
|
import React from 'react';
|
|
|
|
import { renderWithUserEvent } from '../../../../test/lib/render-helpers';
|
|
|
|
import { BannerTip, BannerTipLogoType } from '.';
|
|
|
|
describe('BannerTip', () => {
|
|
it('should render BannerTip element correctly', () => {
|
|
const { getByTestId, container } = render(
|
|
<BannerTip data-testid="bannerTip" title="BannerTip test">
|
|
should render BannerTip element correctly
|
|
</BannerTip>,
|
|
);
|
|
expect(getByTestId('bannerTip')).toHaveClass('mm-banner-tip');
|
|
expect(container).toMatchSnapshot();
|
|
});
|
|
|
|
it('should render with different logo types', () => {
|
|
const { getByTestId } = render(
|
|
<>
|
|
<BannerTip
|
|
logoType={BannerTipLogoType.Greeting}
|
|
logoProps={{ 'data-testid': 'banner-tip-greeting' }}
|
|
>
|
|
should render BannerTip element correctly
|
|
</BannerTip>
|
|
<BannerTip
|
|
logoType={BannerTipLogoType.Chat}
|
|
logoProps={{ 'data-testid': 'banner-tip-chat' }}
|
|
>
|
|
should render BannerTip element correctly
|
|
</BannerTip>
|
|
</>,
|
|
);
|
|
const imageElement = getByTestId('banner-tip-greeting');
|
|
expect(imageElement.tagName).toBe('IMG');
|
|
expect(getByTestId('banner-tip-greeting')).toHaveClass(
|
|
'mm-banner-tip--logo',
|
|
);
|
|
expect(getByTestId('banner-tip-chat')).toHaveClass('mm-banner-tip--logo');
|
|
});
|
|
|
|
it('should render with added classname', () => {
|
|
const { getByTestId } = render(
|
|
<BannerTip
|
|
className="mm-banner-tip--test"
|
|
data-testid="bannerTip"
|
|
title="BannerTip test"
|
|
>
|
|
should render BannerTip element correctly
|
|
</BannerTip>,
|
|
);
|
|
expect(getByTestId('bannerTip')).toHaveClass('mm-banner-tip--test');
|
|
});
|
|
|
|
it('should render BannerTip title', () => {
|
|
const { getByText } = render(<BannerTip title="BannerTip title test" />);
|
|
expect(getByText('BannerTip title test')).toBeDefined();
|
|
});
|
|
|
|
it('should render BannerTip description', () => {
|
|
const { getByText } = render(
|
|
<BannerTip description="BannerTip description test" />,
|
|
);
|
|
expect(getByText('BannerTip description test')).toBeDefined();
|
|
});
|
|
|
|
it('should render BannerTip action button', () => {
|
|
const { getByTestId } = render(
|
|
<BannerTip
|
|
title="Action prop demo"
|
|
actionButtonLabel="Action"
|
|
actionButtonProps={{
|
|
'data-testid': 'action',
|
|
className: 'mm-banner-base__action',
|
|
}}
|
|
actionButtonOnClick={() =>
|
|
console.log('ButtonLink actionButtonOnClick demo')
|
|
}
|
|
>
|
|
Use actionButtonLabel for action text, actionButtonOnClick for the
|
|
onClick handler, and actionButtonProps to pass any ButtonLink prop types
|
|
such as iconName
|
|
</BannerTip>,
|
|
);
|
|
expect(getByTestId('action')).toHaveClass('mm-banner-base__action');
|
|
});
|
|
|
|
it('should render and fire onClose event', async () => {
|
|
const onClose = jest.fn();
|
|
const { user, getByTestId } = renderWithUserEvent(
|
|
<BannerTip
|
|
title="onClose Test"
|
|
closeButtonProps={{ 'data-testid': 'close-button' }}
|
|
onClose={onClose}
|
|
/>,
|
|
);
|
|
await user.click(getByTestId('close-button'));
|
|
expect(onClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|