Skip to content

Commit 3ee11d0

Browse files
committed
setup: update text letter count
1 parent 3ca5202 commit 3ee11d0

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/tests/components/MessageForm.test.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from "react";
22
import { render, fireEvent } from "@testing-library/react";
33
import { MessageForm } from "../../components/MessageForm";
4-
import { USER } from "../../config";
4+
import { USER, MAX_MESSAGE_TEXT_LENGTH } from "../../config";
55

66
describe("MessageForm", () => {
77
test("initiates text as empty", () => {
@@ -17,4 +17,21 @@ describe("MessageForm", () => {
1717
fireEvent.change(input, { target: { value: text } });
1818
expect(input.value).toBe(text);
1919
});
20+
21+
test("initiates text count as 0", () => {
22+
const utils = render(<MessageForm user={USER} />);
23+
const textCount = utils.getByTitle("text-count");
24+
expect(textCount.textContent.trim()).toBe(`0 / ${MAX_MESSAGE_TEXT_LENGTH}`);
25+
});
26+
27+
test("updates text count with user typing", () => {
28+
const text = "55555";
29+
const utils = render(<MessageForm user={USER} />);
30+
const input = utils.getByLabelText("message-form");
31+
fireEvent.change(input, { target: { value: text } });
32+
const textCount = utils.getByTitle("text-count");
33+
expect(textCount.textContent.trim()).toBe(
34+
`${text.length} / ${MAX_MESSAGE_TEXT_LENGTH}`
35+
);
36+
});
2037
});

0 commit comments

Comments
 (0)