Skip to content

Commit

Permalink
Fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yoonieaj committed Oct 9, 2024
1 parent 4ba4dfd commit f8dbbdc
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
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

0 comments on commit f8dbbdc

Please sign in to comment.