Skip to content

Commit

Permalink
chore(downloadLimit): client side validation of download limit field
Browse files Browse the repository at this point in the history
  • Loading branch information
benjohns1 committed Feb 20, 2024
1 parent b95b67e commit f5d8e5c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion app/web/templates/files.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h4 class="form_header">Upload File</h4>
{{ if featureFlagIsOn .ctx "DownloadLimit" }}
<div>
<label for="download_limit" hidden>Download Limit</label>
<input id="download_limit" type="number" name="download_limit" placeholder="Download Limit" data-test="download_limit"/>
<input id="download_limit" type="number" name="download_limit" placeholder="Download Limit" data-test="download_limit" min="1"/>
</div>
{{end}}
<input id="submit_file_upload" type="submit" value="Upload" data-test="upload"/>
Expand Down Expand Up @@ -95,6 +95,7 @@ <h4 class="form_header">Upload File</h4>
document.getElementById("file"),
document.getElementById("expire_in_amount"),
document.getElementById("expiration_time"),
document.getElementById("download_limit"),
]
const onInput = () => {
let valid = true;
Expand Down
5 changes: 5 additions & 0 deletions test/cypress/features/downloadLimit.feature
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,8 @@ Scenario: The file is removed after downloading it the maximum number of times
When I download the file 3 times
Then I can no longer download the file
And it no longer shows up in the file list

Scenario: Cannot upload a file that has a negative download limit
Given I have selected the file "files/download-limit.txt" to upload
When I set its download limit to -1
Then I should not be able to upload the file
15 changes: 15 additions & 0 deletions test/cypress/steps/downloadLimit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,18 @@ Then("I can no longer download the file", () => {
Then("it no longer shows up in the file list", () => {
fileNotInList(state.fileLink);
});

Given("I have selected the file {string} to upload", (name: string) => {
visitFileUploadPage();
state.fileToUpload = `features/${name}`;
deleteDownloadsFolder();
getFileBrowser().selectFile(state.fileToUpload);
});

When("I set its download limit to {int}", (limit: number) => {
getDownloadLimitField().type(limit.toString());
});

Then("I should not be able to upload the file", () => {
getUploadButton().should('be.disabled');
});

0 comments on commit f5d8e5c

Please sign in to comment.