import { Component } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= classify(name) %> } from './<%= dasherize(name) %>';

@Component({
  imports: [<%= classify(name) %>],
  template: `
    <<%= selector %>
      label="Área"
      hint="Escolha uma equipe."
      errorMessage="Área é obrigatória."
      [required]="true"
      [(value)]="area"
    />
  `,
})
class HostComponent {
  area = '';
}

describe('<%= classify(name) %>', () => {
  let fixture: ComponentFixture<HostComponent>;

  beforeEach(async () => {
    await TestBed.configureTestingModule({ imports: [HostComponent] }).compileComponents();
    fixture = TestBed.createComponent(HostComponent);
    fixture.detectChanges();
  });

  function select(): HTMLSelectElement {
    return fixture.nativeElement.querySelector('select');
  }

  it('wires native select semantics with hint and error', () => {
    const label = fixture.nativeElement.querySelector('label');
    const hint = fixture.nativeElement.querySelector('.select__hint');
    const error = fixture.nativeElement.querySelector('.select__error');

    expect(label.textContent).toContain('Área');
    expect(label.getAttribute('for')).toBe(select().id);
    expect(select().required).toBe(true);
    expect(select().getAttribute('aria-invalid')).toBe('true');
    expect(select().getAttribute('aria-describedby')).toContain(hint.id);
    expect(select().getAttribute('aria-describedby')).toContain(error.id);
  });

  it('updates the bound value on change', () => {
    select().value = 'engineering';
    select().dispatchEvent(new Event('change', { bubbles: true }));
    fixture.detectChanges();

    expect(fixture.componentInstance.area).toBe('engineering');
  });
});
