Skip to content

Commit 70e30a5

Browse files
Merge pull request #3348 from OneCommunityGlobal/aaryaneil-allTimeEntriesReducer-UnitTest
Aaryaneil - Updated allTimeEntriesReducer Unit Tests
2 parents 5585060 + 171b06a commit 70e30a5

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import allTimeEntriesReducer from '../allTimeEntriesReducer'; // Adjust the path as necessary
2+
3+
describe('allTimeEntriesReducer', () => {
4+
// Test 1: Should return the initial state when no action is passed
5+
it('should return the initial state when no action is passed', () => {
6+
const initialState = null;
7+
const action = {}; // No action provided
8+
9+
const result = allTimeEntriesReducer(initialState, action);
10+
expect(result).toBeNull(); // Expect the state to be null, which is the initial state
11+
});
12+
13+
// Test 2: Should handle GET_ALL_TIME_ENTRIES action and return the payload
14+
it('should handle GET_ALL_TIME_ENTRIES action and return payload', () => {
15+
const initialState = null; // Initial state is null
16+
const action = {
17+
type: 'GET_ALL_TIME_ENTRIES',
18+
payload: [{ id: 1, entry: 'Sample entry' }] // Action payload
19+
};
20+
21+
const result = allTimeEntriesReducer(initialState, action);
22+
expect(result).toEqual(action.payload); // Expect the state to match the action's payload
23+
});
24+
25+
// Test 3: Should return the previous state when an unknown action is passed
26+
it('should return the previous state when an unknown action is passed', () => {
27+
const initialState = [{ id: 1, entry: 'Sample entry' }]; // Initial state with some data
28+
const action = {
29+
type: 'UNKNOWN_ACTION', // An unknown action
30+
payload: [{ id: 2, entry: 'Another entry' }] // Payload won't matter for unknown actions
31+
};
32+
33+
const result = allTimeEntriesReducer(initialState, action);
34+
expect(result).toEqual(initialState); // Expect the state to remain the same as the previous state
35+
});
36+
});

0 commit comments

Comments
 (0)