Skip to content

Commit

Permalink
fix(file-uploader): update initial state of existing files
Browse files Browse the repository at this point in the history
Existing files were receiving 'undefined' as state values as the name of
the state field used to assign the state value was incorrect
(initialState). This commit fix it
  • Loading branch information
felipebritor committed Sep 17, 2023
1 parent 07f4e58 commit b986494
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/CvFileUploader/CvFileUploader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ function addFiles(files) {
const newFile = createInternalFile(internalFile?.file || file);
if (internalFile) {
internalFile.state = newFile.initialState;
internalFile.state = newFile.state;
internalFile.invalidMessageTitle = newFile.invalidMessageTitle;
internalFile.invalidMessage = newFile.invalidMessage;
} else {
Expand Down
26 changes: 26 additions & 0 deletions src/components/CvFileUploader/__tests__/CvFileUploader.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,32 @@ describe('CvFileUploader', () => {
expect(emitResult[0][0].state).toBe(STATES.NONE);
});

it(`sets "${STATES.UPLOADING}" state to files when initialStateUploading is set and uploaded file already exists`, async () => {
const dummyFile = new File([''], 'dummy-file.jpeg', {
type: 'image/jpeg',
});
const dummyId = 'dummy-id';
const { container, emitted, rerender } = render(CvFileUploader, {
props: {
initialStateUploading: true,
id: dummyId,
},
});

const fileInput = container.querySelector(`#${dummyId}`);
await fireEvent.change(fileInput, { target: { files: [dummyFile] } });

await rerender({ initialStateUploading: false });
await fireEvent.change(fileInput, { target: { files: [dummyFile] } });

await rerender({ initialStateUploading: true });
await fireEvent.change(fileInput, { target: { files: [dummyFile] } });

expect(emitted('update:modelValue').at(2)[0][0].state).toBe(
STATES.UPLOADING
);
});

describe('Drop target label', () => {
it.each(inputKinds)(
'renders drop target label when dropTargetLabel is passed (kind: %s)',
Expand Down

0 comments on commit b986494

Please sign in to comment.