Skip to content

Commit 4227a12

Browse files
authored
Merge pull request #205 from smacker/fe_test_error_path
Add tests for error path and fix bug
2 parents b0b8fd1 + 063d0f9 commit 4227a12

File tree

3 files changed

+60
-7
lines changed

3 files changed

+60
-7
lines changed

src/state/features.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import reducer, {
88
mostSimilar,
99
leastSimilar,
1010
} from './features';
11+
import { ADD as ERROR_ADD } from './errors';
1112

1213
const mockStore = configureMockStore([thunk]);
1314

@@ -71,6 +72,31 @@ describe('features/actions', () => {
7172
]);
7273
});
7374
});
75+
76+
it('error', () => {
77+
const blobIdA = 1;
78+
const blobIdB = 2;
79+
const store = mockStore({
80+
features: {
81+
...initialState,
82+
},
83+
});
84+
85+
const errText = 'some error';
86+
fetch.mockReject(errText);
87+
88+
return store.dispatch(load(blobIdA, blobIdB)).then(() => {
89+
expect(store.getActions()).toEqual([
90+
{
91+
type: LOAD,
92+
},
93+
{
94+
type: ERROR_ADD,
95+
error: errText,
96+
},
97+
]);
98+
});
99+
});
74100
});
75101
});
76102

src/state/filePairs.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,17 @@ export const selectPair = (expId, id) => dispatch => {
120120

121121
export const loadAnnotations = (expId, id) => dispatch => {
122122
dispatch({ type: LOAD_ANNOTATIONS });
123-
return api.getFilePairAnnotations(expId, id).then(res =>
124-
dispatch({
125-
type: SET_ANNOTATIONS,
126-
data: res,
127-
})
128-
);
123+
return api
124+
.getFilePairAnnotations(expId, id)
125+
.then(res =>
126+
dispatch({
127+
type: SET_ANNOTATIONS,
128+
data: res,
129+
})
130+
)
131+
.catch(e => {
132+
dispatch(addErrors(e));
133+
});
129134
};
130135

131136
/* Selectors */
@@ -180,7 +185,7 @@ export const middleware = store => next => action => {
180185
.then(() => next(loadAnnotations(expIdParam, +payload.params.pair)))
181186
.then(() => {
182187
const pair = getCurrentFilePair(store.getState());
183-
return next(featuresLoad(pair.leftBlobId, pair.rightBlobId));
188+
return pair && next(featuresLoad(pair.leftBlobId, pair.rightBlobId));
184189
});
185190
default:
186191
return result;

src/state/filePairs.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ describe('filePairs/actions', () => {
162162
]);
163163
});
164164
});
165+
166+
it('error', () => {
167+
const store = mockStore({
168+
filePairs: {
169+
...initialState,
170+
pairs: { 1: 'pair' },
171+
},
172+
});
173+
174+
const errText = 'some error';
175+
fetch.mockReject(errText);
176+
177+
return store.dispatch(loadAnnotations(1, 1)).then(() => {
178+
expect(store.getActions()).toEqual([
179+
{ type: LOAD_ANNOTATIONS },
180+
{
181+
type: ERROR_ADD,
182+
error: errText,
183+
},
184+
]);
185+
});
186+
});
165187
});
166188
});
167189

0 commit comments

Comments
 (0)