Skip to content

Commit

Permalink
add test defaulting to TEXTAREA_CHAR_LENGTH and to manuel limit
Browse files Browse the repository at this point in the history
  • Loading branch information
m0dh4x committed Dec 10, 2024
1 parent 67ecaf6 commit a5b370b
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions app/components/inputs/__test__/Textarea.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,25 @@ describe("Textarea component", () => {
getInputProps.mockImplementationOnce(() => ({
id: componentName,
placeholder: "Test Placeholder",
maxLength: TEXTAREA_CHAR_LIMIT,
}));

const RemixStub = createRemixStub([
{
path: "",
Component: () => (
<Textarea
name={componentName}
maxLength={5000}
label="Test Label"
formId="formId"
/>
<Textarea name={componentName} label="Test Label" formId="formId" />
),
},
]);

render(<RemixStub />);

expect(getInputProps).toHaveBeenCalledWith(
expect.objectContaining({
maxLength: TEXTAREA_CHAR_LIMIT,
}),
);

const element = screen.getByRole("textbox");
const elementByLabel = screen.getByLabelText("Test Label");
expect(element).toBeInTheDocument();
Expand All @@ -60,8 +60,6 @@ describe("Textarea component", () => {
expect(elementByLabel).not.toHaveClass("ds-heading-03-reg");

expect(screen.getByPlaceholderText("Test Placeholder")).toBeInTheDocument();

expect(element).toHaveAttribute("maxLength", "5000");
});

it("renders without errors when description is provided", () => {
Expand Down Expand Up @@ -139,9 +137,7 @@ describe("Textarea component", () => {
const RemixStub = createRemixStub([
{
path: "",
Component: () => (
<Textarea maxLength={5000} name="componentName" label="Test Label" />
),
Component: () => <Textarea name="componentName" label="Test Label" />,
},
]);

Expand All @@ -168,7 +164,7 @@ describe("Textarea component", () => {
expect(textarea.getAttribute("rows")).toEqual(TEXT_AREA_ROWS.toString());
});

it("should enforce maxCharacterLength limit", () => {
it("should set the maxLength and enforce it", () => {
const maxLength = 10;
getInputProps.mockImplementationOnce(() => ({
id: "componentName",
Expand Down Expand Up @@ -200,6 +196,11 @@ describe("Textarea component", () => {
target: { value: "This is a very long text" },
});

expect(getInputProps).toHaveBeenCalledWith(
expect.objectContaining({
maxLength: maxLength,
}),
);
expect(textarea.value.length).toEqual(maxLength);
expect(textarea.value).toEqual("This is a ");
});
Expand Down

0 comments on commit a5b370b

Please sign in to comment.