columns.client.spec.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { describe, expect, it } from 'vitest'
  2. import { clampWidth, computeColumns } from '../src/client/columns.ts'
  3. describe('clampWidth', () => {
  4. it('clamps into the range and rounds', () => {
  5. expect(clampWidth(250.4, 240, 420)).toBe(250)
  6. expect(clampWidth(100, 240, 420)).toBe(240)
  7. expect(clampWidth(9999, 240, 420)).toBe(420)
  8. })
  9. })
  10. describe('computeColumns', () => {
  11. it('gives each edge column its preference when the center has enough room', () => {
  12. expect(computeColumns(1920, 280, 864)).toEqual({ sidebar: 280, center: 776, rightbar: 864 })
  13. })
  14. it('keeps only the left rail when both panels are closed', () => {
  15. expect(computeColumns(1920, 0, 0)).toEqual({ sidebar: 56, center: 1864, rightbar: 0 })
  16. })
  17. it('clamps sidebar preferences and limits the right panel to 70% of the frame', () => {
  18. expect(computeColumns(3000, 9999, 9999)).toEqual({ sidebar: 420, center: 480, rightbar: 2100 })
  19. expect(computeColumns(1920, 1, 1)).toEqual({ sidebar: 264, center: 1356, rightbar: 300 })
  20. })
  21. it.each([
  22. [1300, 280, 620, 400],
  23. [1100, 280, 420, 400],
  24. [1120, 420, 300, 400],
  25. [1119, 420, 0, 699],
  26. [1024, 420, 0, 604],
  27. [756, 0, 300, 400],
  28. [755, 0, 0, 699],
  29. [455, 0, 0, 399],
  30. [20, 0, 0, 0],
  31. ])('solves frame %i and sidebar %i to right %i and center %i', (viewport, sidebar, rightbar, center) => {
  32. expect(computeColumns(viewport, sidebar, 864)).toEqual({ sidebar: sidebar || 56, center, rightbar })
  33. })
  34. it('does not reduce the wide sidebar to keep a normal right panel open', () => {
  35. expect(computeColumns(1024, 420, 500)).toEqual({ sidebar: 420, center: 604, rightbar: 0 })
  36. })
  37. it('restores a still-open preference when the frame widens', () => {
  38. expect(computeColumns(1100, 280, 864).rightbar).toBe(420)
  39. expect(computeColumns(1920, 280, 864).rightbar).toBe(864)
  40. })
  41. it('leaves a closed right track closed when the frame widens', () => {
  42. expect(computeColumns(755, 0, 0).rightbar).toBe(0)
  43. expect(computeColumns(1920, 0, 0).rightbar).toBe(0)
  44. })
  45. })