import { describe, it, expect, beforeEach } from 'vitest';
import { tossable } from './tossable.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('tossable', () => {
  beforeEach(resetDOM);

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

  it('drag sequence completes without throwing + disconnect cleans up', () => {
    const host = mountHost();
    const inst = connectTrait(tossable, host);
    pointer(host, 'pointerdown', 0, 0);
    pointer(host, 'pointermove', 50, 0);
    pointer(host, 'pointerup', 50, 0);
    expect(() => inst.disconnect(host)).not.toThrow();
    expect(host.hasAttribute('data-tossable-flying')).toBe(false);
  });

  it('respects data-tossable-bounds config', () => {
    const host = mountHost('div', { 'data-tossable-bounds': 'parent' });
    expect(() => connectTrait(tossable, host)).not.toThrow();
  });
});
