From 5ea62b0f9627754023e714ca6a1c6116fdfaa417 Mon Sep 17 00:00:00 2001 From: yoonie-jang Date: Wed, 2 Oct 2024 19:43:12 -0400 Subject: [PATCH] Update tests for modal --- demo/src/MemoryModelsUserInput.tsx | 6 ++++- .../__tests__/MemoryModelsUserInput.spec.tsx | 24 +++++++++++++++---- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/demo/src/MemoryModelsUserInput.tsx b/demo/src/MemoryModelsUserInput.tsx index 2c494d76..6f6dc268 100644 --- a/demo/src/MemoryModelsUserInput.tsx +++ b/demo/src/MemoryModelsUserInput.tsx @@ -81,7 +81,11 @@ function MemoryModelsFileInput(props: MemoryModelsFileInputPropTypes) { - + { @@ -127,7 +133,16 @@ describe("MemoryModelsUserInput", () => { jest.restoreAllMocks(); }); + it("does not render the modal when the page first loads", () => { + const modal = screen.queryByTestId("file-input-modal"); + expect(modal).toBeNull(); + + const input: HTMLInputElement = screen.queryByTestId("file-input"); + expect(input).toBeNull(); + }); + it("renders an enabled input and disabled reapply button", () => { + fireEvent.click(screen.getByText("File Input")); const input: HTMLInputElement = screen.getByTestId("file-input"); expect(input).toHaveProperty("disabled", false); @@ -149,6 +164,7 @@ describe("MemoryModelsUserInput", () => { type: "application/json", } ); + fireEvent.click(screen.getByText("File Input")); const input: HTMLInputElement = screen.getByTestId("file-input"); await waitFor(() => { // this needs to be awaited because of fileReader.onload being async @@ -167,6 +183,7 @@ describe("MemoryModelsUserInput", () => { let input: HTMLInputElement; beforeEach(async () => { + fireEvent.click(screen.getByText("File Input")); const file = new File([fileString], "test.json", { type: "application/json", }); @@ -198,10 +215,7 @@ describe("MemoryModelsUserInput", () => { // once from reapplyBtn onChange, once from MemoryModelsTextInput handleTextFieldChange // if put within the same waitFor block as fireEvent.click(reapplyBtn), this test always passes // even with the wrong expect - expect(setTextDataMock).toHaveBeenNthCalledWith( - 2, - fileString - ); + expect(setTextDataMock).toHaveBeenCalledWith(fileString); }); }); });