Skip to content

Commit b3abb08

Browse files
Issue #9 Backfill tests for Atoms/TextInput and Atoms/TextInputIcon
Add tests for atoms text input and text input icon
2 parents 78d6ec7 + de01f35 commit b3abb08

File tree

3 files changed

+84
-3
lines changed

3 files changed

+84
-3
lines changed
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
import React from "react";
2+
import { TextInputIcon } from "./text-input-icon";
3+
import faker from "faker";
4+
import { render, fireEvent } from "@testing-library/react";
5+
import uuid from "uuid";
6+
import { Icons } from "../constants/icons";
27

38
describe("TextInputIcon", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/9", () => {});
9+
test("when default props, renders icon with input", () => {
10+
// Arrange
11+
const dataTestId = "dataTestId";
12+
const icon = Icons.Checkmark;
13+
14+
// Act
15+
const { getByTestId } = render(
16+
<TextInputIcon
17+
icon={icon}
18+
id={uuid()}
19+
onChange={() => {}}
20+
testId={dataTestId}
21+
/>
22+
);
23+
24+
// Assert
25+
expect(getByTestId(dataTestId)).not.toBeNil();
26+
});
527
});
Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,64 @@
11
import React from "react";
2+
import { TextInput } from "./text-input";
3+
import faker from "faker";
4+
import { render, fireEvent } from "@testing-library/react";
5+
import uuid from "uuid";
26

37
describe("TextInput", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/9", () => {});
8+
test("when default props, renders input", () => {
9+
// Arrange
10+
const dataTestId = "dataTestId";
11+
12+
// Act
13+
const { getByTestId } = render(
14+
<TextInput testId={dataTestId} onChange={() => {}} id={uuid()} />
15+
);
16+
17+
// Assert
18+
expect(getByTestId(dataTestId)).not.toBeNil();
19+
});
20+
21+
test("when onChange set, calls handler upon change", () => {
22+
// Arrange
23+
let isChecked = false;
24+
const dataTestId = "dataTestId";
25+
const handleChange = () => (isChecked = true);
26+
27+
// Act
28+
const { getByTestId } = render(
29+
<TextInput
30+
testId={dataTestId}
31+
onChange={handleChange}
32+
id={uuid()}
33+
/>
34+
);
35+
36+
fireEvent.change(getByTestId(dataTestId), {
37+
target: { value: faker.random.word() },
38+
});
39+
40+
// Assert
41+
expect(isChecked).toBeTrue();
42+
});
43+
44+
test("when maxLength prop set, renders with given value", () => {
45+
// Arrange
46+
const dataTestId = "dataTestId";
47+
const maximumLength = 999;
48+
49+
// Act
50+
const { getByTestId } = render(
51+
<TextInput
52+
id={uuid()}
53+
maxLength={maximumLength}
54+
onChange={() => {}}
55+
testId={dataTestId}
56+
/>
57+
);
58+
59+
// Assert
60+
expect(getByTestId(dataTestId).getAttribute("maxLength")).toBe(
61+
maximumLength.toString()
62+
);
63+
});
564
});

src/atoms/forms/text-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const TextInput: React.FC<TextInputProps> = (props: TextInputProps) => {
4040
return (
4141
<input
4242
aria-labelledby={ariaLabelledBy}
43-
data-test-id={testId}
43+
data-testid={testId}
4444
disabled={disabled}
4545
id={id}
4646
placeholder={placeholder}

0 commit comments

Comments
 (0)