-
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 CategorizerEditor (#890)
* add tests for CategorizerEditor * changeset
- Loading branch information
Showing
4 changed files
with
81 additions
and
1 deletion.
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 CategorizerEditor |
24 changes: 24 additions & 0 deletions
24
packages/perseus-editor/src/widgets/__stories__/categorizer-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,24 @@ | ||
import {ApiOptions} from "@khanacademy/perseus"; | ||
import {action} from "@storybook/addon-actions"; | ||
import * as React from "react"; | ||
|
||
import CategorizerEditor from "../categorizer-editor"; | ||
|
||
type StoryArgs = Record<any, any>; | ||
|
||
type Story = { | ||
title: string; | ||
}; | ||
|
||
export default { | ||
title: "Perseus/Editor/Widgets/Categorizer Editor", | ||
} as Story; | ||
|
||
export const Default = (args: StoryArgs): React.ReactElement => { | ||
return ( | ||
<CategorizerEditor | ||
onChange={action("onChange")} | ||
apiOptions={ApiOptions.defaults} | ||
/> | ||
); | ||
}; |
51 changes: 51 additions & 0 deletions
51
packages/perseus-editor/src/widgets/__tests__/categorizer-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,51 @@ | ||
import {ApiOptions, 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 CategorizerEditor from "../categorizer-editor"; | ||
|
||
describe("categorizer-editor", () => { | ||
beforeEach(() => { | ||
jest.spyOn(Dependencies, "getDependencies").mockReturnValue( | ||
testDependencies, | ||
); | ||
}); | ||
|
||
it("should render", async () => { | ||
render( | ||
<CategorizerEditor | ||
onChange={() => undefined} | ||
apiOptions={ApiOptions.defaults} | ||
/>, | ||
); | ||
|
||
expect( | ||
await screen.findByText("Randomize item order"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should be possible to change randomize item order", async () => { | ||
const onChangeMock = jest.fn(); | ||
|
||
render( | ||
<CategorizerEditor | ||
onChange={onChangeMock} | ||
apiOptions={ApiOptions.defaults} | ||
/>, | ||
); | ||
|
||
userEvent.click( | ||
screen.getByRole("checkbox", { | ||
name: "Randomize item order", | ||
}), | ||
); | ||
|
||
expect(onChangeMock).toBeCalledWith( | ||
expect.objectContaining({randomizeItems: true}), | ||
); | ||
}); | ||
}); |
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