Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forms 11746 allow attaching same file #1201

Merged
merged 3 commits into from
Apr 29, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions ui.frontend/src/view/FormFileInputWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ class FormFileInputWidget {
this.showInvalidMessage(inValidMimeTypefileNames.substring(0, inValidMimeTypefileNames.lastIndexOf(',')), this.invalidFeature.MIMETYPE);
}
}
this.widget.value = null;
}
}

Expand Down
19 changes: 19 additions & 0 deletions ui.tests/test-module/specs/fileinput/fileinput.runtime.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,25 @@ describe("Form with File Input - Basic Tests", () => {
checkHTML(id, field.getModel().getState())
});
})
it(" after attaching the file widget value is reset to allow duplicate file ", () => {
const sampleFileName = 'sample2.txt', fileInput = "input[name='fileinput1']";
cy.get(fileInput).should('have.value', "");
cy.get(fileInput).attachFile(sampleFileName).then(() => {
cy.get(".cmp-adaptiveform-fileinput__filename").contains(sampleFileName);
cy.get(fileInput).should(($element) => {
const actualValue = $element.val();
expect(actualValue.includes("")).to.be.true;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are checking for empty value inside actual value ? Is this relevant

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its because we are clearing the value once the file is attached so that duplicate file can be attached and also I have added the test case to attach the duplicate file.

})
});
// attaching the same file again to check duplicate file attachment
cy.get(fileInput).attachFile(sampleFileName).then(() => {
cy.get(".cmp-adaptiveform-fileinput__filename").should('have.length', 2);
cy.get(fileInput).should(($element) => {
const actualValue = $element.val();
expect(actualValue.includes("")).to.be.true;
})
});
});

it(" model's changes are reflected in the html ", () => {
Object.entries(formContainer._fields).forEach(([id, field]) => {
Expand Down