1
1
import React from 'react' ;
2
2
import { mountWithTheme , renderWithProviders } from '../../test-utils/renderer' ;
3
- import { GlobalBanner } from './global-banner' ;
3
+ import { ActionButton , GlobalBanner , MessageType } from './global-banner' ;
4
4
import { getByTestId } from '../../test-utils/enzyme-selectors' ;
5
5
6
+ const defaultActionButton : ActionButton = {
7
+ label : 'Test button' ,
8
+ onClick : jest . fn ( ) ,
9
+ } ;
10
+
11
+ const messageTypeArray : MessageType [ ] = [ 'alert' , 'warning' , 'info' ] ;
12
+
6
13
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
+ } ) ;
14
25
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
+ } ) ;
16
36
} ) ;
17
37
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
22
50
</ GlobalBanner > ,
23
- 'mobile' ,
24
51
) ;
25
52
26
- expect ( tree ) . toMatchSnapshot ( ) ;
53
+ getByTestId ( wrapper , 'action-button' ) . simulate ( 'click' ) ;
54
+
55
+ expect ( callback ) . toHaveBeenCalledTimes ( 1 ) ;
27
56
} ) ;
28
57
29
- test ( 'Ignore button hides the banner' , ( ) => {
58
+ test ( 'Ignore- button hides the banner' , ( ) => {
30
59
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 > ,
32
67
) ;
33
68
34
69
getByTestId ( wrapper , 'ignore-button' ) . simulate ( 'click' ) ;
@@ -39,15 +74,28 @@ describe('GlobalBanner', () => {
39
74
describe ( 'Hidden property' , ( ) => {
40
75
test ( 'hides the component' , ( ) => {
41
76
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 > ,
43
85
) ;
44
86
45
87
expect ( getByTestId ( wrapper , 'container' ) . exists ( ) ) . toBe ( false ) ;
46
88
} ) ;
47
89
48
90
test ( 'does not hide by default' , ( ) => {
49
91
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 > ,
51
99
) ;
52
100
53
101
expect ( getByTestId ( wrapper , 'container' ) . exists ( ) ) . toBe ( true ) ;
0 commit comments