v4ConversationTimelineHeaderSlot.test.ts 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. const source = readFileSync("packages/ui/src/v4/ConversationTimeline.tsx", "utf8");
  4. describe("ConversationTimeline header slot", () => {
  5. it("headerSlot 落在被 mask 的消息层内,不会从 sticky composer 下方透出", () => {
  6. // Bug 根因:headerSlot 起初渲染在消息层之外,而淡出 mask 只作用于消息层,
  7. // 于是分享导入的只读内容会一直显示在输入框下方。
  8. const messageLayerIndex = source.indexOf('data-v4-timeline-message-layer="true"');
  9. const headerSlotIndex = source.indexOf('data-v4-timeline-header-slot="true"');
  10. const virtualHistoryIndex = source.indexOf('data-v4-timeline-virtual-history="true"');
  11. expect(messageLayerIndex).toBeGreaterThan(-1);
  12. expect(headerSlotIndex).toBeGreaterThan(messageLayerIndex);
  13. expect(headerSlotIndex).toBeLessThan(virtualHistoryIndex);
  14. });
  15. it("headerSlot 套用与实时消息列相同的宽度类", () => {
  16. // 桌面端外层没有 rail 限宽,不套用列宽会整条铺满,比正常对话明显更宽。
  17. const headerSlotIndex = source.indexOf('data-v4-timeline-header-slot="true"');
  18. const headerSlotBlock = source.slice(headerSlotIndex, headerSlotIndex + 400);
  19. expect(headerSlotBlock).toContain("contentWidthClassName");
  20. expect(headerSlotBlock).toContain("summaryPanelInlineOffsetClassName");
  21. });
  22. it("虚拟窗口按 headerSlot 高度做 scrollMargin 换算", () => {
  23. // 不告知这段偏移,虚拟窗口会整体错位一个 header 高度,滚到的位置是空白。
  24. expect(source).toContain("scrollMargin: headerSlotHeight");
  25. expect(source).toContain("translateY(${virtualRow.start - headerSlotHeight}px)");
  26. });
  27. it("rows 为空但有 headerSlot 时仍渲染消息层", () => {
  28. // 刚导入的会话没有任何实时 row,只读块必须照样出现。
  29. expect(source).toContain("renderUnits.length === 0 && !headerSlot ?");
  30. });
  31. it("headerSlot 异步增高时继续保持时间线吸底", () => {
  32. // 导入请求首次吸底时只读块可能尚未完成测高;高度变化必须重新执行底部锚定。
  33. const anchorStart = source.indexOf("// 底部锚定:内容变化");
  34. const anchorEffectStart = source.indexOf("useLayoutEffect(() => {", anchorStart);
  35. const anchorEnd = source.indexOf("useLayoutEffect(() => {", anchorEffectStart + 1);
  36. expect(anchorStart).toBeGreaterThan(-1);
  37. expect(source.slice(anchorStart, anchorEnd)).toContain("headerSlotHeight");
  38. });
  39. });