diff --git a/__tests__/redux/activeUsers.test.ts b/__tests__/redux/activeUsers.test.ts new file mode 100644 index 000000000..e62f82471 --- /dev/null +++ b/__tests__/redux/activeUsers.test.ts @@ -0,0 +1,16 @@ +import { setActiveUsers } from '../../app/actions/activeUsers'; +import { IActiveUsers } from '../../app/reducers/activeUsers'; +import { mockedStore } from '../../__mocks__/mockedStore'; + +describe('test reducer', () => { + it('should return {} as initial state', async () => { + const state = mockedStore.getState().activeUsers; + expect(state).toEqual({}); + }); + it('should return modified store after action', async () => { + const activeUsers: IActiveUsers = { any: { status: 'online', statusText: 'any' } }; + mockedStore.dispatch(setActiveUsers(activeUsers)); + const state = mockedStore.getState().activeUsers; + expect(state).toEqual({ ...activeUsers }); + }); +}); diff --git a/__tests__/redux/selectedUsers.test.ts b/__tests__/redux/selectedUsers.test.ts new file mode 100644 index 000000000..fda0d0a89 --- /dev/null +++ b/__tests__/redux/selectedUsers.test.ts @@ -0,0 +1,20 @@ +import { addUser } from '../../app/actions/selectedUsers'; +import { mockedStore } from '../../__mocks__/mockedStore'; + +describe('test reducer', () => { + const initialState = { + users: [], + loading: false + }; + it('should return initial state', async () => { + const state = mockedStore.getState().selectedUsers; + expect(state).toEqual(initialState); + }); + + it('should return modified store after action', async () => { + const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; + mockedStore.dispatch(addUser(user)); + const state = mockedStore.getState().selectedUsers; + expect(state).toEqual({ loading: false, users: [user] }); + }); +});