"All new business logic should have corresponding unit tests."
Description
This PR introduces unit tests for the business logic contained within public/scripts.js. The tests cover form submission handling, asynchronous file upload, UI updates based on the processing status, and error handling.
A new test file, tests/scripts.test.js, has been created following the structure of existing test files in the repository. The tests within this file mock network requests, DOM elements, and user interactions to thoroughly test the business logic in public/scripts.js.
Summary of Changes
Created tests/scripts.test.js to contain unit tests for public/scripts.js.
Added tests to simulate form submission and verify that a POST request is made to '/upload' with the correct FormData.
Added tests to simulate a successful response from the server and verify that the UI is updated accordingly.
Added tests to simulate an error response from the server and verify that the error is logged correctly.
Added tests to simulate clicking the 'Yes' button for spreadsheet processing and verify that a POST request is made to '/process-spreadsheet'.
Added tests to simulate a successful response from the spreadsheet processing request and verify that the modal is hidden and success is logged.
Added tests to simulate an error response from the spreadsheet processing request and verify that the error is logged correctly.
No changes were made to public/scripts.js as part of this PR. However, any future changes to the business logic in public/scripts.js should be accompanied by corresponding updates to the tests in tests/scripts.test.js.
PR Feedback (click)
I created this PR to address this rule:
"All new business logic should have corresponding unit tests."
Description
This PR introduces unit tests for the business logic contained within
public/scripts.js
. The tests cover form submission handling, asynchronous file upload, UI updates based on the processing status, and error handling.A new test file,
tests/scripts.test.js
, has been created following the structure of existing test files in the repository. The tests within this file mock network requests, DOM elements, and user interactions to thoroughly test the business logic inpublic/scripts.js
.Summary of Changes
tests/scripts.test.js
to contain unit tests forpublic/scripts.js
.No changes were made to
public/scripts.js
as part of this PR. However, any future changes to the business logic inpublic/scripts.js
should be accompanied by corresponding updates to the tests intests/scripts.test.js
.