rollingToolbarLabel.test.ts 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // @vitest-environment jsdom
  2. import { act, createElement } from "react";
  3. import { expect, it, vi } from "vitest";
  4. import { createRoot } from "react-dom/client";
  5. import { RollingToolbarLabel } from "@/chat-input-toolbar/RollingToolbarLabel.js";
  6. // 模型触发器把标签的第二层 span 设为块级省略行;减少动画不能让它命中两个文字片段。
  7. it.each([false, true])("系统减少动画=%s 时供应商和模型共用一个截断行", async (reducedMotion) => {
  8. const host = document.createElement("div");
  9. document.body.append(host);
  10. const root = createRoot(host);
  11. vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
  12. vi.stubGlobal("matchMedia", () => ({
  13. matches: reducedMotion,
  14. addEventListener() {},
  15. removeEventListener() {},
  16. }));
  17. try {
  18. await act(async () =>
  19. root.render(
  20. createElement(RollingToolbarLabel, {
  21. label: "ZAPI (Anthropic) / GLM-5.3-Highspeed-fusion",
  22. prefix: "ZAPI (Anthropic) / ",
  23. prefixClassName: "inline",
  24. value: "GLM-5.3-Highspeed-fusion",
  25. }),
  26. ),
  27. );
  28. const lines = host.querySelectorAll(":scope > span > span");
  29. expect(lines).toHaveLength(1);
  30. expect(lines[0].textContent).toBe("ZAPI (Anthropic) / GLM-5.3-Highspeed-fusion");
  31. } finally {
  32. await act(async () => root.unmount());
  33. host.remove();
  34. vi.unstubAllGlobals();
  35. }
  36. });