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

function tabbableChild(host) {
  const btn = document.createElement('button');
  host.appendChild(btn);
  return btn;
}

describe('roving-tabindex', () => {
  beforeEach(resetDOM);

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

  it('disconnect cleans up', () => {
    const host = mountHost();
    tabbableChild(host);
    const inst = connectTrait(rovingTabindex, host);
    expect(() => inst.disconnect(host)).not.toThrow();
  });
});
