session-panel-width.test.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { describe, expect, test } from "bun:test"
  2. import {
  3. clampSessionPanelWidth,
  4. REVIEW_PANE_WIDTH_MIN,
  5. REVIEW_PANE_WIDTH_MIN_SPLIT,
  6. SESSION_PANEL_WIDTH_MIN,
  7. sessionPanelWidthMax,
  8. } from "./session-panel-width"
  9. describe("sessionPanelWidthMax", () => {
  10. test("reserves the unified review pane minimum", () => {
  11. expect(sessionPanelWidthMax({ available: 1700, split: false })).toBe(1700 - REVIEW_PANE_WIDTH_MIN)
  12. })
  13. test("reserves a larger minimum for split diffs", () => {
  14. expect(sessionPanelWidthMax({ available: 1700, split: true })).toBe(1700 - REVIEW_PANE_WIDTH_MIN_SPLIT)
  15. expect(REVIEW_PANE_WIDTH_MIN_SPLIT).toBeGreaterThan(REVIEW_PANE_WIDTH_MIN)
  16. })
  17. test("lets the chat panel take everything beyond the review pane minimum", () => {
  18. // Regression: the old cap was 45% of the window, forcing the review pane
  19. // to at least 55% of the window regardless of content.
  20. const available = 3440
  21. expect(sessionPanelWidthMax({ available, split: false })).toBeGreaterThan(available * 0.45)
  22. })
  23. test("never drops below the chat panel minimum on small windows", () => {
  24. expect(sessionPanelWidthMax({ available: 600, split: true })).toBe(SESSION_PANEL_WIDTH_MIN)
  25. expect(sessionPanelWidthMax({ available: 0, split: false })).toBe(SESSION_PANEL_WIDTH_MIN)
  26. })
  27. })
  28. describe("clampSessionPanelWidth", () => {
  29. test("keeps widths already within the limit", () => {
  30. expect(clampSessionPanelWidth({ width: 800, available: 1700, split: false })).toBe(800)
  31. })
  32. test("forces the width down when the window shrinks", () => {
  33. expect(clampSessionPanelWidth({ width: 1600, available: 1700, split: false })).toBe(1700 - REVIEW_PANE_WIDTH_MIN)
  34. expect(clampSessionPanelWidth({ width: 1600, available: 1700, split: true })).toBe(
  35. 1700 - REVIEW_PANE_WIDTH_MIN_SPLIT,
  36. )
  37. })
  38. test("holds the chat panel minimum when there is no room for both", () => {
  39. expect(clampSessionPanelWidth({ width: 1600, available: 700, split: true })).toBe(SESSION_PANEL_WIDTH_MIN)
  40. })
  41. test("skips clamping before the layout is measured", () => {
  42. expect(clampSessionPanelWidth({ width: 1600, available: undefined, split: false })).toBe(1600)
  43. })
  44. })