From f8dbbdc3eff328711f7b9f39e8db70dab58dc100 Mon Sep 17 00:00:00 2001 From: yoonie-jang Date: Tue, 8 Oct 2024 22:31:40 -0400 Subject: [PATCH] Fix bug --- CHANGELOG.md | 1 + demo/src/MemoryModelsUserInput.tsx | 5 ++- .../__tests__/MemoryModelsUserInput.spec.tsx | 32 +++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 06de1939..68dc9454 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/demo/src/MemoryModelsUserInput.tsx b/demo/src/MemoryModelsUserInput.tsx index d6209fc4..7e19f4b2 100644 --- a/demo/src/MemoryModelsUserInput.tsx +++ b/demo/src/MemoryModelsUserInput.tsx @@ -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 { diff --git a/demo/src/__tests__/MemoryModelsUserInput.spec.tsx b/demo/src/__tests__/MemoryModelsUserInput.spec.tsx index 1e4751d2..8a130484 100644 --- a/demo/src/__tests__/MemoryModelsUserInput.spec.tsx +++ b/demo/src/__tests__/MemoryModelsUserInput.spec.tsx @@ -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); + }); + }); }); });