webRemoteControlConnectingScreen.test.ts 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import { createElement } from "react";
  2. import { renderToStaticMarkup } from "react-dom/server";
  3. import { describe, expect, it } from "vitest";
  4. import { WebRemoteControlLoadingScreen } from "#src/web-remote-control/views.js";
  5. const render = (props: Parameters<typeof WebRemoteControlLoadingScreen>[0]) =>
  6. renderToStaticMarkup(createElement(WebRemoteControlLoadingScreen, props));
  7. describe("连接过程页", () => {
  8. it.each(["zh-CN", "en-US"] as const)("%s 显示目标电脑、平台图标与当前阶段", (locale) => {
  9. const html = render({
  10. state: "authenticating",
  11. locale,
  12. device: { name: "Alice’s MacBook", platform: "darwin" },
  13. });
  14. expect(html).toContain(
  15. locale === "zh-CN" ? "正在连接 Alice’s MacBook" : "Connecting to Alice’s MacBook",
  16. );
  17. expect(html).toContain(locale === "zh-CN" ? "正在认证设备…" : "Authenticating device…");
  18. expect(html).toContain('data-device-platform-icon="darwin"');
  19. expect(html.match(/data-step-state="done"/g)).toHaveLength(1);
  20. expect(html).toMatch(/aria-current="step"[^>]*data-step-state="active"/);
  21. });
  22. it("没有名字和平台时用通用文案与电脑图标;重连不高亮进度并补充说明", () => {
  23. const html = render({ state: "reconnecting", locale: "zh-CN" });
  24. expect(html).toContain("正在连接电脑");
  25. expect(html).toContain('data-device-platform-icon="unknown"');
  26. expect(html).toContain("连接中断,正在重连…");
  27. expect(html).toContain("网络或休眠恢复后会自动重连,请稍候。");
  28. expect(html.match(/data-step-state="idle"/g)).toHaveLength(4);
  29. expect(html).not.toContain('aria-current="step"');
  30. });
  31. it("配对完成进入最后一段", () => {
  32. const html = render({ state: "paired", locale: "en-US", device: { name: "PC" } });
  33. expect(html).toContain("Paired. Loading workspace…");
  34. expect(html.match(/data-step-state="done"/g)).toHaveLength(3);
  35. });
  36. });