import { describe, it, expect } from 'vitest';
import { shouldCollapseNav } from './TopBar';

describe('shouldCollapseNav', () => {
  it('does not collapse while widths are unmeasured (avoids hamburger flash)', () => {
    expect(shouldCollapseNav(0, 0, 0)).toBe(false);
    expect(shouldCollapseNav(1000, 300, 0)).toBe(false); // navWidth 0 = not measured yet
  });

  it('keeps tabs when the nav fits the leftover space (minus buffer)', () => {
    // row 1000, fixed 300 → 700 available, minus 40 buffer = 660. nav 600 fits.
    expect(shouldCollapseNav(1000, 300, 600)).toBe(false);
  });

  it('collapses when the nav no longer fits', () => {
    // 700 available - 40 buffer = 660. nav 700 does not fit.
    expect(shouldCollapseNav(1000, 300, 700)).toBe(true);
  });

  it('respects the buffer at the boundary', () => {
    // available 660 after buffer; nav exactly 660 fits, 661 collapses.
    expect(shouldCollapseNav(1000, 300, 660)).toBe(false);
    expect(shouldCollapseNav(1000, 300, 661)).toBe(true);
  });

  it('honors a custom buffer', () => {
    expect(shouldCollapseNav(1000, 300, 690, 10)).toBe(false); // 690 <= 690
    expect(shouldCollapseNav(1000, 300, 691, 10)).toBe(true);
  });
});
