webRemoteControlFailureScreen.test.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import {
  5. WebRemoteControlFailureScreen,
  6. resolveWebRemoteControlScreenCopy,
  7. } from "../src/webRemoteControlFailureScreen.js";
  8. describe("WebRemoteControlFailureScreen", () => {
  9. it("explains DEVICE_OFFLINE as a desktop disconnected state", () => {
  10. const copy = resolveWebRemoteControlScreenCopy(
  11. { reason: "desktop-disconnected", message: "Desktop device is offline." },
  12. "zh-CN",
  13. );
  14. expect(copy.title).toBe("桌面端已离线");
  15. expect(copy.description).toContain("电脑端已经断开连接");
  16. expect(copy.action).toBe("重新连接");
  17. });
  18. it("explains mobile recovery timeout without blaming desktop offline", () => {
  19. const copy = resolveWebRemoteControlScreenCopy(
  20. {
  21. reason: "connection-recovery-timeout",
  22. message: "Mobile connection did not recover the RPC bridge in time.",
  23. },
  24. "zh-CN",
  25. );
  26. expect(copy.title).toBe("连接恢复超时");
  27. expect(copy.description).toContain("手机端连接没有及时恢复");
  28. expect(copy.description).not.toContain("电脑端已经断开连接");
  29. });
  30. it("explains KICKED as another mobile controller taking over", () => {
  31. const copy = resolveWebRemoteControlScreenCopy(
  32. {
  33. reason: "session-conflict",
  34. message: "Another mobile controller replaced this one.",
  35. },
  36. "zh-CN",
  37. );
  38. expect(copy.title).toBe("已被其他设备接管");
  39. expect(copy.description).toContain("另一台远程控制设备");
  40. });
  41. it("renders structured recovery guidance and the relay detail message", () => {
  42. const html = renderToStaticMarkup(
  43. createElement(WebRemoteControlFailureScreen, {
  44. failure: {
  45. reason: "desktop-disconnected",
  46. message: "Desktop device is offline.",
  47. },
  48. locale: "en-US",
  49. onReload: () => {},
  50. }),
  51. );
  52. expect(html).toContain("Desktop Offline");
  53. expect(html).toContain("What happened");
  54. expect(html).toContain("Desktop device is offline.");
  55. expect(html).toContain("Try Again");
  56. });
  57. });