pptxElementReferencePreview.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { describe, expect, it } from "vitest";
  2. import type { PptxElementReference } from "@/lib/pptxElementReference.js";
  3. import { createPptxElementReferencePreviewSource } from "@/lib/pptxElementReferencePreview.js";
  4. function makeReference(
  5. overrides: Partial<PptxElementReference> = {},
  6. ): PptxElementReference {
  7. return {
  8. bounds: { x: 10, y: 20, width: 300, height: 80 },
  9. capturedAt: 1,
  10. id: "reference-1",
  11. nodeId: "7",
  12. nodeName: "Title",
  13. nodeType: "shape",
  14. remoteSessionId: "remote-1",
  15. slideIndex: 2,
  16. slidePart: "ppt/slides/slide3.xml",
  17. sourceFingerprint: `sha256:${"a".repeat(64)}`,
  18. sourcePath: "/workspace/docs/deck.pptx",
  19. sourceTitle: "deck.pptx",
  20. workspaceIdentity: "ssh:user@host:/workspace",
  21. workspacePath: "/workspace",
  22. zIndex: 1,
  23. ...overrides,
  24. };
  25. }
  26. describe("PPTX element reference preview source", () => {
  27. it("maps a scoped reference to a repeatable file and page navigation request", () => {
  28. const scope = {
  29. workspacePath: "/mounted/workspace",
  30. workspaceIdentity: "ssh:user@host:/workspace",
  31. remoteSessionId: "remote-1",
  32. };
  33. const first = createPptxElementReferencePreviewSource(
  34. makeReference(),
  35. scope,
  36. );
  37. const second = createPptxElementReferencePreviewSource(
  38. makeReference(),
  39. scope,
  40. );
  41. expect(first).toMatchObject({
  42. type: "pptx",
  43. title: "deck.pptx",
  44. path: "/workspace/docs/deck.pptx",
  45. workspacePath: "/workspace",
  46. workspaceIdentity: "ssh:user@host:/workspace",
  47. workspaceRemoteSessionId: "remote-1",
  48. referenceNavigation: {
  49. pageIndex: 2,
  50. expectedSourceFingerprint: `sha256:${"a".repeat(64)}`,
  51. },
  52. });
  53. expect(first?.referenceNavigation.requestId).not.toBe(
  54. second?.referenceNavigation.requestId,
  55. );
  56. });
  57. it("rejects references outside the current workspace, remote session, or path", () => {
  58. const scope = {
  59. workspacePath: "/workspace",
  60. workspaceIdentity: "ssh:user@host:/workspace",
  61. remoteSessionId: "remote-1",
  62. };
  63. expect(
  64. createPptxElementReferencePreviewSource(
  65. makeReference({ remoteSessionId: "remote-2" }),
  66. scope,
  67. ),
  68. ).toBeNull();
  69. expect(
  70. createPptxElementReferencePreviewSource(
  71. makeReference({ workspaceIdentity: "ssh:user@other:/workspace" }),
  72. scope,
  73. ),
  74. ).toBeNull();
  75. expect(
  76. createPptxElementReferencePreviewSource(
  77. makeReference({ sourcePath: "/outside/deck.pptx" }),
  78. scope,
  79. ),
  80. ).toBeNull();
  81. });
  82. });