-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntakeFieldControl.test.tsx
More file actions
54 lines (46 loc) · 1.7 KB
/
IntakeFieldControl.test.tsx
File metadata and controls
54 lines (46 loc) · 1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// @vitest-environment jsdom
import { cleanup, fireEvent, render, screen } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import { IntakeFieldControl } from "./IntakeFieldControl";
describe("IntakeFieldControl", () => {
afterEach(() => cleanup());
it("renders a single-line text input when no rows prop is provided", () => {
render(
<IntakeFieldControl
label="Issue summary"
value="VPN outage in west region"
onChange={vi.fn()}
/>,
);
const input = screen.getByLabelText("Issue summary") as HTMLInputElement;
expect(input.tagName).toBe("INPUT");
expect(input.type).toBe("text");
expect(input.value).toBe("VPN outage in west region");
});
it("renders a multi-line textarea when rows > 1 and reports new values through onChange", () => {
const onChange = vi.fn();
render(
<IntakeFieldControl
label="Symptoms"
value="initial"
rows={3}
onChange={onChange}
/>,
);
const textarea = screen.getByLabelText("Symptoms") as HTMLTextAreaElement;
expect(textarea.tagName).toBe("TEXTAREA");
expect(textarea.rows).toBe(3);
fireEvent.change(textarea, { target: { value: "updated symptoms" } });
expect(onChange).toHaveBeenCalledWith("updated symptoms");
});
it("fires onChange with the latest value on single-line edits", () => {
const onChange = vi.fn();
render(
<IntakeFieldControl label="Affected user" value="" onChange={onChange} />,
);
fireEvent.change(screen.getByLabelText("Affected user"), {
target: { value: "alice@example.com" },
});
expect(onChange).toHaveBeenCalledWith("alice@example.com");
});
});