HighspeedModelIndicator.test.ts 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // @vitest-environment jsdom
  2. import { createElement } from "react";
  3. import { cleanup, fireEvent, render, screen } from "@testing-library/react";
  4. import { afterEach, describe, expect, it } from "vitest";
  5. import { HighspeedModelIndicator } from "@/highspeed/HighspeedModelIndicator.js";
  6. import { TooltipProvider } from "@/components/ui/tooltip.js";
  7. import { ZCodeIntlProvider } from "@/i18n/IntlProvider.js";
  8. afterEach(cleanup);
  9. function renderIndicator(sweepActive = false, animateEntrance = true) {
  10. return render(
  11. createElement(
  12. ZCodeIntlProvider,
  13. { initialLocale: "zh-CN" },
  14. createElement(
  15. TooltipProvider,
  16. null,
  17. createElement(HighspeedModelIndicator, {
  18. model: "GLM-5.3",
  19. originalModel: "GLM-5.2",
  20. sweepActive,
  21. animateEntrance,
  22. }),
  23. ),
  24. ),
  25. );
  26. }
  27. /** 翻页动效挂在图标与文字外层的 motion 容器上。 */
  28. function readFlipContainerOpacity(container: HTMLElement): string | undefined {
  29. const flip = container.querySelector('[data-highspeed-model-icon="true"]')?.parentElement;
  30. return flip?.style.opacity;
  31. }
  32. describe("HighspeedModelIndicator", () => {
  33. it("renders the draw model as a read-only Highspeed identity", () => {
  34. const { container, getByLabelText } = renderIndicator();
  35. const modelIcon = container.querySelector('[data-highspeed-model-icon="true"]');
  36. expect(getByLabelText("GLM-5.3 HighSpeed")).toBeTruthy();
  37. expect(container.textContent).toContain("GLM-5.3 HighSpeed");
  38. expect(modelIcon?.tagName).toBe("IMG");
  39. expect(decodeURIComponent(modelIcon?.getAttribute("src") ?? "")).toContain("stroke='#A888F2'");
  40. expect(getByLabelText("GLM-5.3 HighSpeed").className).toContain("@max-xl/composer:size-7");
  41. expect(container.querySelector(".highspeed-model-trigger-label-sweep")?.className).toContain(
  42. "@xl/composer:inline-flex",
  43. );
  44. expect(container.querySelector("button")).toBeNull();
  45. expect(container.querySelector('[data-chat-toolbar-popover-trigger="true"]')).toBeNull();
  46. });
  47. it("在 hover 时展示加速前的原模型", async () => {
  48. renderIndicator();
  49. fireEvent.pointerMove(screen.getByLabelText("GLM-5.3 HighSpeed"), {
  50. pointerType: "mouse",
  51. });
  52. expect((await screen.findAllByText("原模型:GLM-5.2")).length).toBeGreaterThan(0);
  53. expect(screen.queryByText(/剩余时间/)).toBeNull();
  54. });
  55. it("draw 新命中从翻页起点入场;切回或恢复时直接呈现静止标识", () => {
  56. const activation = renderIndicator(false, true);
  57. expect(readFlipContainerOpacity(activation.container)).toBe("0");
  58. activation.unmount();
  59. const restore = renderIndicator(false, false);
  60. expect(readFlipContainerOpacity(restore.container)).toBe("1");
  61. });
  62. it("activates the one-shot label sweep without adding interaction", () => {
  63. const { container } = renderIndicator(true);
  64. expect(
  65. container.querySelector(".highspeed-model-trigger-label-sweep.is-sweep-active"),
  66. ).not.toBeNull();
  67. expect(container.querySelector("button")).toBeNull();
  68. });
  69. });