1+ import reducer , { _alert } from './index' ;
2+
3+ describe ( 'alert reducer' , ( ) => {
4+
5+ // mock document.getElementsByClassName
6+ // as it used in styling the alert pop-up
7+
8+ const originalDocument = global . document ;
9+
10+ beforeEach ( ( ) => {
11+ global . document = Object . assign ( document , {
12+ getElementsByClassName : ( selector ) => [ {
13+ style : {
14+ color : 'blue'
15+ }
16+ } ]
17+ } ) ;
18+ } ) ;
19+
20+ afterEach ( ( ) => {
21+ global . document = originalDocument ;
22+ } ) ;
23+
24+ it ( 'should initialize the default alert' , ( ) => {
25+ const action = { type : 'unknown' } ;
26+ expect ( reducer ( undefined , action ) ) . toEqual ( _alert ) ;
27+ } ) ;
28+
29+ it ( 'should open the alert on ALERT_OPEN' , ( ) => {
30+ const alert = { } ;
31+ const action = { type : 'ALERT_OPEN' , payload : { alert } } ;
32+ expect ( reducer ( { open : false } , action ) . open ) . toBe ( true ) ;
33+ } ) ;
34+
35+ it ( 'should open the alert on ALERT_REPLAY' , ( ) => {
36+ const alert = { } ;
37+ const action = { type : 'ALERT_REPLAY' , payload : { alert } } ;
38+ expect ( reducer ( { open : false } , action ) . open ) . toBe ( true ) ;
39+ } ) ;
40+
41+ it ( 'should close the alert on ALERT_CLOSE' , ( ) => {
42+ const action = { type : 'ALERT_CLOSE' } ;
43+ const alert = { open : true } ;
44+ expect ( reducer ( alert , action ) . open ) . toBe ( false ) ;
45+ } ) ;
46+
47+ } ) ;
0 commit comments