sidePaneTabStripLayout.test.ts 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { readFileSync } from "node:fs";
  2. import { describe, expect, it } from "vitest";
  3. import { resolveSidePaneTabsOverflow } from "../src/app-shell/sidePaneLayout.js";
  4. const source = readFileSync(
  5. new URL("../src/app-shell/AnimatedSidePanePanel.tsx", import.meta.url),
  6. "utf8",
  7. );
  8. describe("side pane tab strip layout", () => {
  9. it("lets tabs share the viewport before overflowing at their minimum width", () => {
  10. expect(source).toContain("ref={tabsScrollContentRef}");
  11. expect(source).toContain('data-side-pane-tabs-content=""');
  12. expect(source).toContain('className="flex w-full gap-1 py-2.5"');
  13. expect(source).not.toContain(
  14. '<div ref={tabsScrollContentRef} className="flex w-max py-2.5 gap-2">',
  15. );
  16. });
  17. it("keeps the add-tab menu beside tabs until scrolling begins", () => {
  18. expect(source).toContain("!isTabsOverflowing ? addTabMenu : null");
  19. expect(source).toContain("isTabsOverflowing ? addTabMenu : null");
  20. });
  21. it.each([
  22. { tabCount: 3, insideViewportWidth: 220, outsideViewportWidth: 188 },
  23. { tabCount: 4, insideViewportWidth: 284, outsideViewportWidth: 252 },
  24. { tabCount: 5, insideViewportWidth: 348, outsideViewportWidth: 316 },
  25. ])(
  26. "keeps the overflow decision stable when the add button moves for $tabCount tabs",
  27. ({ tabCount, insideViewportWidth, outsideViewportWidth }) => {
  28. expect(
  29. resolveSidePaneTabsOverflow({
  30. addButtonInside: true,
  31. addButtonWidth: 32,
  32. tabCount,
  33. viewportWidth: insideViewportWidth,
  34. }),
  35. ).toBe(true);
  36. expect(
  37. resolveSidePaneTabsOverflow({
  38. addButtonInside: false,
  39. addButtonWidth: 32,
  40. tabCount,
  41. viewportWidth: outsideViewportWidth,
  42. }),
  43. ).toBe(true);
  44. expect(
  45. resolveSidePaneTabsOverflow({
  46. addButtonInside: true,
  47. addButtonWidth: 32,
  48. tabCount,
  49. viewportWidth: insideViewportWidth + 10,
  50. }),
  51. ).toBe(false);
  52. expect(
  53. resolveSidePaneTabsOverflow({
  54. addButtonInside: false,
  55. addButtonWidth: 32,
  56. tabCount,
  57. viewportWidth: outsideViewportWidth + 10,
  58. }),
  59. ).toBe(false);
  60. },
  61. );
  62. });