diff --git a/client/test/unitTests/Util/Store.test.ts b/client/test/unitTests/Util/Store.test.ts new file mode 100644 index 000000000..b17c981f6 --- /dev/null +++ b/client/test/unitTests/Util/Store.test.ts @@ -0,0 +1,62 @@ +import menuReducer, { openMenu, closeMenu } from 'store/menu.slice'; +import authReducer, { setUserName } from 'store/auth.slice'; + +describe('reducers', () => { + let initialState: { + menu: { + isOpen: boolean; + }; + auth: { + userName: string | undefined; + }; + }; + + beforeEach(() => { + initialState = { + menu: { + isOpen: false, + }, + auth: { + userName: undefined, + }, + }; + }); + + describe('menu reducer', () => { + const itShouldHandleMenuActions = ( + actionCreator: () => { type: string }, + expectedValue: boolean + ) => { + const newState = menuReducer(initialState.menu, actionCreator()); + expect(newState.isOpen).toBe(expectedValue); + }; + + it('menuReducer should return the initial menu state when an unknown action type is passed with an undefined state', () => { + expect(menuReducer(undefined, { type: 'unknown' })).toEqual( + initialState.menu + ); + }); + + it('should handle openMenu', () => { + itShouldHandleMenuActions(openMenu, true); + }); + + it('should handle closeMenu', () => { + initialState.menu.isOpen = true; + itShouldHandleMenuActions(closeMenu, false); + }); + }); + + describe('auth reducer', () => { + it('authReducer should return the initial menu state when an unknown action type is passed with an undefined state', () => { + expect(authReducer(undefined, { type: 'unknown' })).toEqual( + initialState.auth + ); + }); + + it('should handle setUserName', () => { + const newState = authReducer(initialState.auth, setUserName('user1')); + expect(newState.userName).toBe('user1'); + }); + }); +});