@bigbinary/neetoui 3.2.67 → 3.2.68
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/formik.js +1 -1
- package/index.js +1 -1
- package/layouts.js +1 -1
- package/package.json +1 -1
- package/tests/Textarea.test.js +51 -0
- package/tests/Typography.test.js +20 -0
package/package.json
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react";
|
|
3
|
+
import { Textarea } from "../lib/components";
|
|
4
|
+
import userEvent from "@testing-library/user-event";
|
|
5
|
+
|
|
6
|
+
describe("Textarea", () => {
|
|
7
|
+
it("should render without error", () => {
|
|
8
|
+
const { getByLabelText } = render(<Textarea id="text" label="Textarea" />);
|
|
9
|
+
expect(getByLabelText("Textarea")).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should update value on input when uncontrolled", () => {
|
|
13
|
+
const { getByLabelText } = render(<Textarea id="text" label="Textarea" />);
|
|
14
|
+
const textarea = getByLabelText("Textarea");
|
|
15
|
+
userEvent.type(textarea, "Test");
|
|
16
|
+
expect(textarea).toHaveValue("Test");
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("should call onChange when textarea value changes", () => {
|
|
20
|
+
const onChange = jest.fn();
|
|
21
|
+
const { getByLabelText } = render(
|
|
22
|
+
<Textarea id="text" label="Textarea" onChange={onChange} />
|
|
23
|
+
);
|
|
24
|
+
userEvent.type(getByLabelText("Textarea"), "Test");
|
|
25
|
+
expect(onChange).toHaveBeenCalledTimes(4);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("should display helpText", () => {
|
|
29
|
+
const { getByText } = render(<Textarea id="text" label="Textarea" helpText="Help text" />);
|
|
30
|
+
expect(getByText("Help text")).toBeInTheDocument();
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should display error message", () => {
|
|
34
|
+
const { getByText } = render(
|
|
35
|
+
<Textarea id="text" label="Textarea" error="Error message" />
|
|
36
|
+
);
|
|
37
|
+
expect(getByText("Error message")).toBeInTheDocument();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should properly handle maxLength", () => {
|
|
41
|
+
const { getByLabelText, getByText } = render(
|
|
42
|
+
<Textarea id="text" label="Textarea" maxLength={5} />
|
|
43
|
+
);
|
|
44
|
+
expect(getByText("0 / 5")).toBeInTheDocument();
|
|
45
|
+
expect(getByLabelText("Textarea")).toHaveAttribute("maxLength", "5");
|
|
46
|
+
|
|
47
|
+
userEvent.type(getByLabelText("Textarea"), "Testing maxLength");
|
|
48
|
+
expect(getByText("5 / 5")).toBeInTheDocument();
|
|
49
|
+
expect(getByLabelText("Textarea")).toHaveValue("Testi");
|
|
50
|
+
});
|
|
51
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Typography } from "../lib/components";
|
|
3
|
+
import { render } from "@testing-library/react";
|
|
4
|
+
|
|
5
|
+
describe("Typography", () => {
|
|
6
|
+
it("should render without error", () => {
|
|
7
|
+
const { getByText } = render(<Typography style="body1">Typography</Typography>);
|
|
8
|
+
expect(getByText("Typography")).toBeInTheDocument();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
it("should render a heading when style is of heading type", () => {
|
|
12
|
+
const { getByRole } = render(<Typography style="h1">Typography</Typography>);
|
|
13
|
+
expect(getByRole("heading", { level: 1 })).toBeInTheDocument();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should override default tag when component prop is given", () => {
|
|
17
|
+
const { getByRole } = render(<Typography style="h1" component="h2">Typography</Typography>);
|
|
18
|
+
expect(getByRole("heading", { level: 2 })).toBeInTheDocument();
|
|
19
|
+
});
|
|
20
|
+
});
|