-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9412f6d
commit 5e980c8
Showing
2 changed files
with
62 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,63 @@ | ||
jest.mock( | ||
"../sample/automation/automation.json", | ||
() => ({ sample: "automation" }), | ||
{ virtual: true } | ||
); | ||
jest.mock("../sample/automation/config.json", () => ({ config: "config" }), { | ||
virtual: true, | ||
}); | ||
|
||
import React from "react"; | ||
import { fireEvent, render, screen, waitFor } from "@testing-library/react"; | ||
import MemoryModelsSample from "../MemoryModelsSample"; | ||
describe("MemoryModelsSample", () => { | ||
// submit button by default resets the form https://stackoverflow.com/a/62404526 | ||
const onSubmitMock = jest.fn(() => {}); | ||
const setTextDataMock = jest.fn(); | ||
let nextState; | ||
let setConfigDataMock; | ||
|
||
beforeEach(() => { | ||
setConfigDataMock = jest.fn().mockImplementation((callback) => { | ||
nextState = callback({ config: "config" }); | ||
}); | ||
|
||
render( | ||
<MemoryModelsSample | ||
onTextDataSubmit={onSubmitMock} | ||
setTextData={setTextDataMock} | ||
setConfigData={setConfigDataMock} | ||
/> | ||
); | ||
}); | ||
|
||
it("renders Accordion", () => { | ||
expect( | ||
screen.getByTestId("sample-inputs-accordion").textContent | ||
).toEqual("Sample Inputs"); | ||
expect(screen.getByText("Sample Inputs")).toBeDefined(); | ||
}); | ||
|
||
it("renders all sample buttons", () => { | ||
// sx for MUI comps or non-inline CSS in general will not be loaded into Jest by default | ||
// might be achievable with some libs but this test makes sure the base texts are present. | ||
// Therefore, we can't test for capitalization (via sx) here | ||
["automation", "blankspace", "manual", "simple", "style"].map( | ||
(sample) => expect(screen.getByText(sample)).toBeDefined() | ||
); | ||
}); | ||
|
||
it("handles sample button click", async () => { | ||
const button = screen.getByText("automation"); | ||
fireEvent.click(button); | ||
|
||
// Wait for state updates and side effects to complete | ||
await waitFor(() => { | ||
// expect(onSubmitMock).toHaveBeenCalledWith(); | ||
expect(setTextDataMock).toHaveBeenCalledWith( | ||
JSON.stringify({ sample: "automation" }, null, 2) | ||
); | ||
expect(nextState).toEqual({ config: "config" }); | ||
}); | ||
}); | ||
}); |