forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.testids.test.ts
More file actions
47 lines (40 loc) · 2.04 KB
/
Copy pathinput.testids.test.ts
File metadata and controls
47 lines (40 loc) · 2.04 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
import { readFileSync } from "fs";
import { resolve } from "path";
/**
* Verifies stable `data-testid` markers exist on the CopilotChat input controls
* so e2e tests (e.g. Playwright) can deterministically locate the textarea and
* send button on the default `<CopilotChat>` surface. See GitHub issue #4215.
*
* The selector names mirror the V2 components in
* `@copilotkit/react-core` (`copilot-chat-textarea`, `copilot-send-button`) so a
* test recipe written against V2 carries over to the default surface unchanged.
*
* This runs in the package's node test environment (no DOM), so it asserts the
* wiring at the source level. Crucially it checks BOTH that `Input.tsx` passes
* the testid AND that `Textarea.tsx` forwards it onto the rendered `<textarea>`:
* `AutoResizingTextarea` destructures a fixed prop set with no `{...rest}`
* spread, so a testid passed from `Input.tsx` is silently dropped unless the
* inner component explicitly declares and applies it.
*/
const inputPath = resolve(__dirname, "Input.tsx");
const textareaPath = resolve(__dirname, "Textarea.tsx");
const inputSrc = readFileSync(inputPath, "utf-8");
const textareaSrc = readFileSync(textareaPath, "utf-8");
describe("CopilotChat input stable testids", () => {
it("Input passes the copilot-chat-textarea testid to the textarea", () => {
expect(inputSrc).toMatch(/data-testid="copilot-chat-textarea"/);
});
it("Input puts the copilot-send-button testid on the send control", () => {
expect(inputSrc).toMatch(/data-testid="copilot-send-button"/);
});
it("Input preserves the legacy data-test-id for back-compat", () => {
expect(inputSrc).toMatch(/data-test-id=/);
expect(inputSrc).toMatch(/copilot-chat-ready/);
});
it("Textarea declares and forwards data-testid onto the inner textarea", () => {
// Declared on the props interface...
expect(textareaSrc).toMatch(/"data-testid"\?: string/);
// ...and actually applied to the rendered <textarea> (the dropped-prop guard).
expect(textareaSrc).toMatch(/data-testid=\{dataTestId\}/);
});
});