import { ComponentFixture, TestBed } from '@angular/core/testing';
import { <%= classify(name) %>, <%= classify(name) %>Item } 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 a native table with caption, row headers, checkboxes, and statuses', () => {
    expect(fixture.nativeElement.querySelector('caption').textContent).toContain('Autorizações pendentes');
    expect(fixture.nativeElement.querySelectorAll('tbody th[scope="row"]').length).toBeGreaterThan(0);
    expect(fixture.nativeElement.querySelectorAll('input[type="checkbox"]').length).toBeGreaterThan(1);
    expect(fixture.nativeElement.textContent).toContain('Pendente de aprovação');
  });

  it('enables bulk approval after selecting a row', () => {
    let approved: readonly <%= classify(name) %>Item[] = [];
    fixture.componentInstance.approve.subscribe((items) => {
      approved = items;
    });

    const rowCheckbox: HTMLInputElement = fixture.nativeElement.querySelectorAll('tbody input[type="checkbox"]')[0];
    rowCheckbox.click();
    fixture.detectChanges();

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

    approveButton.click();
    fixture.detectChanges();

    expect(approved.length).toBe(1);
    expect(fixture.nativeElement.textContent).toContain('aprovada');
  });
});
