Skip to content

Commit 30f017d

Browse files
t3dotgggb1095
authored andcommitted
fix(web): reject undispatched preview clicks
1 parent 8f12a7a commit 30f017d

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

‎apps/web/src/components/preview/previewAutomationErrors.test.ts‎

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
1+
import {
2+
type DesktopPreviewAutomationClickResult,
3+
EnvironmentId,
4+
ThreadId,
5+
} from "@t3tools/contracts";
26
import { describe, expect, it } from "vite-plus/test";
37

48
import {
59
confirmPreviewAutomationClickTarget,
10+
PreviewAutomationOperationError,
611
PreviewAutomationTargetLookupHostError,
712
} from "./previewAutomationErrors";
813

14+
type NotSentClickResult = Extract<DesktopPreviewAutomationClickResult, { _tag: "NotSent" }>;
15+
916
describe("confirmPreviewAutomationClickTarget", () => {
1017
const context = {
1118
requestId: "request-1",
@@ -53,4 +60,33 @@ describe("confirmPreviewAutomationClickTarget", () => {
5360
expect(disabled.message).not.toContain("secret");
5461
expect(ambiguous.message).not.toContain("secret");
5562
});
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+
});
5692
});

‎apps/web/src/components/preview/previewAutomationErrors.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export function confirmPreviewAutomationClickTarget(
195195
matchCount: result.matchCount,
196196
});
197197
default:
198-
return result;
198+
throw new PreviewAutomationOperationError({ ...context, cause: result });
199199
}
200200
}
201201

0 commit comments

Comments
 (0)