import { TestBed } from '@angular/core/testing';
import { provideRouter } from '@angular/router';
import { AdminSidebar } from './sidebar';

describe('AdminSidebar', () => {
  beforeEach(async () => {
    await TestBed.configureTestingModule({
      imports: [AdminSidebar],
      providers: [provideRouter([])],
    }).compileComponents();
  });

  function render(): HTMLElement {
    const fixture = TestBed.createComponent(AdminSidebar);
    fixture.detectChanges();
    return fixture.nativeElement as HTMLElement;
  }

  it('renders a navigation landmark labelled "Admin navigation"', () => {
    const root = render();
    const nav = root.querySelector('nav');
    expect(nav?.getAttribute('aria-label')).toBe('Admin navigation');
  });

  it('exposes the Audit log entry as a live router link', () => {
    const root = render();
    const links = Array.from(root.querySelectorAll<HTMLAnchorElement>('a.nav-link'));
    const auditLink = links.find((a) => a.textContent?.includes('Audit log'));
    expect(auditLink).toBeTruthy();
    // RouterLink renders the resolved href on the anchor.
    expect(auditLink?.getAttribute('href')).toBe('/audit');
  });

  it('exposes the User list entry as a live router link', () => {
    const root = render();
    const links = Array.from(root.querySelectorAll<HTMLAnchorElement>('a.nav-link'));
    const usersLink = links.find((a) => a.textContent?.includes('User list'));
    expect(usersLink).toBeTruthy();
    expect(usersLink?.getAttribute('href')).toBe('/users');
  });

  it('renders the not-yet-implemented entries as aria-disabled placeholders with a "Soon" badge', () => {
    const root = render();
    const disabled = Array.from(root.querySelectorAll('.nav-link--disabled'));
    expect(disabled.length).toBeGreaterThan(0);
    for (const node of disabled) {
      expect(node.getAttribute('aria-disabled')).toBe('true');
      expect(node.querySelector('.nav-badge')?.textContent?.trim()).toBe('Soon');
    }
  });
});
