Skip to content

Commit

Permalink
Merge pull request #1628 from NYPL/DSD-1746/feedback-interaction-tests
Browse files Browse the repository at this point in the history
DSD-1746: FeedbackBox interaction tests
  • Loading branch information
7emansell authored Jun 28, 2024
2 parents 970f14c + f600cbb commit 40e9625
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 8 deletions.
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";

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

0 comments on commit 40e9625

Please sign in to comment.