|
1 | 1 | import React from "react"; |
| 2 | +import faker from "faker"; |
| 3 | +import { InputCharacterCount } from "./input-character-count"; |
| 4 | +import { render } from "@testing-library/react"; |
2 | 5 |
|
3 | 6 | 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 | + }); |
5 | 45 | }); |
0 commit comments