File tree Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Expand file tree Collapse file tree 2 files changed +54
-0
lines changed Original file line number Diff line number Diff line change
1
+ import header , { setCustom } from '../header' ;
2
+
3
+ describe ( 'header redux module' , ( ) => {
4
+ describe ( 'reducer' , ( ) => {
5
+ const initialState = {
6
+ custom : false ,
7
+ userLogo : null ,
8
+ } ;
9
+ it ( 'should have initialState' , ( ) => {
10
+ const state = header ( undefined , { } ) ;
11
+ expect ( state ) . toEqual ( initialState ) ;
12
+ } ) ;
13
+ it ( 'handles SET_CUSTOM action' , ( ) => {
14
+ let state = header ( initialState , setCustom ( true ) ) ;
15
+ expect ( state . custom ) . toBe ( true ) ;
16
+ state = header ( initialState , setCustom ( false ) ) ;
17
+ expect ( state . custom ) . toBe ( false ) ;
18
+ } ) ;
19
+ } ) ;
20
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { createReducer , updateKey } from '../lib/utils' ;
2
+ import { createStandardAction } from 'typesafe-actions' ;
3
+
4
+ const SET_CUSTOM = 'header/SET_CUSTOM' ;
5
+
6
+ export const setCustom = createStandardAction ( SET_CUSTOM ) < boolean > ( ) ;
7
+
8
+ type UserLogo = {
9
+ title : string ;
10
+ logo_image : string ;
11
+ } ;
12
+
13
+ interface HeaderState {
14
+ custom : boolean ;
15
+ userLogo : null | UserLogo ;
16
+ }
17
+
18
+ type SetCustom = ReturnType < typeof setCustom > ;
19
+
20
+ const initialState = {
21
+ custom : false ,
22
+ userLogo : null ,
23
+ } ;
24
+
25
+ const header = createReducer (
26
+ {
27
+ [ SET_CUSTOM ] : ( state , action : SetCustom ) => {
28
+ return updateKey ( state , 'custom' , action . payload ) ;
29
+ } ,
30
+ } ,
31
+ initialState ,
32
+ ) ;
33
+
34
+ export default header ;
You can’t perform that action at this time.
0 commit comments