Files
community-rule/tests/components/TextArea.test.tsx
T
adilalloandCursor 42d83c8b62 Give builder fields persistent labels, treat description as optional, and validate save-progress email with a real form.
Name stays required; description is a labelled optional textarea. Email uses native validity and form submit. Drop the dead workshop link and fix a few copy errors.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-10 11:37:41 -06:00

69 lines
2.1 KiB
TypeScript

import React from "react";
import { describe, it, expect } from "vitest";
import { screen } from "@testing-library/react";
import "@testing-library/jest-dom/vitest";
import TextArea from "../../app/components/controls/TextArea";
import { componentTestSuite } from "../utils/componentTestSuite";
import { renderWithProviders } from "../utils/test-utils";
type TextAreaProps = React.ComponentProps<typeof TextArea>;
componentTestSuite<TextAreaProps>({
component: TextArea,
name: "TextArea",
props: {
label: "Description",
value: "",
} as TextAreaProps,
requiredProps: ["label"],
optionalProps: {
placeholder: "Enter description",
},
primaryRole: "textbox",
testCases: {
renders: true,
accessibility: true,
keyboardNavigation: true,
disabledState: true,
errorState: true,
},
states: {
disabledProps: { disabled: true },
errorProps: { error: true },
},
});
describe("TextArea appearance", () => {
it("renders with appearance embedded and applies borderless styling", () => {
renderWithProviders(
<TextArea label="Notes" value="Some text" appearance="embedded" />,
);
const textarea = screen.getByRole("textbox", { name: /notes/i });
expect(textarea).toBeInTheDocument();
expect(textarea).toHaveClass("border-0");
});
it("keeps a programmatic label when the visible header is off", () => {
const { container } = renderWithProviders(
<TextArea label="Community description" formHeader={false} value="" />,
);
expect(
screen.getByRole("textbox", { name: "Community description" }),
).toBeInTheDocument();
expect(container.querySelector("label")).toHaveClass("sr-only");
});
it("uses tertiary text in the embedded default state and primary on focus", () => {
renderWithProviders(
<TextArea label="Notes" value="Some text" appearance="embedded" />,
);
const textarea = screen.getByRole("textbox", { name: /notes/i });
expect(textarea).toHaveClass(
"text-[var(--color-content-default-tertiary,#b4b4b4)]",
);
expect(textarea).toHaveClass(
"focus:text-[var(--color-content-default-primary)]",
);
});
});