diff --git a/lib/redux/reducers/uploads.js b/lib/redux/reducers/uploads.js index 658ccf2433..871f78eff5 100644 --- a/lib/redux/reducers/uploads.js +++ b/lib/redux/reducers/uploads.js @@ -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; diff --git a/test/browser/redux/reducers/uploads.test.js b/test/browser/redux/reducers/uploads.test.js index e2e7ecf472..e211fec306 100644 --- a/test/browser/redux/reducers/uploads.test.js +++ b/test/browser/redux/reducers/uploads.test.js @@ -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]: {