workbenchDragDrop.test.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. WORKBENCH_SESSION_DRAG_MIME,
  4. clearActiveWorkbenchSessionDragPayload,
  5. parseWorkbenchSessionDragPayload,
  6. serializeWorkbenchSessionDragPayload,
  7. setActiveWorkbenchSessionDragPayload,
  8. } from "@/v4/workbenchDragDrop.js";
  9. describe("workbench session drag/drop helpers", () => {
  10. it("serializes and parses session drag payloads", () => {
  11. const serialized = serializeWorkbenchSessionDragPayload({
  12. kind: "zcode/session",
  13. workspacePath: "/ws/a",
  14. workspaceIdentity: " remote:ssh:host:/ws/a ",
  15. remoteSessionId: "remote-1",
  16. sessionId: "sess-a",
  17. });
  18. expect(serialized).toContain("sess-a");
  19. expect(
  20. parseWorkbenchSessionDragPayload({
  21. types: [WORKBENCH_SESSION_DRAG_MIME],
  22. getData: () => serialized,
  23. }),
  24. ).toEqual({
  25. kind: "zcode/session",
  26. workspacePath: "/ws/a",
  27. workspaceIdentity: " remote:ssh:host:/ws/a ",
  28. remoteSessionId: "remote-1",
  29. sessionId: "sess-a",
  30. });
  31. });
  32. it("rejects missing, malformed, or non-session drag payloads", () => {
  33. expect(
  34. parseWorkbenchSessionDragPayload({
  35. types: [],
  36. getData: () => "",
  37. }),
  38. ).toBeNull();
  39. expect(
  40. parseWorkbenchSessionDragPayload({
  41. types: [WORKBENCH_SESSION_DRAG_MIME],
  42. getData: () => "{bad json",
  43. }),
  44. ).toBeNull();
  45. expect(
  46. parseWorkbenchSessionDragPayload({
  47. types: [WORKBENCH_SESSION_DRAG_MIME],
  48. getData: () => JSON.stringify({ kind: "other" }),
  49. }),
  50. ).toBeNull();
  51. });
  52. it("falls back to the active renderer-local payload when dragover cannot read data", () => {
  53. const payload = {
  54. kind: "zcode/session" as const,
  55. workspacePath: "/ws/a",
  56. sessionId: "sess-a",
  57. };
  58. setActiveWorkbenchSessionDragPayload(payload);
  59. expect(
  60. parseWorkbenchSessionDragPayload({
  61. types: [WORKBENCH_SESSION_DRAG_MIME],
  62. getData: () => "",
  63. }),
  64. ).toEqual(payload);
  65. clearActiveWorkbenchSessionDragPayload();
  66. expect(
  67. parseWorkbenchSessionDragPayload({
  68. types: [WORKBENCH_SESSION_DRAG_MIME],
  69. getData: () => "",
  70. }),
  71. ).toBeNull();
  72. });
  73. });