Skip to content

Commit 2ad5353

Browse files
Issue #7 Backfill tests for Atoms/PasswordInput
Add tests for atoms password input
2 parents b8dd4ac + 368aeb4 commit 2ad5353

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed
Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,60 @@
11
import React from "react";
2+
import faker from "faker";
3+
import { PasswordInput } from "./password-input";
4+
import { render, fireEvent } from "@testing-library/react";
5+
import uuid from "uuid";
6+
import { InputTypes } from "../constants/input-types";
27

38
describe("PasswordInput", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/7", () => {});
9+
test("when given default props, renders input", () => {
10+
// Arrange
11+
const testDataId = "testDataId";
12+
13+
// Act
14+
const { getByTestId } = render(
15+
<PasswordInput
16+
isVisible={true}
17+
id={uuid()}
18+
onChange={() => {}}
19+
testId={testDataId}
20+
/>
21+
);
22+
23+
// Assert
24+
expect(getByTestId(testDataId)).not.toBeNil();
25+
});
26+
27+
test("when onChange prop set, calls handler upon change", () => {
28+
// Arrange
29+
let isChecked = false;
30+
const handleChange = () => (isChecked = true);
31+
const testDataId = "testDataId";
32+
33+
// Act
34+
const { getByTestId } = render(
35+
<PasswordInput
36+
isVisible={true}
37+
id={uuid()}
38+
onChange={handleChange}
39+
testId={testDataId}
40+
/>
41+
);
42+
fireEvent.change(getByTestId(testDataId), {
43+
target: { value: faker.random.word() },
44+
});
45+
46+
// Assert
47+
expect(isChecked).toBeTrue();
48+
});
49+
50+
test("when isVisible prop set to false, renders with type password", () => {
51+
// Arrange & Act
52+
const { container } = render(
53+
<PasswordInput onChange={() => {}} isVisible={false} id={uuid()} />
54+
);
55+
const htmlInputElement = container.getElementsByTagName("input");
56+
57+
// Assert
58+
expect(htmlInputElement[0].type).toBe(InputTypes.Password);
59+
});
560
});

src/atoms/forms/password-input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const PasswordInput: React.FC<PasswordInputProps> = (
3939

4040
return (
4141
<input
42-
data-test-id={testId}
42+
data-testid={testId}
4343
disabled={disabled}
4444
id={id}
4545
maxLength={20}

0 commit comments

Comments
 (0)