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

DSD-1746: FeedbackBox interaction tests #1628

Merged
merged 4 commits into from
Jun 28, 2024
Merged
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Currently, this repo is in Prerelease. When it is released, this project will ad

### Adds

- Adds Storybook interaction tests for `CheckboxGroup`, `DatePicker`, and `Slider` components.
- Adds Storybook interaction tests for `CheckboxGroup`, `DatePicker`, `Slider`, and `FeedbackBox` components.
- Adds `closeOnBlur` prop to `MultiSelect` component which, when set to true, closes the component if it loses focus.

### Updates
Expand Down
8 changes: 4 additions & 4 deletions src/components/FeedbackBox/FeedbackBox.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Link from "../Link/Link";

# FeedbackBox

| Component Version | DS Version |
| ----------------- | ---------- |
| Added | `1.3.0` |
| Latest | `3.0.0` |
| Component Version | DS Version |
| ----------------- | ------------ |
| Added | `1.3.0` |
| Latest | `Prerelease` |

## Table of Contents

Expand Down
43 changes: 40 additions & 3 deletions src/components/FeedbackBox/FeedbackBox.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box } from "@chakra-ui/react";
import type { Meta, StoryObj } from "@storybook/react";
import { useState } from "react";
import { userEvent, expect, screen } from "@storybook/test";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did not know you can get the mounted DOM directly from the package. I've been doing const screen = within(canvasElement);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, something to remember for Modal for sure bc screen here is not the same as within(canvasElement)


import FeedbackBox, { feedbackBoxViewTypeArray } from "./FeedbackBox";
import Heading from "../Heading/Heading";
Expand Down Expand Up @@ -102,14 +103,14 @@ export const WithControls: Story = {
hiddenFields: undefined,
id: "feedbackBox-id",
isInvalidComment: false,
isInvalidEmail: false,
isInvalidEmail: true,
isOpen: undefined,
notificationText: undefined,
onClose: undefined,
onOpen: undefined,
onSubmit: undefined,
showCategoryField: false,
showEmailField: false,
showCategoryField: true,
showEmailField: true,
title: "Help and Feedback",
view: "form",
},
Expand All @@ -120,5 +121,41 @@ export const WithControls: Story = {
},
jest: "FeedbackBox.test.tsx",
},
play: async () => {
expect(
screen.queryByRole("textbox", { name: /comment/i })
).not.toBeInTheDocument();
const button = screen.getByRole("button", { name: "Help and Feedback" });
await userEvent.click(button);
expect(screen.getByLabelText("Correction")).not.toBeChecked();
await userEvent.click(screen.getByLabelText("Correction"));
expect(screen.getByLabelText("Correction")).toBeChecked();
expect(
screen.getByRole("textbox", { name: /comment/i })
).toBeInTheDocument();
const submit = screen.getByRole("button", { name: "Submit" });
await userEvent.click(submit);
expect(screen.getByText(/please fill out this field/i)).toBeInTheDocument();
await userEvent.type(
screen.getByRole("textbox", { name: /comment/i }),
"Hello"
);
await userEvent.type(
screen.getByRole("textbox", { name: /email/i }),
"not valid"
);
expect(
screen.getByText(/please enter a valid email address/i)
).toBeInTheDocument();
await userEvent.clear(screen.getByRole("textbox", { name: /email/i }));
await userEvent.type(
screen.getByRole("textbox", { name: /email/i }),
"a@b.com"
);
await userEvent.click(submit);
expect(
screen.getByText(/thank you for submitting your feedback/i)
).toBeInTheDocument();
},
render: (args) => <FeedbackBoxWithControls {...args} />,
};
7 changes: 7 additions & 0 deletions src/components/FeedbackBox/feedbackBoxChangelogData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@
import { ChangelogData } from "../../utils/ComponentChangelogTable";

export const changelogData: ChangelogData[] = [
{
date: "Prerelease",
version: "Prerelease",
type: "Update",
affects: ["Styles"],
notes: ["Adds interaction tests for the Controls story."],
},
{
date: "2024-03-14",
version: "3.0.0",
Expand Down
Loading