-
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 for SorterEditor * changeset
- Loading branch information
Showing
3 changed files
with
78 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 SorterEditor |
18 changes: 18 additions & 0 deletions
18
packages/perseus-editor/src/widgets/__stories__/sorter-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 SorterEditor from "../sorter-editor"; | ||
|
||
type StoryArgs = Record<any, any>; | ||
|
||
type Story = { | ||
title: string; | ||
}; | ||
|
||
export default { | ||
title: "Perseus/Editor/Widgets/Sorter Editor", | ||
} as Story; | ||
|
||
export const Default = (args: StoryArgs): React.ReactElement => { | ||
return <SorterEditor onChange={action("onChange")} />; | ||
}; |
55 changes: 55 additions & 0 deletions
55
packages/perseus-editor/src/widgets/__tests__/sorter-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,55 @@ | ||
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 SorterEditor from "../sorter-editor"; | ||
|
||
describe("sorter-editor", () => { | ||
beforeEach(() => { | ||
jest.spyOn(Dependencies, "getDependencies").mockReturnValue( | ||
testDependencies, | ||
); | ||
}); | ||
|
||
it("renders", async () => { | ||
render(<SorterEditor onChange={() => {}} />); | ||
|
||
expect(screen.getByText("Correct answer:")).toBeInTheDocument(); | ||
}); | ||
|
||
it("should be possible to change layout to vertical", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
render(<SorterEditor onChange={onChangeMock} />); | ||
|
||
const select = screen.getByRole("combobox", {name: "Layout:"}); | ||
userEvent.selectOptions(select, "vertical"); | ||
|
||
expect(onChangeMock).toBeCalledWith({layout: "vertical"}); | ||
}); | ||
|
||
it("should be possible to change layout to horizontal", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
render(<SorterEditor onChange={onChangeMock} />); | ||
|
||
const select = screen.getByRole("combobox", {name: "Layout:"}); | ||
userEvent.selectOptions(select, "horizontal"); | ||
|
||
expect(onChangeMock).toBeCalledWith({layout: "horizontal"}); | ||
}); | ||
|
||
it("should be possible to change padding", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
render(<SorterEditor onChange={onChangeMock} />); | ||
|
||
userEvent.click(screen.getByRole("checkbox", {name: "Padding:"})); | ||
|
||
expect(onChangeMock).toBeCalledWith({padding: false}); | ||
}); | ||
}); |