import { describe, it, expect, beforeEach } from 'vitest';
import '../../core/element.js';
import './option-card.js';

const tick = () => new Promise((r) => queueMicrotask(r));
function mount(html) {
  const w = document.createElement('div');
  w.innerHTML = html;
  document.body.appendChild(w);
  return w.firstElementChild;
}

describe('option-card-ui — heading/description stamp-if-absent (wrapper trap)', () => {
  beforeEach(() => { document.body.innerHTML = ''; });

  it('stamps heading + description from attrs when no slots are provided', async () => {
    const el = mount('<option-card-ui heading="Pro" description="Best value"></option-card-ui>');
    await tick();
    expect(el.querySelectorAll('[slot="heading"]').length).toBe(1);
    expect(el.querySelectorAll('[slot="description"]').length).toBe(1);
  });

  // Regression (audit-wrapper-trap arm 2): a WRAPPED consumer [slot="heading"]
  // override must suppress the attr-stamp, not collide with it.
  it('does NOT stamp a duplicate heading when a WRAPPED consumer heading is present', async () => {
    const el = mount(`<option-card-ui heading="Pro"><span style="display:contents" role="presentation"><h3 slot="heading" data-test="h">Custom</h3></span></option-card-ui>`);
    await tick();
    const headings = el.querySelectorAll('[slot="heading"]');
    expect(headings.length).toBe(1);
    expect(headings[0].dataset.test).toBe('h');
  });
});
