webRemoteControlTaskRead.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { describe, expect, it, vi } from "vitest";
  2. import {
  3. markWebRemoteControlBridgeTaskRead,
  4. markWebRemoteControlTaskRead,
  5. } from "@web/webRemoteControlTaskRead.js";
  6. describe("markWebRemoteControlTaskRead", () => {
  7. it("persists the exact mobile task target as read", async () => {
  8. const setTaskUnread = vi.fn(async () => ({}));
  9. const result = await markWebRemoteControlTaskRead({
  10. service: { setTaskUnread },
  11. target: {
  12. taskId: "task-1",
  13. workspacePath: "/workspace/remote",
  14. workspaceIdentity: "ssh://host/workspace/remote",
  15. expectedUnreadAt: 123,
  16. },
  17. });
  18. expect(result).toEqual({ ok: true });
  19. expect(setTaskUnread).toHaveBeenCalledWith({
  20. taskId: "task-1",
  21. workspacePath: "/workspace/remote",
  22. workspaceIdentity: "ssh://host/workspace/remote",
  23. unread: false,
  24. expectedUnreadAt: 123,
  25. });
  26. });
  27. it("reports a failed read mutation without rejecting task navigation", async () => {
  28. const failure = new Error("task index unavailable");
  29. await expect(
  30. markWebRemoteControlTaskRead({
  31. service: {
  32. setTaskUnread: vi.fn(async () => {
  33. throw failure;
  34. }),
  35. },
  36. target: {
  37. taskId: "task-1",
  38. workspacePath: "/workspace/local",
  39. expectedUnreadAt: 123,
  40. },
  41. }),
  42. ).resolves.toEqual({ ok: false, error: failure });
  43. });
  44. it("uses the newly connected remote bridge identity for cross-workspace read clearing", async () => {
  45. const setTaskUnread = vi.fn(async () => ({}));
  46. const result = await markWebRemoteControlBridgeTaskRead({
  47. bridge: {
  48. kind: "remote",
  49. workspacePath: "/workspace/shared-path",
  50. workspaceIdentity: "ssh://new-host/workspace/shared-path",
  51. initialTaskId: "task-cross-workspace",
  52. },
  53. service: { setTaskUnread },
  54. expectedUnreadAt: 456,
  55. });
  56. expect(result).toEqual({ ok: true });
  57. expect(setTaskUnread).toHaveBeenCalledWith({
  58. taskId: "task-cross-workspace",
  59. workspacePath: "/workspace/shared-path",
  60. workspaceIdentity: "ssh://new-host/workspace/shared-path",
  61. unread: false,
  62. expectedUnreadAt: 456,
  63. });
  64. });
  65. });