rollingToolbarLabel.test.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // @vitest-environment jsdom
  2. import { act, createElement } from "react";
  3. import { renderToStaticMarkup } from "react-dom/server";
  4. import { describe, expect, it, vi } from "vitest";
  5. import { createRoot } from "react-dom/client";
  6. import { RollingToolbarLabel } from "@/chat-input-toolbar/RollingToolbarLabel.js";
  7. describe("RollingToolbarLabel", () => {
  8. it("uses a taller line box for toolbar labels", () => {
  9. const html = renderToStaticMarkup(createElement(RollingToolbarLabel, { label: "Planning" }));
  10. expect(html).toContain("h-[1.3em]");
  11. expect(html).toContain("leading-[1.25]");
  12. expect(html).not.toContain("h-[1.15em]");
  13. expect(html).not.toContain("leading-none");
  14. });
  15. it("renders a responsive prefix separately while preserving the full title", () => {
  16. const html = renderToStaticMarkup(
  17. createElement(RollingToolbarLabel, {
  18. label: "deepseek/deepseek-v4-flash",
  19. prefix: "deepseek/",
  20. prefixClassName: "hidden @xl/composer:inline",
  21. value: "deepseek-v4-flash",
  22. }),
  23. );
  24. expect(html).toContain('title="deepseek/deepseek-v4-flash"');
  25. expect(html).toContain('class="hidden @xl/composer:inline"');
  26. expect(html).toContain("deepseek/");
  27. expect(html).toContain("deepseek-v4-flash");
  28. });
  29. });
  30. // 模型触发器把标签的第二层 span 设为块级省略行;减少动画不能让它命中两个文字片段。
  31. it.each([false, true])("系统减少动画=%s 时供应商和模型共用一个截断行", async (reducedMotion) => {
  32. const host = document.createElement("div");
  33. document.body.append(host);
  34. const root = createRoot(host);
  35. vi.stubGlobal("IS_REACT_ACT_ENVIRONMENT", true);
  36. vi.stubGlobal("matchMedia", () => ({
  37. matches: reducedMotion,
  38. addEventListener() {},
  39. removeEventListener() {},
  40. }));
  41. try {
  42. await act(async () =>
  43. root.render(
  44. createElement(RollingToolbarLabel, {
  45. label: "ZAPI (Anthropic) / GLM-5.3-Highspeed-fusion",
  46. prefix: "ZAPI (Anthropic) / ",
  47. prefixClassName: "inline",
  48. value: "GLM-5.3-Highspeed-fusion",
  49. }),
  50. ),
  51. );
  52. const lines = host.querySelectorAll(":scope > span > span");
  53. expect(lines).toHaveLength(1);
  54. expect(lines[0].textContent).toBe("ZAPI (Anthropic) / GLM-5.3-Highspeed-fusion");
  55. } finally {
  56. await act(async () => root.unmount());
  57. host.remove();
  58. vi.unstubAllGlobals();
  59. }
  60. });