queuedSummaryContent.test.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. import { describe, expect, it } from "vitest";
  2. import {
  3. resolveQueuedSummaryPlaybackQueue,
  4. SUMMARY_ROLL_TOTAL_MS,
  5. shouldAnimateQueuedSummaryContent,
  6. shouldRefreshQueuedSummaryContent,
  7. } from "@/ToolCallBlocks/QueuedSummaryContent.js";
  8. describe("summary roll timing", () => {
  9. it("keeps each queued summary step under one second", () => {
  10. expect(SUMMARY_ROLL_TOTAL_MS).toBeLessThan(1000);
  11. });
  12. });
  13. describe("resolveQueuedSummaryPlaybackQueue", () => {
  14. it("keeps queued summaries when the timer fires on time", () => {
  15. expect(resolveQueuedSummaryPlaybackQueue(["read", "search"], 100)).toEqual(["read", "search"]);
  16. });
  17. it("skips stale queued summaries when the timer fires late", () => {
  18. // Bugfix: 主线程卡顿后不要补播过期摘要,否则用户会看到旧状态继续滚动。
  19. expect(resolveQueuedSummaryPlaybackQueue(["read", "search"], 300)).toEqual(["search"]);
  20. });
  21. });
  22. describe("shouldAnimateQueuedSummaryContent", () => {
  23. it("allows callers to disable summary animation explicitly", () => {
  24. expect(
  25. shouldAnimateQueuedSummaryContent({
  26. enabled: true,
  27. disableAnimation: true,
  28. reducedMotion: false,
  29. }),
  30. ).toBe(false);
  31. });
  32. it("keeps animation enabled when no disable switch is set", () => {
  33. expect(
  34. shouldAnimateQueuedSummaryContent({
  35. enabled: true,
  36. reducedMotion: false,
  37. }),
  38. ).toBe(true);
  39. });
  40. });
  41. describe("shouldRefreshQueuedSummaryContent", () => {
  42. it("refreshes streaming text in place without changing the queue key", () => {
  43. expect(
  44. shouldRefreshQueuedSummaryContent(
  45. { key: "message:2", refreshVersion: "正在", trailingText: "2 events" },
  46. { key: "message:2", refreshVersion: "正在检查", trailingText: "2 events" },
  47. ),
  48. ).toBe(true);
  49. expect(
  50. shouldRefreshQueuedSummaryContent(
  51. { key: "message:2", refreshVersion: "正在检查", trailingText: "2 events" },
  52. { key: "message:3", refreshVersion: "下一条", trailingText: "3 events" },
  53. ),
  54. ).toBe(false);
  55. });
  56. });