This repository has been archived by the owner on Jan 20, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Justin Anastos
authored
Jan 5, 2021
1 parent
5ab5602
commit 4de9a45
Showing
24 changed files
with
1,897 additions
and
231 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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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,7 @@ | ||
export { FormControl as Control } from "../FormControl"; | ||
export { FormDescription as Description } from "../FormDescription"; | ||
export { FormEndAdornment as EndAdornment } from "../FormEndAdornment"; | ||
export { FormErrorMessage as ErrorMessage } from "../FormErrorMessage"; | ||
export { FormHelperText as HelperText } from "../FormHelperText"; | ||
export { FormLabel as Label } from "../FormLabel"; | ||
export { FormStartAdornment as StartAdornment } from "../FormStartAdornment"; |
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,117 @@ | ||
/*eslint react/jsx-sort-props: "error" */ | ||
import "@testing-library/jest-dom"; | ||
import React from "react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { FormControl } from "../FormControl"; | ||
import { FormLabel } from "../FormLabel"; | ||
import { FormHelperText } from "../FormHelperText"; | ||
import { Input } from "../Input"; | ||
import { FormErrorMessage } from "../FormErrorMessage"; | ||
|
||
test("when passed a label, renders it", () => { | ||
render( | ||
<FormControl id="test"> | ||
<FormLabel>label text</FormLabel> | ||
<Input /> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.getByText("label text")).toBeInTheDocument(); | ||
}); | ||
|
||
test("when the label is clicked it focuses the input", () => { | ||
const labelText = "label text"; | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<FormLabel>{labelText}</FormLabel> | ||
<Input /> | ||
</FormControl>, | ||
); | ||
|
||
// Use `throw` so TypeScript knows `label` is not null | ||
const label = container.querySelector("label"); | ||
if (!label) throw new Error("Could not find label"); | ||
|
||
const input = screen.getByLabelText(labelText); | ||
expect(input).not.toHaveFocus(); | ||
|
||
userEvent.click(label); | ||
expect(input).toHaveFocus(); | ||
}); | ||
|
||
test("when passed `HelperText`, helper text is rendered", () => { | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<FormHelperText>helper text</FormHelperText> | ||
<Input /> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.queryByText("helper text")).toBeInTheDocument(); | ||
expect(container.querySelectorAll("svg")).toHaveLength(1); | ||
}); | ||
|
||
test("when passed two `HelperText` and `FormErrorMessage`, only renders the `FormErrorMessage`", () => { | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<Input /> | ||
<FormHelperText>helper text</FormHelperText> | ||
<FormErrorMessage>error text</FormErrorMessage> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.getByText("error text")).toBeInTheDocument(); | ||
expect(screen.queryByText("helper text")).not.toBeInTheDocument(); | ||
expect(container.querySelectorAll("svg")).toHaveLength(1); | ||
}); | ||
|
||
test("when passed `<FormControl error />`, renders error and svg", () => { | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<Input /> | ||
<FormErrorMessage>error text</FormErrorMessage> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.getByText("error text")).toBeInTheDocument(); | ||
expect(container.querySelector("svg")).toBeInTheDocument(); | ||
}); | ||
|
||
test("when passed `<HelperText>` witout `showIcon` prop, renders no svg", () => { | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<Input /> | ||
<FormHelperText>helper text</FormHelperText> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.getByText("helper text")).toBeInTheDocument(); | ||
expect(container.querySelector("svg")).not.toBeInTheDocument(); | ||
}); | ||
|
||
test.only("when passed `<HelperText>` with `showIcon` prop, renders svg", () => { | ||
const { container } = render( | ||
<FormControl id="test"> | ||
<FormHelperText showIcon>helper text</FormHelperText> | ||
<Input /> | ||
</FormControl>, | ||
); | ||
|
||
expect(screen.getByText("helper text")).toBeInTheDocument(); | ||
expect(container.querySelector("svg")).toBeInTheDocument(); | ||
}); | ||
|
||
test("when not passed `autoFocus` prop, should not have focus after mounting", () => { | ||
const labelText = "label text"; | ||
render( | ||
<FormControl id="test"> | ||
<FormLabel>{labelText}</FormLabel> | ||
<Input /> | ||
</FormControl>, | ||
); | ||
|
||
const formField = screen.getByLabelText(labelText); | ||
|
||
expect(formField).not.toHaveFocus(); | ||
}); |
Oops, something went wrong.