markdownTableStickyScrollbar.test.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. import {
  4. resolveMarkdownTableStickyScrollbarMode,
  5. resolveMarkdownTableStickyScrollbarOffset,
  6. } from "@/components/ai-elements/markdown-table.js";
  7. describe("resolveMarkdownTableStickyScrollbarMode", () => {
  8. it("enables sticky markdown table scrollbars for tall content", () => {
  9. expect(
  10. resolveMarkdownTableStickyScrollbarMode({
  11. stickyScrollbarDisabled: false,
  12. viewportHeight: 800,
  13. dockHeight: 200,
  14. tableHeight: 500,
  15. }),
  16. ).toBe(true);
  17. });
  18. it("disables sticky markdown table scrollbars for opted-out subagent content", () => {
  19. expect(
  20. resolveMarkdownTableStickyScrollbarMode({
  21. stickyScrollbarDisabled: true,
  22. viewportHeight: 256,
  23. dockHeight: 200,
  24. tableHeight: 220,
  25. }),
  26. ).toBe(false);
  27. });
  28. });
  29. describe("resolveMarkdownTableStickyScrollbarOffset", () => {
  30. it("pins a long table scrollbar to the visible timeline bottom", () => {
  31. expect(
  32. resolveMarkdownTableStickyScrollbarOffset({
  33. frameTop: -87,
  34. frameBottom: 1211,
  35. scrollbarHeight: 26,
  36. viewportBottom: 921,
  37. }),
  38. ).toBe(-290);
  39. });
  40. it("keeps the scrollbar inside the current table boundaries", () => {
  41. expect(
  42. resolveMarkdownTableStickyScrollbarOffset({
  43. frameTop: 950,
  44. frameBottom: 2248,
  45. scrollbarHeight: 26,
  46. viewportBottom: 921,
  47. }),
  48. ).toBe(-1272);
  49. expect(
  50. resolveMarkdownTableStickyScrollbarOffset({
  51. frameTop: -1400,
  52. frameBottom: -102,
  53. scrollbarHeight: 26,
  54. viewportBottom: 921,
  55. }),
  56. ).toBe(0);
  57. });
  58. });
  59. describe("markdown table sticky scrollbar lifecycle", () => {
  60. it("keeps the scrollbar mounted across visibility changes and observes V4 composer dock changes", () => {
  61. const source = readFileSync(
  62. "packages/ui/src/components/ai-elements/markdown-table.tsx",
  63. "utf8",
  64. );
  65. expect(source).toContain('className="my-0 flex min-w-0 flex-col gap-2"');
  66. expect(source).toContain(
  67. 'data-markdown-table-virtual-scroll-visible={virtualScrollbarVisible ? "true" : "false"}',
  68. );
  69. expect(source).toContain(
  70. 'data-markdown-table-virtual-scroll-sticky={',
  71. );
  72. expect(source).toContain('data-markdown-table-frame=""');
  73. expect(source).not.toContain("{virtualScrollbarVisible ? (");
  74. expect(source).toContain(
  75. "}, [virtualScrollbarSticky, virtualScrollbarVisible]);",
  76. );
  77. expect(source).toContain("resizeObserver?.observe(observedDock)");
  78. expect(source).toContain("new MutationObserver(syncDockObservation)");
  79. expect(source).toContain("readMarkdownTableBackToBottomClearance(root)");
  80. });
  81. });