Skip to content

Commit

Permalink
handle an edge case resetting another upload after successful (and no…
Browse files Browse the repository at this point in the history
…t reset) block-mode upload
  • Loading branch information
jebeck committed Feb 11, 2016
1 parent 9238889 commit b61cc6e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/redux/reducers/uploads.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,15 @@ export function uploadsByUser(state = {}, action) {
const uploadInProgress = _.some(
_.get(state, [userId], {}),
(upload, key) => {
const fileDataExists = _.get(upload, ['file', 'data'], null) !== null;
// because we don't want the existence of file.data on a block-mode device
// to make it appear as though an upload is in progress when we're trying
// to reset the block-mode device itself!
if (key !== deviceKey) {
return upload.choosingFile || upload.readingFile ||
_.get(upload, ['file', 'data'], null) !== null || upload.uploading;
return upload.choosingFile ||
upload.readingFile ||
(fileDataExists && !upload.completed) ||
upload.uploading;
}
else {
return false;
Expand Down
46 changes: 46 additions & 0 deletions test/browser/redux/reducers/uploads.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,52 @@ describe('uploads', () => {
expect(initialState.a1b2c3.a_cgm === result.a1b2c3.a_cgm).to.be.false;
});

it('should handle RESET_UPLOAD [resetting another when block mode successful not reset]', () => {
let initialState = {
[userId]: {[deviceKey]: {
completed: true,
data: [8,10],
history: [{start: time, finish: time}],
successful: true,
uploading: false
},
another_pump: {
choosingFile: false,
completed: true,
data: [2,4,6],
file: {data: [1,2,3], name: 'foo.ibf'},
history: [{start: time, finish: time}],
readingFile: false,
successful: true,
uploading: false
}
}};
let result = uploads.uploadsByUser(initialState, {
type: actionTypes.RESET_UPLOAD,
payload: { userId, deviceKey }
});
expect(result).to.deep.equal({
[userId]: {[deviceKey]: {
history: [{start: time, finish: time}]
},
another_pump: {
choosingFile: false,
completed: true,
data: [2,4,6],
file: {data: [1,2,3], name: 'foo.ibf'},
history: [{start: time, finish: time}],
readingFile: false,
successful: true,
uploading: false
}
}
});
// tests to be sure not *mutating* state object but rather returning new!
expect(initialState === result).to.be.false;
expect(initialState.a1b2c3 === result.a1b2c3).to.be.false;
expect(initialState.a1b2c3.a_cgm === result.a1b2c3.a_cgm).to.be.false;
});

it('should handle RESET_UPLOAD [upload failed]', () => {
let initialState = {
[userId]: {[deviceKey]: {
Expand Down

0 comments on commit b61cc6e

Please sign in to comment.