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

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

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

  it('renders an alert with required acknowledgement before continuing', () => {
    const alert = fixture.nativeElement.querySelector('[role="alert"]');
    const confirm: HTMLButtonElement = fixture.nativeElement.querySelector('button');

    expect(alert.getAttribute('aria-labelledby')).toBe(fixture.nativeElement.querySelector('h2').id);
    expect(fixture.nativeElement.querySelector('input[type="checkbox"]')).toBeTruthy();
    expect(confirm.disabled).toBe(true);
  });

  it('enables acknowledgement after consent and emits action', () => {
    let acknowledged = false;
    fixture.componentInstance.acknowledge.subscribe(() => {
      acknowledged = true;
    });

    const checkbox: HTMLInputElement = fixture.nativeElement.querySelector('input[type="checkbox"]');
    checkbox.click();
    fixture.detectChanges();

    const confirm: HTMLButtonElement = fixture.nativeElement.querySelector('button');
    expect(confirm.disabled).toBe(false);

    confirm.click();
    fixture.detectChanges();

    expect(acknowledged).toBe(true);
    expect(fixture.nativeElement.querySelector('[aria-live="polite"]').textContent).toContain('confirmado');
  });
});
