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

Fix file input bug #93

Merged
merged 1 commit into from
Oct 10, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### 🐛 Bug fixes

- Fixed a bug where the `Download JSON` button would not download the JSON currently inside the input box.
- Made sure file input would reset when file input dialog was closed.

### 📚 Documentation and demo website changes

Expand Down
5 changes: 4 additions & 1 deletion demo/src/MemoryModelsUserInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ function MemoryModelsFileInput(props: MemoryModelsFileInputPropTypes) {
const [open, setOpen] = useState(false);

const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const handleClose = () => {
setOpen(false);
setUploadedFileString("");
};

const onChange = (event) => {
try {
Expand Down
32 changes: 32 additions & 0 deletions demo/src/__tests__/MemoryModelsUserInput.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,38 @@ describe("MemoryModelsUserInput", () => {
expect(setTextDataMock).toHaveBeenCalledWith(fileString);
});
});

it("closing the dialog resets the file input", async () => {
const reapplyBtn = screen.getByTestId(
"file-input-reapply-button"
);

await waitFor(() => {
// wait until the button is enabled
expect(reapplyBtn).toHaveProperty("disabled", false);
// click off the dialog window
fireEvent.keyDown(
screen.queryByTestId("file-input-dialog"),
{
key: "Escape",
code: "Escape",
keyCode: 27,
charCode: 27,
}
);
});

await waitFor(() => {
// // expect dialog to no longer be there
expect(
screen.queryByTestId("file-input-dialog")
).toBeNull();

// // re-open the modal, reapplyBtn should be disabled
fireEvent.click(screen.getByText("Upload JSON File"));
expect(reapplyBtn).toHaveProperty("disabled", true);
});
});
});
});

Expand Down
Loading