-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests to DefinitionEditor (#891)
* add tests to DefinitionEditor * changeset
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@khanacademy/perseus-editor": patch | ||
--- | ||
|
||
add tests for DefinitionEditor |
18 changes: 18 additions & 0 deletions
18
packages/perseus-editor/src/widgets/__stories__/definition-editor.stories.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,18 @@ | ||
import {action} from "@storybook/addon-actions"; | ||
import * as React from "react"; | ||
|
||
import DefinitionEditor from "../definition-editor"; | ||
|
||
type StoryArgs = Record<any, any>; | ||
|
||
type Story = { | ||
title: string; | ||
}; | ||
|
||
export default { | ||
title: "Perseus/Editor/Widgets/Definition Editor", | ||
} as Story; | ||
|
||
export const Default = (args: StoryArgs): React.ReactElement => { | ||
return <DefinitionEditor onChange={action("onChange")} />; | ||
}; |
41 changes: 41 additions & 0 deletions
41
packages/perseus-editor/src/widgets/__tests__/definition-editor.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,41 @@ | ||
import {Dependencies} from "@khanacademy/perseus"; | ||
import {render, screen} from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import * as React from "react"; | ||
|
||
import "@testing-library/jest-dom"; | ||
|
||
import {testDependencies} from "../../../../../testing/test-dependencies"; | ||
import DefinitionEditor from "../definition-editor"; | ||
|
||
describe("definition-editor", () => { | ||
beforeEach(() => { | ||
jest.spyOn(Dependencies, "getDependencies").mockReturnValue( | ||
testDependencies, | ||
); | ||
}); | ||
|
||
it("should render", async () => { | ||
render(<DefinitionEditor onChange={() => undefined} />); | ||
|
||
expect( | ||
await screen.findByText("Definition style guide"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should be possible to change the definition", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
render(<DefinitionEditor onChange={onChangeMock} />); | ||
|
||
const input = screen.getByRole("textbox", { | ||
name: "Word to be defined:", | ||
}); | ||
userEvent.type(input, "a"); | ||
|
||
expect(onChangeMock).toBeCalledWith( | ||
expect.objectContaining({togglePrompt: "a"}), | ||
undefined, | ||
); | ||
}); | ||
}); |