import { describe, it, expect, beforeEach } from 'vitest';
import '../../core/element.js';
import './timeline.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('timeline-item-ui — label stamp-if-absent (wrapper trap)', () => {
  beforeEach(() => { document.body.innerHTML = ''; });

  it('stamps the label structure when the consumer provides none', async () => {
    const el = mount('<timeline-item-ui text="Shipped"></timeline-item-ui>');
    await tick();
    expect(el.querySelectorAll('[slot="label"]').length).toBe(1);
  });

  // Regression (audit-wrapper-trap arm 2): a WRAPPED consumer [slot="label"]
  // must suppress the default-structure stamp, not produce a duplicate label.
  it('does NOT stamp a duplicate when a WRAPPED consumer label is present', async () => {
    const el = mount(`<timeline-item-ui text="Shipped"><span style="display:contents" role="presentation"><span slot="label" data-test="l">Custom</span></span></timeline-item-ui>`);
    await tick();
    const labels = el.querySelectorAll('[slot="label"]');
    expect(labels.length).toBe(1);
    expect(labels[0].dataset.test).toBe('l');
  });
});
