verdnatura-chat/__tests__/redux/selectedUsers.test.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-12-22 12:27:40 +00:00
import { addUser, reset, setLoading, removeUser } from '../../app/actions/selectedUsers';
import { mockedStore } from '../../__mocks__/mockedStore';
2021-12-22 12:27:40 +00:00
describe('test selectedUsers reducer', () => {
const initialState = {
users: [],
loading: false
};
2021-12-22 12:27:40 +00:00
it('should return initial state', async () => {
const state = mockedStore.getState().selectedUsers;
expect(state).toEqual(initialState);
});
2021-12-22 12:27:40 +00:00
it('should return modified store after addUser', async () => {
const user = { _id: 'xxx', name: 'xxx', fname: 'xxx' };
mockedStore.dispatch(addUser(user));
2021-12-22 12:27:40 +00:00
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;
2021-12-22 12:27:40 +00:00
expect(state).toEqual(initialState);
});
it('should return loading after call action', async () => {
mockedStore.dispatch(setLoading(true));
const state = mockedStore.getState().selectedUsers.loading;
expect(state).toEqual(true);
});
});