|
1 | | -import { EnvironmentId, ThreadId } from "@t3tools/contracts"; |
| 1 | +import { |
| 2 | + type DesktopPreviewAutomationClickResult, |
| 3 | + EnvironmentId, |
| 4 | + ThreadId, |
| 5 | +} from "@t3tools/contracts"; |
2 | 6 | import { describe, expect, it } from "vite-plus/test"; |
3 | 7 |
|
4 | 8 | import { |
5 | 9 | confirmPreviewAutomationClickTarget, |
| 10 | + PreviewAutomationOperationError, |
6 | 11 | PreviewAutomationTargetLookupHostError, |
7 | 12 | } from "./previewAutomationErrors"; |
8 | 13 |
|
| 14 | +type NotSentClickResult = Extract<DesktopPreviewAutomationClickResult, { _tag: "NotSent" }>; |
| 15 | + |
9 | 16 | describe("confirmPreviewAutomationClickTarget", () => { |
10 | 17 | const context = { |
11 | 18 | requestId: "request-1", |
@@ -53,4 +60,33 @@ describe("confirmPreviewAutomationClickTarget", () => { |
53 | 60 | expect(disabled.message).not.toContain("secret"); |
54 | 61 | expect(ambiguous.message).not.toContain("secret"); |
55 | 62 | }); |
| 63 | + |
| 64 | + it("fails every NotSent outcome and preserves successful results", () => { |
| 65 | + const results = [ |
| 66 | + { _tag: "NotSent", reason: "tab-not-visible" }, |
| 67 | + { _tag: "NotSent", reason: "timeout", timeoutMs: 5_000 }, |
| 68 | + { _tag: "NotSent", reason: "target-missing" }, |
| 69 | + { _tag: "NotSent", reason: "target-hidden" }, |
| 70 | + { _tag: "NotSent", reason: "target-disabled" }, |
| 71 | + { _tag: "NotSent", reason: "target-ambiguous", matchCount: 3 }, |
| 72 | + ] satisfies ReadonlyArray<NotSentClickResult>; |
| 73 | + |
| 74 | + for (const result of results) { |
| 75 | + expect(() => confirmPreviewAutomationClickTarget(result, context)).toThrow(); |
| 76 | + } |
| 77 | + |
| 78 | + for (const result of results.slice(0, 2)) { |
| 79 | + try { |
| 80 | + confirmPreviewAutomationClickTarget(result, context); |
| 81 | + throw new Error("Expected click target confirmation to fail"); |
| 82 | + } catch (error) { |
| 83 | + expect(error).toBeInstanceOf(PreviewAutomationOperationError); |
| 84 | + expect((error as PreviewAutomationOperationError).cause).toEqual(result); |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + const dispatched = { _tag: "Dispatched" } as const; |
| 89 | + expect(confirmPreviewAutomationClickTarget(dispatched, context)).toBe(dispatched); |
| 90 | + expect(confirmPreviewAutomationClickTarget(undefined, context)).toBeUndefined(); |
| 91 | + }); |
56 | 92 | }); |
0 commit comments