HighspeedModelIndicator.test.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. expect(getByLabelText("GLM-5.3 HighSpeed")).toBeTruthy();
  36. expect(container.textContent).toContain("GLM-5.3 HighSpeed");
  37. expect(container.querySelector("button")).toBeNull();
  38. expect(container.querySelector('[data-chat-toolbar-popover-trigger="true"]')).toBeNull();
  39. });
  40. it("在 hover 时展示加速前的原模型", async () => {
  41. renderIndicator();
  42. fireEvent.pointerMove(screen.getByLabelText("GLM-5.3 HighSpeed"), {
  43. pointerType: "mouse",
  44. });
  45. expect((await screen.findAllByText("原模型:GLM-5.2")).length).toBeGreaterThan(0);
  46. expect(screen.queryByText(/剩余时间/)).toBeNull();
  47. });
  48. it("draw 新命中从翻页起点入场;切回或恢复时直接呈现静止标识", () => {
  49. const activation = renderIndicator(false, true);
  50. expect(readFlipContainerOpacity(activation.container)).toBe("0");
  51. activation.unmount();
  52. const restore = renderIndicator(false, false);
  53. expect(readFlipContainerOpacity(restore.container)).toBe("1");
  54. });
  55. });