Skip to content

Commit c138269

Browse files
feat(GlobalBanner): add actionButton prop
1 parent e5051cd commit c138269

File tree

5 files changed

+1181
-95
lines changed

5 files changed

+1181
-95
lines changed

packages/react/src/components/global-banner/global-banner.test.tsx

+67-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,69 @@
11
import React from 'react';
22
import { mountWithTheme, renderWithProviders } from '../../test-utils/renderer';
3-
import { GlobalBanner } from './global-banner';
3+
import { ActionButton, GlobalBanner, MessageType } from './global-banner';
44
import { getByTestId } from '../../test-utils/enzyme-selectors';
55

6+
const defaultActionButton: ActionButton = {
7+
label: 'Test button',
8+
onClick: jest.fn(),
9+
};
10+
11+
const messageTypeArray: MessageType[] = ['alert', 'warning', 'info'];
12+
613
describe('GlobalBanner', () => {
7-
test('Matches snapshot (desktop)', () => {
8-
const tree = renderWithProviders(
9-
<GlobalBanner label="Test" type="warning">
10-
WARNING! Lorem ipsum
11-
</GlobalBanner>,
12-
'desktop',
13-
);
14+
messageTypeArray.forEach((type): void => {
15+
test(`Matches snapshot (desktop, ${type})`, () => {
16+
const tree = renderWithProviders(
17+
<GlobalBanner actionButton={defaultActionButton} label={type} type={type}>
18+
Test content
19+
</GlobalBanner>,
20+
'desktop',
21+
);
22+
23+
expect(tree).toMatchSnapshot();
24+
});
1425

15-
expect(tree).toMatchSnapshot();
26+
test(`Matches snapshot (mobile, ${type})`, () => {
27+
const tree = renderWithProviders(
28+
<GlobalBanner actionButton={defaultActionButton} label={type} type={type}>
29+
Test content
30+
</GlobalBanner>,
31+
'mobile',
32+
);
33+
34+
expect(tree).toMatchSnapshot();
35+
});
1636
});
1737

18-
test('Matches snapshot (mobile)', () => {
19-
const tree = renderWithProviders(
20-
<GlobalBanner label="Test" type="alert">
21-
ERROR! Lorem ipsum
38+
test('Should call action-button onClick callback when action-button is clicked', () => {
39+
const callback = jest.fn();
40+
const wrapper = mountWithTheme(
41+
<GlobalBanner
42+
actionButton={{
43+
label: 'Test button',
44+
onClick: callback,
45+
}}
46+
label="Test"
47+
type="warning"
48+
>
49+
Test
2250
</GlobalBanner>,
23-
'mobile',
2451
);
2552

26-
expect(tree).toMatchSnapshot();
53+
getByTestId(wrapper, 'action-button').simulate('click');
54+
55+
expect(callback).toHaveBeenCalledTimes(1);
2756
});
2857

29-
test('Ignore button hides the banner', () => {
58+
test('Ignore-button hides the banner', () => {
3059
const wrapper = mountWithTheme(
31-
<GlobalBanner label="Test" type="warning">WARNING! test test</GlobalBanner>,
60+
<GlobalBanner
61+
actionButton={defaultActionButton}
62+
label="Test"
63+
type="warning"
64+
>
65+
WARNING! test test
66+
</GlobalBanner>,
3267
);
3368

3469
getByTestId(wrapper, 'ignore-button').simulate('click');
@@ -39,15 +74,28 @@ describe('GlobalBanner', () => {
3974
describe('Hidden property', () => {
4075
test('hides the component', () => {
4176
const wrapper = mountWithTheme(
42-
<GlobalBanner label="Test" type="warning" hidden>WARNING! test test</GlobalBanner>,
77+
<GlobalBanner
78+
actionButton={defaultActionButton}
79+
label="Test"
80+
type="warning"
81+
hidden
82+
>
83+
WARNING! test test
84+
</GlobalBanner>,
4385
);
4486

4587
expect(getByTestId(wrapper, 'container').exists()).toBe(false);
4688
});
4789

4890
test('does not hide by default', () => {
4991
const wrapper = mountWithTheme(
50-
<GlobalBanner label="Test" type="warning">WARNING! test test</GlobalBanner>,
92+
<GlobalBanner
93+
actionButton={defaultActionButton}
94+
label="Test"
95+
type="warning"
96+
>
97+
WARNING! test test
98+
</GlobalBanner>,
5199
);
52100

53101
expect(getByTestId(wrapper, 'container').exists()).toBe(true);

0 commit comments

Comments
 (0)