-
Notifications
You must be signed in to change notification settings - Fork 350
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
Showing
5 changed files
with
188 additions
and
14 deletions.
There are no files selected for viewing
102 changes: 102 additions & 0 deletions
102
packages/perseus-editor/src/components/__tests__/interactive-graph-description.test.tsx
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 |
---|---|---|
@@ -0,0 +1,102 @@ | ||
import {Dependencies} from "@khanacademy/perseus"; | ||
import {render, screen} from "@testing-library/react"; | ||
import {userEvent as userEventLib} from "@testing-library/user-event"; | ||
import * as React from "react"; | ||
|
||
import {testDependencies} from "../../../../../testing/test-dependencies"; | ||
import InteractiveGraphDescription from "../interactive-graph-description"; | ||
|
||
import type {UserEvent} from "@testing-library/user-event"; | ||
|
||
import "@testing-library/jest-dom"; // Imports custom matchers | ||
|
||
function userEventForFakeTimers() { | ||
return userEventLib.setup({ | ||
advanceTimers: jest.advanceTimersByTime, | ||
}); | ||
} | ||
|
||
describe("InteractiveGraphSettings", () => { | ||
let userEvent: UserEvent; | ||
beforeEach(() => { | ||
userEvent = userEventForFakeTimers(); | ||
jest.spyOn(Dependencies, "getDependencies").mockReturnValue( | ||
testDependencies, | ||
); | ||
}); | ||
|
||
test("renders", () => { | ||
// Arrange | ||
render( | ||
<InteractiveGraphDescription | ||
ariaLabelValue="Graph Title" | ||
ariaDescriptionValue="Graph Description" | ||
onChange={jest.fn()} | ||
/>, | ||
); | ||
|
||
// Act | ||
const titleInput = screen.getByRole("textbox", {name: "Title"}); | ||
const descriptionInput = screen.getByRole("textbox", { | ||
name: "Description", | ||
}); | ||
|
||
// Assert | ||
expect(titleInput).toBeInTheDocument(); | ||
expect(titleInput).toHaveValue("Graph Title"); | ||
expect(descriptionInput).toBeInTheDocument(); | ||
expect(descriptionInput).toHaveValue("Graph Description"); | ||
}); | ||
|
||
test("calls onChange when the title is changed", async () => { | ||
// Arrange | ||
const onChange = jest.fn(); | ||
render( | ||
<InteractiveGraphDescription | ||
ariaLabelValue="" | ||
ariaDescriptionValue="" | ||
onChange={onChange} | ||
/>, | ||
); | ||
|
||
// Act | ||
const titleInput = screen.getByRole("textbox", {name: "Title"}); | ||
await userEvent.clear(titleInput); | ||
await userEvent.type(titleInput, "Zot"); | ||
|
||
// Assert | ||
// Calls are not being accumulated because they're mocked. | ||
expect(onChange.mock.calls).toEqual([ | ||
[{fullGraphAriaLabel: "Z"}], | ||
[{fullGraphAriaLabel: "o"}], | ||
[{fullGraphAriaLabel: "t"}], | ||
]); | ||
}); | ||
|
||
test("calls onChange when the description is changed", async () => { | ||
// Arrange | ||
const onChange = jest.fn(); | ||
render( | ||
<InteractiveGraphDescription | ||
ariaLabelValue="" | ||
ariaDescriptionValue="" | ||
onChange={onChange} | ||
/>, | ||
); | ||
|
||
// Act | ||
const descriptionInput = screen.getByRole("textbox", { | ||
name: "Description", | ||
}); | ||
await userEvent.clear(descriptionInput); | ||
await userEvent.type(descriptionInput, "Zot"); | ||
|
||
// Assert | ||
// Calls are not being accumulated because they're mocked. | ||
expect(onChange.mock.calls).toEqual([ | ||
[{fullGraphAriaDescription: "Z"}], | ||
[{fullGraphAriaDescription: "o"}], | ||
[{fullGraphAriaDescription: "t"}], | ||
]); | ||
}); | ||
}); |
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
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