remoteConnectionDialogState.test.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. getRemoteConnectionCompletionDialogState,
  4. getRemoteConnectionDirectoryFailureState,
  5. isRemoteConnectionFlowActive,
  6. type RemoteConnectionDialogSnapshot,
  7. } from "@/lib/remoteConnectionDialogState.js";
  8. const baseSnapshot: RemoteConnectionDialogSnapshot = {
  9. currentStep: "device",
  10. loading: false,
  11. connectedSessionId: null,
  12. };
  13. describe("remoteConnectionDialogState", () => {
  14. it("keeps minimized connecting flow active", () => {
  15. const snapshot: RemoteConnectionDialogSnapshot = {
  16. ...baseSnapshot,
  17. currentStep: "connecting",
  18. loading: true,
  19. };
  20. expect(isRemoteConnectionFlowActive(snapshot)).toBe(true);
  21. });
  22. it("keeps connected directory selection active after minimizing", () => {
  23. const snapshot: RemoteConnectionDialogSnapshot = {
  24. ...baseSnapshot,
  25. currentStep: "directory",
  26. connectedSessionId: "session-1",
  27. };
  28. expect(isRemoteConnectionFlowActive(snapshot)).toBe(true);
  29. });
  30. it("does not treat idle device selection as an active connection", () => {
  31. const snapshot: RemoteConnectionDialogSnapshot = {
  32. ...baseSnapshot,
  33. currentStep: "device",
  34. loading: false,
  35. connectedSessionId: null,
  36. };
  37. expect(isRemoteConnectionFlowActive(snapshot)).toBe(false);
  38. });
  39. it("does not treat the failed connecting step as an active connection", () => {
  40. const snapshot: RemoteConnectionDialogSnapshot = {
  41. ...baseSnapshot,
  42. currentStep: "connecting",
  43. loading: false,
  44. connectedSessionId: null,
  45. };
  46. expect(isRemoteConnectionFlowActive(snapshot)).toBe(false);
  47. });
  48. it("reopens minimized dialog at the ready connecting step after connection succeeds", () => {
  49. expect(getRemoteConnectionCompletionDialogState("success")).toEqual({
  50. open: true,
  51. step: "connecting",
  52. });
  53. });
  54. it("jumps straight to the directory step for the online-device direct flow", () => {
  55. // 原型 rail-foot:已有设备可从第 1 步直达第 5 步——在线卡「选择其他目录」成功后不在第 4 步停留。
  56. expect(
  57. getRemoteConnectionCompletionDialogState("success", {
  58. directToDirectory: true,
  59. }),
  60. ).toEqual({
  61. open: true,
  62. step: "directory",
  63. });
  64. });
  65. it("stays on the connecting step when the direct flow fails", () => {
  66. expect(
  67. getRemoteConnectionCompletionDialogState("error", {
  68. directToDirectory: true,
  69. }),
  70. ).toEqual({
  71. open: true,
  72. step: "connecting",
  73. });
  74. });
  75. it("reopens minimized dialog at connecting step after connection fails", () => {
  76. expect(getRemoteConnectionCompletionDialogState("error")).toEqual({
  77. open: true,
  78. step: "connecting",
  79. });
  80. });
  81. it("returns to settings when directory finalization disposed the logical session", () => {
  82. expect(
  83. getRemoteConnectionDirectoryFailureState({
  84. connectedSessionId: "remote-session-1",
  85. sessionStillRegistered: false,
  86. }),
  87. ).toEqual({
  88. connectedSessionId: null,
  89. step: "settings",
  90. });
  91. });
  92. it("keeps directory services available for retry when the logical session survives", () => {
  93. expect(
  94. getRemoteConnectionDirectoryFailureState({
  95. connectedSessionId: "remote-session-1",
  96. sessionStillRegistered: true,
  97. }),
  98. ).toEqual({
  99. connectedSessionId: "remote-session-1",
  100. step: "directory",
  101. });
  102. });
  103. });