| 1 | import { describe, expect, it } from "vite-plus/test"; |
| 2 | |
| 3 | import { |
| 4 | snapShotAccessibilityDetails, |
| 5 | snapShotIncludesAccessibility, |
| 6 | } from "./SnapShotAttachmentDetails"; |
| 7 | |
| 8 | describe("SnapShotAttachmentDetails", () => { |
| 9 | it("reports screenshot-only captures without inventing accessibility data", () => { |
| 10 | const source = { |
| 11 | kind: "snap-shot" as const, |
| 12 | capturedAt: "2026-08-27T00:00:00.000Z", |
| 13 | appName: "Safari", |
| 14 | windowTitle: "T3 Code", |
| 15 | }; |
| 16 | |
| 17 | expect(snapShotIncludesAccessibility(source)).toBe(false); |
| 18 | expect(snapShotAccessibilityDetails(source)).toBeUndefined(); |
| 19 | }); |
| 20 | |
| 21 | it("formats a structured accessibility tree as JSON", () => { |
| 22 | const source = { |
| 23 | kind: "snap-shot" as const, |
| 24 | capturedAt: "2026-08-27T00:00:00.000Z", |
| 25 | appName: "Safari", |
| 26 | windowTitle: "T3 Code", |
| 27 | accessibility: { |
| 28 | format: "element-tree" as const, |
| 29 | coordinateSpace: "captured-image" as const, |
| 30 | imageSize: { width: 800, height: 600 }, |
| 31 | truncated: false, |
| 32 | root: { |
| 33 | role: "window", |
| 34 | name: "T3 Code", |
| 35 | bounds: { x: 0, y: 0, width: 800, height: 600 }, |
| 36 | children: [ |
| 37 | { |
| 38 | role: "button", |
| 39 | name: "Save", |
| 40 | bounds: { x: 10, y: 10, width: 80, height: 24 }, |
| 41 | children: [], |
| 42 | }, |
| 43 | ], |
| 44 | }, |
| 45 | }, |
| 46 | }; |
| 47 | |
| 48 | expect(snapShotIncludesAccessibility(source)).toBe(true); |
| 49 | const details = snapShotAccessibilityDetails(source); |
| 50 | expect(details?.format).toBe("json"); |
| 51 | expect(details?.content).toBe(JSON.stringify(source.accessibility, null, 2)); |
| 52 | expect(JSON.parse(details?.content ?? "")).toEqual(source.accessibility); |
| 53 | }); |
| 54 | |
| 55 | it("prefers structured JSON over duplicate legacy text", () => { |
| 56 | const source = { |
| 57 | kind: "snap-shot" as const, |
| 58 | capturedAt: "2026-08-27T00:00:00.000Z", |
| 59 | appName: "Safari", |
| 60 | windowTitle: "T3 Code", |
| 61 | accessibleText: "T3 Code\nSave", |
| 62 | accessibility: { |
| 63 | format: "element-tree" as const, |
| 64 | coordinateSpace: "captured-image" as const, |
| 65 | imageSize: { width: 800, height: 600 }, |
| 66 | truncated: false, |
| 67 | root: { |
| 68 | role: "window", |
| 69 | name: "T3 Code", |
| 70 | bounds: { x: 0, y: 0, width: 800, height: 600 }, |
| 71 | children: [], |
| 72 | }, |
| 73 | }, |
| 74 | }; |
| 75 | |
| 76 | expect(snapShotAccessibilityDetails(source)).toEqual({ |
| 77 | content: JSON.stringify(source.accessibility, null, 2), |
| 78 | format: "json", |
| 79 | }); |
| 80 | }); |
| 81 | |
| 82 | it("falls back to flat accessibility text", () => { |
| 83 | const source = { |
| 84 | kind: "snap-shot" as const, |
| 85 | capturedAt: "2026-08-27T00:00:00.000Z", |
| 86 | appName: "Terminal", |
| 87 | windowTitle: "Logs", |
| 88 | accessibleText: "legacy duplicate", |
| 89 | accessibility: { |
| 90 | format: "flat-text" as const, |
| 91 | text: "Current terminal text", |
| 92 | truncated: false, |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | expect(snapShotAccessibilityDetails(source)).toEqual({ |
| 97 | content: "Current terminal text", |
| 98 | format: "text", |
| 99 | }); |
| 100 | }); |
| 101 | }); |