Skip to content

Commit 0106e91

Browse files
committed
add test cases for ungit-config and path reducers
1 parent 3bd318e commit 0106e91

File tree

2 files changed

+105
-0
lines changed

2 files changed

+105
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import * as types from 'constants/action-types';
2+
3+
import path from 'reducers/path';
4+
5+
describe('path.js reducers', () => {
6+
let initialState;
7+
const DECREASE_PENDING_ACTIONS = [
8+
types.RECEIVE_UNGIT_CONFIG,
9+
types.RECEIVE_USER_CONFIG,
10+
types.RECEIVE_GIT_VERSION,
11+
types.RECEIVE_LATEST_VERSION
12+
];
13+
14+
beforeEach(() => {
15+
initialState = {
16+
pending: null,
17+
errMessage: []
18+
};
19+
});
20+
21+
it('should return original state if action doesn\'t match any case' , function() {
22+
const state = path(initialState, { type: 'no-op' });
23+
expect(state.pending).toEqual(initialState.pending);
24+
expect(state.errMessage.length).toEqual(initialState.errMessage.length);
25+
});
26+
27+
describe('when PATH_PAGE_PENDING action dispatch', () => {
28+
it('pending state should be calculated correctly', function() {
29+
const action1 = { type: types.PATH_PAGE_PENDING, payload: 1 };
30+
const action2 = { type: types.PATH_PAGE_PENDING, payload: 3 };
31+
32+
const state1 = path(initialState, action1);
33+
expect(state1.pending).toEqual(initialState.pending + action1.payload);
34+
35+
const state2 = path(state1, action2);
36+
expect(state2.pending).toEqual(state1.pending + action2.payload);
37+
});
38+
});
39+
40+
DECREASE_PENDING_ACTIONS.forEach(actionName => {
41+
describe(`when ${actionName} action dispatch`, () => {
42+
beforeEach(() => {
43+
initialState = {
44+
pending: 1,
45+
errMessage: []
46+
};
47+
});
48+
it('pending state should be minused one', () => {
49+
const action = { type: actionName };
50+
51+
const state = path(initialState, action);
52+
expect(state.pending).toEqual(initialState.pending - 1);
53+
});
54+
});
55+
});
56+
57+
describe('when PATH_PAGE_API_ERR action dispatch', () => {
58+
it('pending state should be minused one', function() {
59+
const action = { type: types.PATH_PAGE_API_ERR, payload: 'error message' };
60+
61+
const state = path(initialState, action);
62+
expect(state.pending).toEqual(initialState.pending - 1);
63+
});
64+
65+
it('errMessage state should correct content', function() {
66+
const action = { type: types.PATH_PAGE_API_ERR, payload: 'error message' };
67+
68+
const state = path(initialState, action);
69+
expect(state.errMessage.length).toEqual(initialState.errMessage.length + 1);
70+
expect(state.errMessage[0]).toEqual(action.payload);
71+
});
72+
});
73+
});
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as types from 'constants/action-types';
2+
3+
import ungitConfig from 'reducers/ungit-config';
4+
5+
describe('ungit-config.js reducers', () => {
6+
let initialState;
7+
8+
it('should return original state if action doesn\'t match any case' , function() {
9+
const state = ungitConfig(initialState, { type: 'no-op' });
10+
expect(state).toEqual({});
11+
});
12+
13+
describe('when RECEIVE_UNGIT_CONFIG action dispatch', () => {
14+
it('state should have ungit configuration correctly', function() {
15+
// TODO: consider to use sinon to mock data and make mock data reuseable and meaningful
16+
const action = { type: types.RECEIVE_UNGIT_CONFIG, payload: {
17+
config: {
18+
allowCheckoutNodes: false,
19+
autoStashAndPop: true
20+
},
21+
platform: 'darwin',
22+
userHash: '69d23970c3b39b2a8d68a70c30cab99a2bf46e74',
23+
version: 'dev-1.1.16-071f30a',
24+
pluginApiVersion: '0.2.0'
25+
} };
26+
27+
const state = ungitConfig(initialState, action);
28+
expect(JSON.stringify(state)).toEqual(JSON.stringify(action.payload));
29+
});
30+
});
31+
32+
});

0 commit comments

Comments
 (0)