close
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/state/features.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import reducer, {
mostSimilar,
leastSimilar,
} from './features';
import { ADD as ERROR_ADD } from './errors';

const mockStore = configureMockStore([thunk]);

Expand Down Expand Up @@ -71,6 +72,31 @@ describe('features/actions', () => {
]);
});
});

it('error', () => {
const blobIdA = 1;
const blobIdB = 2;
const store = mockStore({
features: {
...initialState,
},
});

const errText = 'some error';
fetch.mockReject(errText);

return store.dispatch(load(blobIdA, blobIdB)).then(() => {
expect(store.getActions()).toEqual([
{
type: LOAD,
},
{
type: ERROR_ADD,
error: errText,
},
]);
});
});
});
});

Expand Down
19 changes: 12 additions & 7 deletions src/state/filePairs.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,17 @@ export const selectPair = (expId, id) => dispatch => {

export const loadAnnotations = (expId, id) => dispatch => {
dispatch({ type: LOAD_ANNOTATIONS });
return api.getFilePairAnnotations(expId, id).then(res =>
dispatch({
type: SET_ANNOTATIONS,
data: res,
})
);
return api
.getFilePairAnnotations(expId, id)
.then(res =>
dispatch({
type: SET_ANNOTATIONS,
data: res,
})
)
.catch(e => {
dispatch(addErrors(e));
});
};

/* Selectors */
Expand Down Expand Up @@ -180,7 +185,7 @@ export const middleware = store => next => action => {
.then(() => next(loadAnnotations(expIdParam, +payload.params.pair)))
.then(() => {
const pair = getCurrentFilePair(store.getState());
return next(featuresLoad(pair.leftBlobId, pair.rightBlobId));
return pair && next(featuresLoad(pair.leftBlobId, pair.rightBlobId));
});
default:
return result;
Expand Down
22 changes: 22 additions & 0 deletions src/state/filePairs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,28 @@ describe('filePairs/actions', () => {
]);
});
});

it('error', () => {
const store = mockStore({
filePairs: {
...initialState,
pairs: { 1: 'pair' },
},
});

const errText = 'some error';
fetch.mockReject(errText);

return store.dispatch(loadAnnotations(1, 1)).then(() => {
expect(store.getActions()).toEqual([
{ type: LOAD_ANNOTATIONS },
{
type: ERROR_ADD,
error: errText,
},
]);
});
});
});
});

Expand Down