-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2913 from OneCommunityGlobal/vijay-anand-unit-tes…
…t-weekly-summaries-reducer Vijay Anand - Add unit tests for weeklySummariesReducer
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { weeklySummariesReducer } from '../weeklySummariesReducer'; | ||
import * as actions from '../../constants/weeklySummaries'; | ||
|
||
describe('weeklySummariesReducer', () => { | ||
const initialState = { | ||
summaries: {}, | ||
loading: false, | ||
fetchError: null, | ||
}; | ||
|
||
it('should return the initial state when no action is provided', () => { | ||
expect(weeklySummariesReducer(undefined, {})).toEqual(initialState); | ||
}); | ||
|
||
it('should handle FETCH_WEEKLY_SUMMARIES_BEGIN', () => { | ||
const action = { type: actions.FETCH_WEEKLY_SUMMARIES_BEGIN }; | ||
const expectedState = { | ||
...initialState, | ||
loading: true, | ||
fetchError: null, | ||
}; | ||
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState); | ||
}); | ||
|
||
it('should handle FETCH_WEEKLY_SUMMARIES_SUCCESS', () => { | ||
const mockData = { | ||
weeklySummariesData: { | ||
week1: { summary: 'Test Summary 1' }, | ||
week2: { summary: 'Test Summary 2' }, | ||
}, | ||
}; | ||
const action = { | ||
type: actions.FETCH_WEEKLY_SUMMARIES_SUCCESS, | ||
payload: mockData, | ||
}; | ||
const expectedState = { | ||
...initialState, | ||
loading: false, | ||
summaries: mockData.weeklySummariesData, | ||
}; | ||
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState); | ||
}); | ||
|
||
it('should handle FETCH_WEEKLY_SUMMARIES_ERROR', () => { | ||
const mockError = new Error('Failed to fetch data'); | ||
const action = { | ||
type: actions.FETCH_WEEKLY_SUMMARIES_ERROR, | ||
payload: { error: mockError }, | ||
}; | ||
const expectedState = { | ||
...initialState, | ||
loading: false, | ||
fetchError: mockError, | ||
}; | ||
expect(weeklySummariesReducer(initialState, action)).toEqual(expectedState); | ||
}); | ||
}); |