remoteAccessibility.test.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, render, screen } from "@testing-library/react";
  4. import { afterEach, expect, it } from "vitest";
  5. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  6. import { Dialog, DialogContent, DialogTitle } from "@/components/ui/dialog.js";
  7. import { RemoteConnectionStatusTag } from "@/remote-connection/RemoteConnectionTags.js";
  8. import { RemoteConnectionNavigationDot } from "@/remote-connection/RemoteConnectionNavigationDot.js";
  9. import { resolveRemoteConnectionPresentation } from "@/lib/remoteConnectionPresentation.js";
  10. afterEach(cleanup);
  11. it.each([
  12. ["zh-CN", "关闭"],
  13. ["en-US", "Close"],
  14. ] as const)("%s 对话框关闭按钮有本地化名称", (locale, close) => {
  15. render(
  16. createElement(
  17. ZCodeIntlProvider,
  18. { initialLocale: locale },
  19. createElement(
  20. Dialog,
  21. { open: true },
  22. createElement(
  23. DialogContent,
  24. { "aria-describedby": undefined },
  25. createElement(DialogTitle, null, "Connection"),
  26. ),
  27. ),
  28. ),
  29. );
  30. expect(screen.getByRole("button", { name: close })).toBeTruthy();
  31. });
  32. it("状态变化在 live region 中读出,导航状态点有语义和名称", () => {
  33. const view = (state: "online" | "offline") =>
  34. createElement(
  35. ZCodeIntlProvider,
  36. { initialLocale: "zh-CN" },
  37. createElement(RemoteConnectionStatusTag, { status: state }),
  38. createElement(RemoteConnectionNavigationDot, {
  39. presentation: resolveRemoteConnectionPresentation({ state }),
  40. }),
  41. );
  42. const { rerender } = render(view("online"));
  43. expect(screen.getByRole("status").textContent).toContain("已连接");
  44. expect(screen.getByRole("img", { name: "已连接" })).toBeTruthy();
  45. rerender(view("offline"));
  46. expect(screen.getByRole("status").textContent).toContain("未连接");
  47. expect(screen.getByRole("img", { name: "未连接" })).toBeTruthy();
  48. });