Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions apps/desktop/src/ipc/methods/preview.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,81 @@ describe("preview IPC methods", () => {
}),
).toThrow();
});

effectIt.effect("returns fulfilled automation press results for known keyboard failures", () =>
Effect.gen(function* () {
const errors = [
new PreviewManager.PreviewAutomationKeyboardWindowNotFocusedError({
tabId: "tab-1",
webContentsId: 41,
}),
new PreviewManager.PreviewAutomationKeyboardFocusedFrameUnsupportedError({
tabId: "tab-1",
webContentsId: 41,
}),
new PreviewManager.PreviewAutomationKeyboardDeliveryNotConfirmedError({
tabId: "tab-1",
webContentsId: 41,
}),
new PreviewManager.PreviewAutomationTargetChangedError({
operation: "press",
tabId: "tab-1",
webContentsId: 41,
}),
];

for (const error of errors) {
const manager = PreviewManager.PreviewManager.of({
automationPress: () => Effect.fail(error),
} as unknown as PreviewManager.PreviewManager["Service"]);

expect(
yield* PreviewIpc.automationPress
.handler({ tabId: "tab-1", input: { key: "x" } })
.pipe(Effect.provideService(PreviewManager.PreviewManager, manager)),
).toEqual({
_tag: "Failure",
error: {
_tag: error._tag,
...(error._tag === "PreviewAutomationTargetChangedError"
? { operation: error.operation }
: {}),
tabId: error.tabId,
webContentsId: error.webContentsId,
},
});
}
}),
);

effectIt.effect("returns a fulfilled automation press success", () =>
Effect.gen(function* () {
const manager = PreviewManager.PreviewManager.of({
automationPress: () => Effect.void,
} as unknown as PreviewManager.PreviewManager["Service"]);

expect(
yield* PreviewIpc.automationPress
.handler({ tabId: "tab-1", input: { key: "x" } })
.pipe(Effect.provideService(PreviewManager.PreviewManager, manager)),
).toEqual({ _tag: "Success" });
}),
);

effectIt.effect("rejects unrelated automation press failures", () =>
Effect.gen(function* () {
const error = new PreviewManager.PreviewTabNotFoundError({ tabId: "tab-1" });
const manager = PreviewManager.PreviewManager.of({
automationPress: () => Effect.fail(error),
} as unknown as PreviewManager.PreviewManager["Service"]);

const exit = yield* PreviewIpc.automationPress
.handler({ tabId: "tab-1", input: { key: "x" } })
.pipe(Effect.provideService(PreviewManager.PreviewManager, manager), Effect.exit);

expect(Exit.isFailure(exit)).toBe(true);
if (Exit.isSuccess(exit)) return;
expect(Cause.findErrorOption(exit.cause)).toEqual(Option.some(error));
}),
);
});
17 changes: 15 additions & 2 deletions apps/desktop/src/ipc/methods/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DesktopPreviewAutomationClickInputSchema,
DesktopPreviewAutomationEvaluateInputSchema,
DesktopPreviewAutomationPressInputSchema,
DesktopPreviewAutomationPressResultSchema,
DesktopPreviewAutomationScrollInputSchema,
DesktopPreviewAutomationStatusSchema,
DesktopPreviewAutomationTypeInputSchema,
Expand Down Expand Up @@ -377,10 +378,22 @@ export const automationType = DesktopIpc.makeIpcMethod({
export const automationPress = DesktopIpc.makeIpcMethod({
channel: IpcChannels.PREVIEW_AUTOMATION_PRESS_CHANNEL,
payload: DesktopPreviewAutomationPressInputSchema,
result: Schema.Void,
result: DesktopPreviewAutomationPressResultSchema,
handler: Effect.fn("desktop.ipc.preview.automationPress")(function* ({ tabId, input }) {
const manager = yield* PreviewManager.PreviewManager;
yield* manager.automationPress(tabId, input);
return yield* manager.automationPress(tabId, input).pipe(
Effect.as({ _tag: "Success" } as const),
Effect.catchTags({
PreviewAutomationKeyboardWindowNotFocusedError: (error) =>
Effect.succeed({ _tag: "Failure", error } as const),
PreviewAutomationKeyboardFocusedFrameUnsupportedError: (error) =>
Effect.succeed({ _tag: "Failure", error } as const),
PreviewAutomationKeyboardDeliveryNotConfirmedError: (error) =>
Effect.succeed({ _tag: "Failure", error } as const),
PreviewAutomationTargetChangedError: (error) =>
Effect.succeed({ _tag: "Failure", error } as const),
}),
);
}),
});

Expand Down
Loading
Loading