Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Numeric Input] - Update editor screen to be more organized #1951

Draft
wants to merge 15 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/nice-turkeys-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@khanacademy/perseus-editor": minor
---

[Numeric Input] - Adjust editor to organize settings more logically
1 change: 1 addition & 0 deletions packages/perseus-editor/src/components/heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ const styles = StyleSheet.create({
marginInline: -10,
backgroundColor: color.offBlack8,
padding: spacing.xSmall_8,
width: "calc(100% + 20px)",
},
heading: {
flexDirection: "row",
Expand Down
10 changes: 10 additions & 0 deletions packages/perseus-editor/src/styles/perseus-editor.less
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@
.categorizer-container {
overflow-x: scroll;
}

.section-accordion {
display: flex;
flex-direction: row;
}

.delete-item-button {
align-self: center;
padding-right: 0.5em;
}
}

.perseus-widget-editor-title-id > svg {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {Dependencies} from "@khanacademy/perseus";
import {RenderStateRoot} from "@khanacademy/wonder-blocks-core";
import {render, screen, waitFor} from "@testing-library/react";
import {userEvent as userEventLib} from "@testing-library/user-event";
import * as React from "react";
Expand All @@ -21,7 +22,9 @@ describe("numeric-input-editor", () => {
});

it("should render", async () => {
render(<NumericInputEditor onChange={() => undefined} />);
render(<NumericInputEditor onChange={() => undefined} />, {
wrapper: RenderStateRoot,
});

await waitFor(async () =>
expect(
Expand All @@ -33,7 +36,9 @@ describe("numeric-input-editor", () => {
it("should be possible to select normal width", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("button", {name: "Normal (80px)"}),
Expand All @@ -48,7 +53,9 @@ describe("numeric-input-editor", () => {
it("should be possible to select small width", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("button", {name: "Small (40px)"}),
Expand All @@ -63,7 +70,9 @@ describe("numeric-input-editor", () => {
it("should be possible to select right alignment", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("checkbox", {name: "Right alignment"}),
Expand All @@ -75,7 +84,9 @@ describe("numeric-input-editor", () => {
it("should be possible to select coefficient", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("checkbox", {name: "Coefficient"}),
Expand All @@ -87,9 +98,10 @@ describe("numeric-input-editor", () => {
it("should be possible to select strictly match only these formats", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(screen.getByLabelText("Toggle options"));
await userEvent.click(
screen.getByRole("checkbox", {
name: "Strictly match only these formats",
Expand All @@ -114,7 +126,9 @@ describe("numeric-input-editor", () => {
it("should be possible to update label text", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

const input = screen.getByRole("textbox", {
name: "Aria label",
Expand All @@ -128,26 +142,13 @@ describe("numeric-input-editor", () => {
);
});

it("should be possible to toggle options", async () => {
render(<NumericInputEditor onChange={() => {}} />);

await userEvent.click(
screen.getByRole("link", {name: "Toggle options"}),
);

expect(
screen.getByText("Unsimplified answers are"),
).toBeInTheDocument();
});

it("should be possible to set unsimplified answers to ungraded", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("link", {name: "Toggle options"}),
);
await userEvent.click(screen.getByRole("button", {name: "ungraded"}));

expect(onChangeMock).toBeCalledWith(
Expand All @@ -162,11 +163,10 @@ describe("numeric-input-editor", () => {
it("should be possible to set unsimplified answers to accepted", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("link", {name: "Toggle options"}),
);
await userEvent.click(screen.getByRole("button", {name: "accepted"}));

expect(onChangeMock).toBeCalledWith(
Expand All @@ -181,11 +181,10 @@ describe("numeric-input-editor", () => {
it("should be possible to set unsimplified answers to wrong", async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("link", {name: "Toggle options"}),
);
await userEvent.click(screen.getByRole("button", {name: "wrong"}));

expect(onChangeMock).toBeCalledWith(
Expand All @@ -210,11 +209,10 @@ describe("numeric-input-editor", () => {
it(`should be possible to set suggested answer format to: ${name}`, async () => {
const onChangeMock = jest.fn();

render(<NumericInputEditor onChange={onChangeMock} />);
render(<NumericInputEditor onChange={onChangeMock} />, {
wrapper: RenderStateRoot,
});

await userEvent.click(
screen.getByRole("link", {name: "Toggle options"}),
);
await userEvent.click(screen.getByTitle(name));

expect(onChangeMock).toBeCalledWith(
Expand Down
Loading
Loading