1+ import { projectByIdReducer } from '../projectByIdReducer' ;
2+ import { GET_PROJECT_BY_ID } from '../../constants/project' ;
3+
4+ describe ( 'projectByIdReducer' , ( ) => {
5+
6+ it ( 'should return the initial state if no action is provided' , ( ) => {
7+ const initialState = null ;
8+ const action = { type : 'UNKNOWN_ACTION' } ;
9+ const state = projectByIdReducer ( undefined , action ) ;
10+
11+ expect ( state ) . toBe ( initialState ) ;
12+ } ) ;
13+
14+ it ( 'should handle GET_PROJECT_BY_ID action' , ( ) => {
15+ const projectData = {
16+ id : 1 ,
17+ name : 'Test Project' ,
18+ description : 'This is a test project'
19+ } ;
20+
21+ const action = {
22+ type : GET_PROJECT_BY_ID ,
23+ payload : projectData
24+ } ;
25+
26+ const state = projectByIdReducer ( null , action ) ;
27+
28+ expect ( state ) . toEqual ( projectData ) ;
29+ } ) ;
30+
31+ it ( 'should update the project when a valid GET_PROJECT_BY_ID action is dispatched' , ( ) => {
32+ const initialState = { id : 1 , name : 'Initial Project' , description : 'Old description' } ;
33+
34+ const updatedProject = {
35+ id : 1 ,
36+ name : 'Updated Project' ,
37+ description : 'New project description'
38+ } ;
39+
40+ const action = {
41+ type : GET_PROJECT_BY_ID ,
42+ payload : updatedProject
43+ } ;
44+
45+ const state = projectByIdReducer ( initialState , action ) ;
46+
47+ expect ( state ) . toEqual ( updatedProject ) ;
48+ } ) ;
49+
50+ it ( 'should return the current state when an unknown action type is dispatched' , ( ) => {
51+ const currentState = {
52+ id : 1 ,
53+ name : 'Test Project' ,
54+ description : 'Current project description'
55+ } ;
56+
57+ const action = {
58+ type : 'UNKNOWN_ACTION' ,
59+ } ;
60+
61+ const state = projectByIdReducer ( currentState , action ) ;
62+
63+ expect ( state ) . toEqual ( currentState ) ;
64+ } ) ;
65+
66+ } ) ;
0 commit comments