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

describe('scale-press', () => {
  beforeEach(resetDOM);

  it('pointerdown applies scale(0.95) + active attribute', () => {
    const host = mountHost();
    connectTrait(scalePress, host);
    host.dispatchEvent(new PointerEvent('pointerdown'));
    expect(host.hasAttribute('data-scale-press-active')).toBe(true);
    expect(host.style.transform).toContain('0.95');
  });

  it('pointerup releases scale and clears attribute', () => {
    const host = mountHost();
    connectTrait(scalePress, host);
    host.dispatchEvent(new PointerEvent('pointerdown'));
    host.dispatchEvent(new PointerEvent('pointerup'));
    expect(host.hasAttribute('data-scale-press-active')).toBe(false);
  });

  it('pointerleave during press releases (canceled press)', () => {
    const host = mountHost();
    connectTrait(scalePress, host);
    host.dispatchEvent(new PointerEvent('pointerdown'));
    host.dispatchEvent(new PointerEvent('pointerleave'));
    expect(host.hasAttribute('data-scale-press-active')).toBe(false);
  });

  it('respects [disabled] — no transform, no attribute', () => {
    const host = mountHost('button', { disabled: '' });
    connectTrait(scalePress, host);
    host.dispatchEvent(new PointerEvent('pointerdown'));
    expect(host.hasAttribute('data-scale-press-active')).toBe(false);
    expect(host.style.transform).toBe('');
  });
});
