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

Fixing bug: No Rename Check When Rename Input Is Empty #7124

Merged
merged 10 commits into from
Jul 12, 2024
Merged
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
- Ensure annotation rendering is updated in real-time for Jupyter notebooks (#7084)
- Fix MathJax rendering in annotations for Jupyter notebooks (#7084)
- Fix MathJax rendering of released overall comments (#7084)
- Fix rename confirmation check triggering even upon no rename input (#7124)

### 🔧 Internal changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,26 @@ class SubmissionFileUploadModal extends React.Component {
if (this.state.newFiles.length === 1) {
const newFilename = this.state.renameTo;
const originalFilename = this.state.newFiles[0].name; // Assuming only one file is uploaded
const originalExtension = originalFilename.split(".").pop();
const newExtension = newFilename.split(".").pop();
// Check if newFilename is not blank
if (newFilename.trim() !== "") {
const originalExtension = originalFilename.split(".").pop();
const newExtension = newFilename.split(".").pop();

if (originalExtension !== newExtension) {
const confirmChange = window.confirm(I18n.t("modals.file_upload.rename_warning"));
if (!confirmChange) {
// Prevent form submission if the user cancels the operation
return;
if (originalExtension !== newExtension) {
const confirmChange = window.confirm(I18n.t("modals.file_upload.rename_warning"));
if (!confirmChange) {
// Prevent form submission if the user cancels the operation
return;
}
}
}
}
this.props.onSubmit(this.state.newFiles, undefined, this.state.unzip, this.state.renameTo);
this.props.onSubmit(
this.state.newFiles,
undefined,
this.state.unzip,
this.state.renameTo.trim()
);
};

handleFileUpload = event => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,26 @@ describe("For the SubmissionFileUploadModal", () => {
"file2.txt"
);
});

it("should call onSubmit prop with correct arguments when rename input is left blank", () => {
david-yz-liu marked this conversation as resolved.
Show resolved Hide resolved
// Mock setState method
wrapper.setState({
newFiles: [{name: "file.py"}],
renameTo: "",
});
wrapper.instance().onSubmit({preventDefault: jest.fn()});
expect(mockOnSubmit).toHaveBeenCalledWith([{name: "file.py"}], undefined, false, "");
});

it("should call onSubmit prop with correct arguments when rename input consists only of whitespace", () => {
// Mock setState method
wrapper.setState({
newFiles: [{name: "file.py"}],
renameTo: " ",
});
wrapper.instance().onSubmit({preventDefault: jest.fn()});
expect(mockOnSubmit).toHaveBeenCalledWith([{name: "file.py"}], undefined, false, "");
});
});

describe("The progress bar", () => {
Expand Down