The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import type { PickedElementPayload } from "@t3tools/contracts"; |
| 2 | import { describe, expect, it } from "vite-plus/test"; |
| 3 | |
| 4 | import { normalizeElementContextSelection } from "./elementContext"; |
| 5 | |
| 6 | function makePayload(overrides?: Partial<PickedElementPayload>): PickedElementPayload { |
| 7 | return { |
| 8 | pageUrl: "https://example.com/dashboard", |
| 9 | pageTitle: "Dashboard", |
| 10 | tagName: "BUTTON", |
| 11 | selector: "button.submit", |
| 12 | htmlPreview: '<button class="submit">Save</button>', |
| 13 | componentName: "SubmitButton", |
| 14 | source: { |
| 15 | functionName: "SubmitButton", |
| 16 | fileName: "/repo/src/Button.tsx", |
| 17 | lineNumber: 12, |
| 18 | columnNumber: 5, |
| 19 | }, |
| 20 | stack: [ |
| 21 | { |
| 22 | functionName: "SubmitButton", |
| 23 | fileName: "/repo/src/Button.tsx", |
| 24 | lineNumber: 12, |
| 25 | columnNumber: 5, |
| 26 | }, |
| 27 | ], |
| 28 | styles: ".submit { color: white; }", |
| 29 | pickedAt: "2026-05-03T18:00:00.000Z", |
| 30 | ...overrides, |
| 31 | }; |
| 32 | } |
| 33 | |
| 34 | describe("normalizeElementContextSelection", () => { |
| 35 | it("clamps oversized htmlPreview / styles so we don't blow localStorage", () => { |
| 36 | const huge = "x".repeat(10_000); |
| 37 | const result = normalizeElementContextSelection( |
| 38 | makePayload({ htmlPreview: huge, styles: huge }), |
| 39 | ); |
| 40 | expect(result).not.toBeNull(); |
| 41 | expect(result!.htmlPreview.length).toBeLessThanOrEqual(4000); |
| 42 | expect(result!.styles.length).toBeLessThanOrEqual(4000); |
| 43 | expect(result!.htmlPreview.endsWith("…")).toBe(true); |
| 44 | expect(result!.styles.endsWith("…")).toBe(true); |
| 45 | }); |
| 46 | }); |