File size: 1,645 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import produce from 'immer';
import appReducer from '../reducer';
import { loadRepos, reposLoaded, repoLoadingError } from '../actions';
/* eslint-disable default-case, no-param-reassign */
describe('appReducer', () => {
let state;
beforeEach(() => {
state = {
loading: false,
error: false,
currentUser: false,
userData: {
repositories: false,
},
};
});
it('should return the initial state', () => {
const expectedResult = state;
expect(appReducer(undefined, {})).toEqual(expectedResult);
});
it('should handle the loadRepos action correctly', () => {
const expectedResult = produce(state, draft => {
draft.loading = true;
draft.error = false;
draft.userData.repositories = false;
});
expect(appReducer(state, loadRepos())).toEqual(expectedResult);
});
it('should handle the reposLoaded action correctly', () => {
const fixture = [
{
name: 'My Repo',
},
];
const username = 'test';
const expectedResult = produce(state, draft => {
draft.userData.repositories = fixture;
draft.loading = false;
draft.currentUser = username;
});
expect(appReducer(state, reposLoaded(fixture, username))).toEqual(
expectedResult,
);
});
it('should handle the repoLoadingError action correctly', () => {
const fixture = {
msg: 'Not found',
};
const expectedResult = produce(state, draft => {
draft.error = fixture;
draft.loading = false;
});
expect(appReducer(state, repoLoadingError(fixture))).toEqual(
expectedResult,
);
});
});
|