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

@Component({
  imports: [<%= classify(name) %>],
  template: `
    <<%= selector %>
      title="Revisar transferência"
      currencyCode="BRL"
      [totalAmount]="250.75"
      (confirm)="confirmed = true"
      (cancel)="cancelled = true"
    />
  `,
})
class HostComponent {
  confirmed = false;
  cancelled = false;
}

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

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

  function section(): HTMLElement {
    return fixture.nativeElement.querySelector('section');
  }

  function buttons(): HTMLButtonElement[] {
    return Array.from(fixture.nativeElement.querySelectorAll('button'));
  }

  it('renders a labelled confirmation summary with details and total amount', () => {
    const heading = fixture.nativeElement.querySelector('h2');

    expect(section().getAttribute('aria-labelledby')).toBe(heading.id);
    expect(section().getAttribute('aria-describedby')).toBeTruthy();
    expect(heading.textContent).toContain('Revisar transferência');
    expect(fixture.nativeElement.querySelectorAll('dt').length).toBeGreaterThan(0);
    expect(fixture.nativeElement.textContent).toContain('R$250.75');
  });

  it('emits cancel and confirm actions from native buttons', () => {
    const [cancelButton, confirmButton] = buttons();

    cancelButton.click();
    confirmButton.click();
    fixture.detectChanges();

    expect(fixture.componentInstance.cancelled).toBe(true);
    expect(fixture.componentInstance.confirmed).toBe(true);
  });
});
