import { describe, it, expect } from 'vitest';
import { navItems, getNavItemsForRole } from '@/lib/constants/navigation';
import type { UserRole } from '@/lib/constants/navigation';

describe('navItems', () => {
  it('contains 19 navigation items', () => {
    expect(navItems).toHaveLength(19);
  });

  it('includes all expected labels', () => {
    const labels = navItems.map((item) => item.label);
    expect(labels).toEqual([
      'Overview',
      'Works',
      'Composers',
      'Payees',
      'Contracts',
      'Income',
      'Transactions',
      'Costs',
      'Statements',
      'Suspense',
      'Audit',
      'Inicio',
      'Overview',
      'Top Songs',
      'Income Groups',
      'Territories',
      'Exploitation Sources',
      'Canciones',
      'Documentos',
    ]);
  });
});

describe('getNavItemsForRole', () => {
  it('returns only Overview, Income, Statements, Costs for Viewer', () => {
    const items = getNavItemsForRole('Viewer');
    const labels = items.map((i) => i.label);
    expect(labels).toEqual(['Overview', 'Income', 'Costs', 'Statements']);
  });

  it('returns all items except Audit for Publisher_Admin', () => {
    const items = getNavItemsForRole('Publisher_Admin');
    const labels = items.map((i) => i.label);
    expect(labels).not.toContain('Audit');
    expect(labels).toHaveLength(10);
  });

  it('returns all 11 items for Super_Admin', () => {
    const items = getNavItemsForRole('Super_Admin');
    expect(items).toHaveLength(11);
  });

  it('every returned item includes the queried role', () => {
    const roles: UserRole[] = ['Super_Admin', 'Publisher_Admin', 'Viewer'];
    for (const role of roles) {
      const items = getNavItemsForRole(role);
      for (const item of items) {
        expect(item.roles).toContain(role);
      }
    }
  });
});
