import { describe, it, expect } from 'vitest';
import { offsetToDelta } from './queue-row-math';

describe('offsetToDelta', () => {
  it('returns 0 for zero offset', () => {
    expect(offsetToDelta(0, 64)).toBe(0);
  });

  it('returns 1 for a full row down', () => {
    expect(offsetToDelta(64, 64)).toBe(1);
  });

  it('rounds half-rows down (just under midpoint)', () => {
    expect(offsetToDelta(31, 64)).toBe(0);
  });

  it('rounds half-rows up (at or past midpoint)', () => {
    expect(offsetToDelta(32, 64)).toBe(1);
  });

  it('handles negative offsets symmetrically (drag up)', () => {
    expect(offsetToDelta(-64, 64)).toBe(-1);
    expect(offsetToDelta(-32, 64)).toBe(0); // Math.round(-0.5) === 0 in JS
  });

  it('handles multi-row offsets', () => {
    expect(offsetToDelta(192, 64)).toBe(3);
    expect(offsetToDelta(-128, 64)).toBe(-2);
  });

  it('returns 0 when rowHeight is non-positive (defensive)', () => {
    expect(offsetToDelta(100, 0)).toBe(0);
    expect(offsetToDelta(100, -1)).toBe(0);
  });

  it('respects the measured row height (e.g., h-14 = 56px)', () => {
    expect(offsetToDelta(56, 56)).toBe(1);
    expect(offsetToDelta(28, 56)).toBe(1); // 0.5 → 1 (half-up)
  });
});
