Skip to content

Commit

Permalink
Fix typo and add test
Browse files Browse the repository at this point in the history
  • Loading branch information
henrych4 committed Oct 12, 2020
1 parent e80dd39 commit e9b5cd3
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ const reducer = (state, action) =>
break;
}
case 'ON_SUBMIT_EDIT_NEW_FILE': {
const originalIndex = draftState.fileToEdit.originalIndex;
const originalIndex = state.fileToEdit.originalIndex;
draftState.filesToUpload[originalIndex] = draftState.fileToEdit;
draftState.fileToEdit = null;
break;
Expand Down Expand Up @@ -217,7 +217,9 @@ const reducer = (state, action) =>
}
case 'SET_FILE_TO_EDIT': {
draftState.fileToEdit = formatFileForEditing(
[...state.files, ...state.selectedFiles].find(file => file.id.toString() === action.fileId.toString())
[...state.files, ...state.selectedFiles].find(
file => file.id.toString() === action.fileId.toString()
)
);
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2250,4 +2250,69 @@ describe('UPLOAD | containers | ModalStepper | reducer', () => {
expect(reducer(state, action)).toEqual(expected);
});
});

describe('ON_SUBMIT_EDIT_NEW_FILE', () => {
it('should update file info after edit', () => {
const action = {
type: 'ON_SUBMIT_EDIT_NEW_FILE',
};
const state = {
currentStep: 'edit-new',
fileToEdit: {
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: 'test1 alternativeText',
caption: 'test1 caption',
name: 'test1 name',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
filesToUpload: [
{
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: '',
caption: '',
name: 'test1',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
],
};
const expected = {
currentStep: 'edit-new',
fileToEdit: null,
filesToUpload: [
{
abortController: new AbortController(),
file: { name: 'test1', ok: true },
fileInfo: {
alternativeText: 'test1 alternativeText',
caption: 'test1 caption',
name: 'test1 name',
},
originalName: 'test1',
hasError: false,
errorMessage: null,
isUploading: false,
originalIndex: 0,
tempId: null,
},
],
};
expect(reducer(state, action)).toEqual(expected);
});
});
});

0 comments on commit e9b5cd3

Please sign in to comment.