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

describe('hoverable', () => {
  beforeEach(resetDOM);

  it('pointerenter sets data-hoverable-hover; pointerleave clears it', () => {
    const host = mountHost();
    connectTrait(hoverable, host);
    host.dispatchEvent(new PointerEvent('pointerenter'));
    expect(host.hasAttribute('data-hoverable-hover')).toBe(true);
    host.dispatchEvent(new PointerEvent('pointerleave'));
    expect(host.hasAttribute('data-hoverable-hover')).toBe(false);
  });

  it('disconnect clears attribute even mid-hover', () => {
    const host = mountHost();
    const inst = connectTrait(hoverable, host);
    host.dispatchEvent(new PointerEvent('pointerenter'));
    inst.disconnect(host);
    expect(host.hasAttribute('data-hoverable-hover')).toBe(false);
  });
});
