import { describe, it, expect, beforeEach } from 'vitest';
import { inertiaDrag } from './inertia-drag.js';
import { mountHost, connectTrait, resetDOM } from '../test-helpers.js';

function pointer(host, type, x, y) {
  host.dispatchEvent(new PointerEvent(type, { clientX: x, clientY: y, pointerId: 1, bubbles: true }));
}

describe('inertia-drag', () => {
  beforeEach(resetDOM);

  it('connect attaches without throwing', () => {
    const host = mountHost();
    expect(() => connectTrait(inertiaDrag, host)).not.toThrow();
  });

  it('drag sequence does not throw + disconnect cleans up', () => {
    const host = mountHost();
    const inst = connectTrait(inertiaDrag, host);
    pointer(host, 'pointerdown', 0, 0);
    pointer(host, 'pointermove', 30, 30);
    pointer(host, 'pointerup', 30, 30);
    expect(() => inst.disconnect(host)).not.toThrow();
    expect(host.hasAttribute('data-inertia-drag-coasting')).toBe(false);
  });

  it('respects [disabled] — pointerdown is a no-op', () => {
    const host = mountHost('div', { disabled: '' });
    connectTrait(inertiaDrag, host);
    pointer(host, 'pointerdown', 0, 0);
    expect(host.hasAttribute('data-inertia-drag-coasting')).toBe(false);
  });
});
