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

describe('sound-feedback', () => {
  beforeEach(resetDOM);

  it('connect sets data-sound-feedback-active', () => {
    const host = mountHost();
    connectTrait(soundFeedback, host);
    expect(host.hasAttribute('data-sound-feedback-active')).toBe(true);
  });

  it('disconnect clears active + stops listening', () => {
    const host = mountHost();
    const inst = connectTrait(soundFeedback, host);
    inst.disconnect(host);
    expect(host.hasAttribute('data-sound-feedback-active')).toBe(false);
  });

  it('without data-sound-type: press fires no audio (no throw)', () => {
    const host = mountHost();
    connectTrait(soundFeedback, host);
    expect(() => host.dispatchEvent(new CustomEvent('press', { bubbles: true }))).not.toThrow();
  });
});
