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();
  });

  function checkbox(): HTMLElement {
    return fixture.nativeElement.querySelector('[role="checkbox"]');
  }

  it('renders keyboard-focusable checkbox semantics', () => {
    expect(checkbox().getAttribute('aria-checked')).toBe('false');
    expect(checkbox().getAttribute('tabindex')).toBe('0');
    expect(checkbox().textContent?.trim()).toBe('Assinar newsletter');
  });

  it('toggles aria-checked when clicked', () => {
    checkbox().click();
    fixture.detectChanges();
    expect(checkbox().getAttribute('aria-checked')).toBe('true');
  });

  it('toggles with Space and Enter', () => {
    checkbox().dispatchEvent(new KeyboardEvent('keydown', { key: ' ', bubbles: true }));
    fixture.detectChanges();
    expect(checkbox().getAttribute('aria-checked')).toBe('true');

    checkbox().dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }));
    fixture.detectChanges();
    expect(checkbox().getAttribute('aria-checked')).toBe('false');
  });
});
