diff --git a/src/components/InfoBar/InfoBar.test.tsx b/src/components/InfoBar/InfoBar.test.tsx new file mode 100644 index 000000000..2c0e43c68 --- /dev/null +++ b/src/components/InfoBar/InfoBar.test.tsx @@ -0,0 +1,83 @@ +import React from 'react'; +import Enzyme from 'enzyme'; +import Adapter from '@wojtekmaj/enzyme-adapter-react-17'; +import MatchMediaMock from 'jest-matchmedia-mock'; +import { InfoBar, InfoBarType } from './'; +import { fireEvent, render } from '@testing-library/react'; +import { IconName } from '../Icon'; + +Enzyme.configure({ adapter: new Adapter() }); + +let matchMedia: any; + +describe('InfoBar', () => { + beforeAll(() => { + matchMedia = new MatchMediaMock(); + }); + + afterEach(() => { + matchMedia.clear(); + }); + + test('Renders without crashing', () => { + const { container, getByRole } = render( + + ); + const infoBar = getByRole('alert'); + expect(() => container).not.toThrowError(); + expect(infoBar).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); + + test('Calls onClose callback when close button is clicked', () => { + const onClose = jest.fn(); + const { container } = render( + + ); + fireEvent.click(container.querySelector('.close-button')); + expect(onClose).toHaveBeenCalled(); + }); + + test('Renders a custom icon when the icon prop uses a custom icon', () => { + const { container } = render( + + ); + expect(container.querySelector('.icon')).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); + + test('InfoBar is Disruptive', () => { + const { container } = render( + + ); + expect(container.querySelector('.disruptive')).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); + + test('InfoBar is Neutral', () => { + const { container } = render( + + ); + expect(container.querySelector('.neutral')).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); + + test('InfoBar is Positive', () => { + const { container } = render( + + ); + expect(container.querySelector('.positive')).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); + + test('InfoBar is Warning', () => { + const { container } = render( + + ); + expect(container.querySelector('.warning')).toBeTruthy(); + expect(container).toMatchSnapshot(); + }); +}); diff --git a/src/components/InfoBar/InfoBar.tsx b/src/components/InfoBar/InfoBar.tsx index bf3dc5119..930fbcce3 100644 --- a/src/components/InfoBar/InfoBar.tsx +++ b/src/components/InfoBar/InfoBar.tsx @@ -93,8 +93,12 @@ export const InfoBar: FC = React.forwardRef(
{content}
{actionButtonProps && ( )} {closable && ( @@ -103,8 +107,12 @@ export const InfoBar: FC = React.forwardRef( iconProps={{ path: closeIcon }} onClick={onClose} shape={ButtonShape.Round} + transparent {...closeButtonProps} - disruptive={type === InfoBarType.disruptive} + classNames={mergeClasses([ + styles.closeButton, + closeButtonProps?.classNames, + ])} /> )} diff --git a/src/components/InfoBar/__snapshots__/InfoBar.test.tsx.snap b/src/components/InfoBar/__snapshots__/InfoBar.test.tsx.snap new file mode 100644 index 000000000..b9f6bc73a --- /dev/null +++ b/src/components/InfoBar/__snapshots__/InfoBar.test.tsx.snap @@ -0,0 +1,187 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`InfoBar InfoBar is Disruptive 1`] = ` +
+ +
+`; + +exports[`InfoBar InfoBar is Neutral 1`] = ` +
+ +
+`; + +exports[`InfoBar InfoBar is Positive 1`] = ` +
+ +
+`; + +exports[`InfoBar InfoBar is Warning 1`] = ` +
+ +
+`; + +exports[`InfoBar Renders a custom icon when the icon prop uses a custom icon 1`] = ` +
+ +
+`; + +exports[`InfoBar Renders without crashing 1`] = ` +
+ +
+`; diff --git a/src/components/InfoBar/infoBar.module.scss b/src/components/InfoBar/infoBar.module.scss index deec4c39e..8e14fc258 100644 --- a/src/components/InfoBar/infoBar.module.scss +++ b/src/components/InfoBar/infoBar.module.scss @@ -11,35 +11,74 @@ &.neutral { background-color: var(--info-bar-background-color); color: var(--info-bar-text-color); + + .action-button, + .close-button { + &:active { + background-color: var(--info-bar-button-active-background-color); + } + } } &.positive { background-color: var(--info-bar-positive-background-color); color: var(--info-bar-positive-text-color); + + .action-button, + .close-button { + &:active { + background-color: var( + --info-bar-positive-button-active-background-color + ); + } + } } &.warning { background-color: var(--info-bar-warning-background-color); color: var(--info-bar-warning-text-color); + + .action-button, + .close-button { + &:active { + background-color: var( + --info-bar-warning-button-active-background-color + ); + } + } } &.disruptive { background-color: var(--info-bar-disruptive-background-color); color: var(--info-bar-disruptive-text-color); + + .action-button, + .close-button { + &:active { + background-color: var( + --info-bar-disruptive-button-active-background-color + ); + } + } } + .action-button, + .close-button, .icon { color: inherit; } + .action-button, + .close-button { + &:hover { + background-color: var(--info-bar-button-hover-background-color); + } + } + .message { flex: 1; display: flex; align-items: center; color: inherit; } - - .buttons-container { - padding: $space-m; - } } diff --git a/src/styles/themes/_default-theme.scss b/src/styles/themes/_default-theme.scss index adc554d3e..c6d1be8e2 100644 --- a/src/styles/themes/_default-theme.scss +++ b/src/styles/themes/_default-theme.scss @@ -643,12 +643,19 @@ // ------ Info Bar theme ------ --info-bar-border-radius: var(--border-radius-xl); --info-bar-background-color: var(--grey-color-10); + --info-bar-button-active-background-color: var(--grey-color-20); + --info-bar-button-hover-background-color: var(--background-color); --info-bar-text-color: var(--grey-color-70); --info-bar-positive-background-color: var(--green-color-10); + --info-bar-positive-button-active-background-color: var(--green-color-20); --info-bar-positive-text-color: var(--green-color-70); --info-bar-warning-background-color: var(--orange-color-10); + --info-bar-warning-button-active-background-color: var(--orange-color-20); --info-bar-warning-text-color: var(--orange-color-70); --info-bar-disruptive-background-color: var(--disruptive-color-10); + --info-bar-disruptive-button-active-background-color: var( + --disruptive-color-20 + ); --info-bar-disruptive-text-color: var(--disruptive-color-70); // ------ Info Bar theme ------