Skip to content

Commit 980ebce

Browse files
author
Said Shah
committed
Merge branch 'main' of github.com:AndcultureCode/AndcultureCode.JavaScript.React.Components into main
2 parents 890dabd + be520c4 commit 980ebce

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed
Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,45 @@
11
import React from "react";
2+
import faker from "faker";
3+
import { InputCharacterCount } from "./input-character-count";
4+
import { render } from "@testing-library/react";
25

36
describe("InputCharacterCount", () => {
4-
test.skip("TODO - https://github.com/AndcultureCode/AndcultureCode.JavaScript.React.Components/issues/12", () => {});
7+
test("when default props, renders character count", () => {
8+
// Arrange
9+
const maxCharCount = faker.random.number(100);
10+
const charCount = faker.random.number(maxCharCount);
11+
const dataTestId = "dataTestId";
12+
13+
// Act
14+
const { getByTestId } = render(
15+
<InputCharacterCount
16+
currentLength={charCount}
17+
maxLength={maxCharCount}
18+
testId={dataTestId}
19+
/>
20+
);
21+
22+
// Assert
23+
expect(getByTestId(dataTestId)).not.toBeNil();
24+
});
25+
26+
test("when maxLength and currentLength props set, renders with values", () => {
27+
// Arrange
28+
const maxCharCount = faker.random.number(100);
29+
const charCount = faker.random.number(maxCharCount);
30+
const dataTestId = "dataTestId";
31+
32+
// Act
33+
const { getByTestId } = render(
34+
<InputCharacterCount
35+
currentLength={charCount}
36+
maxLength={maxCharCount}
37+
testId={dataTestId}
38+
/>
39+
);
40+
41+
// Assert
42+
expect(getByTestId(dataTestId).textContent).toContain(maxCharCount);
43+
expect(getByTestId(dataTestId).textContent).toContain(charCount);
44+
});
545
});

src/atoms/forms/input-character-count.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ import React from "react";
77
export interface InputCharacterCountProps {
88
currentLength: number;
99
maxLength: number;
10+
11+
/**
12+
* Unique identifier used select the underlying <input> for functional/e2e testing
13+
*/
14+
testId?: string;
1015
}
1116

1217
// #endregion Interfaces
@@ -19,7 +24,9 @@ const InputCharacterCount: React.FC<InputCharacterCountProps> = (
1924
props: InputCharacterCountProps
2025
) => {
2126
return (
22-
<div className="c-form-field__bottom__character-count">
27+
<div
28+
className="c-form-field__bottom__character-count"
29+
data-testid={props.testId}>
2330
{props.currentLength}/{props.maxLength}
2431
</div>
2532
);

0 commit comments

Comments
 (0)