1+ import { teamByIdReducer } from '../teamByIdReducer' ;
2+ import { GET_TEAM_BY_ID } from '../../constants/team' ;
3+
4+
5+ describe ( 'teamByIdReducer' , ( ) => {
6+ it ( 'should return the initial state when state is undefined' , ( ) => {
7+ const initialState = null ;
8+ const action = { } ;
9+ expect ( teamByIdReducer ( undefined , action ) ) . toBe ( initialState ) ;
10+ } ) ;
11+
12+ it ( 'should return the current state when action type does not match' , ( ) => {
13+ const currentState = { id : 1 , name : 'Team A' } ;
14+ const action = { type : 'UNKNOWN_ACTION' , payload : { id : 2 , name : 'Team B' } } ;
15+ expect ( teamByIdReducer ( currentState , action ) ) . toBe ( currentState ) ;
16+ } ) ;
17+
18+ it ( 'should return the new state when action type is GET_TEAM_BY_ID' , ( ) => {
19+ const action = { type : GET_TEAM_BY_ID , payload : { id : 2 , name : 'Team B' } } ;
20+ expect ( teamByIdReducer ( null , action ) ) . toEqual ( action . payload ) ;
21+ } ) ;
22+
23+ it ( 'should update the state with the new team when action type is GET_TEAM_BY_ID' , ( ) => {
24+ const currentState = { id : 1 , name : 'Team A' } ;
25+ const action = { type : GET_TEAM_BY_ID , payload : { id : 2 , name : 'Team B' } } ;
26+ expect ( teamByIdReducer ( currentState , action ) ) . toEqual ( action . payload ) ;
27+ } ) ;
28+ } ) ;
0 commit comments