test: add more selectedUsers tests

This commit is contained in:
GleidsonDaniel 2021-12-22 09:27:40 -03:00
parent b80c0635d6
commit b5bda757bc
1 changed files with 26 additions and 5 deletions

View File

@ -1,20 +1,41 @@
import { addUser } from '../../app/actions/selectedUsers'; import { addUser, reset, setLoading, removeUser } from '../../app/actions/selectedUsers';
import { mockedStore } from '../../__mocks__/mockedStore'; import { mockedStore } from '../../__mocks__/mockedStore';
describe('test reducer', () => { describe('test selectedUsers reducer', () => {
const initialState = { const initialState = {
users: [], users: [],
loading: false loading: false
}; };
it('should return initial state', async () => { it('should return initial state', async () => {
const state = mockedStore.getState().selectedUsers; const state = mockedStore.getState().selectedUsers;
expect(state).toEqual(initialState); expect(state).toEqual(initialState);
}); });
it('should return modified store after action', async () => { it('should return modified store after addUser', async () => {
const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' }; const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' };
mockedStore.dispatch(addUser(user)); mockedStore.dispatch(addUser(user));
const state = mockedStore.getState().selectedUsers.users;
expect(state).toEqual([user]);
});
it('should return empty store after remove user', async () => {
const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' };
mockedStore.dispatch(removeUser(user));
const state = mockedStore.getState().selectedUsers.users;
expect(state).toEqual([]);
});
it('should return initialState after reset', async () => {
mockedStore.dispatch(reset());
const state = mockedStore.getState().selectedUsers; const state = mockedStore.getState().selectedUsers;
expect(state).toEqual({ loading: false, users: [user] }); expect(state).toEqual(initialState);
});
it('should return loading after call action', async () => {
const user = { _id: 'user.id', name: 'user.username', fname: 'user.name' };
mockedStore.dispatch(setLoading(true));
const state = mockedStore.getState().selectedUsers.loading;
expect(state).toEqual(true);
}); });
}); });