import { describe, expect, it } from 'vitest'
import { pickActiveItem, type RoleSwitcherItem } from '@/components/app/role-switcher-bar'

/** Pilot testing bar highlight follows the current page (Nash, 2026-09-13). */
const items: RoleSwitcherItem[] = [
  { kind: 'link', href: '/fb-dashboard', label: 'Broker dashboard', activeOn: ['/fb-dashboard', '/fb-trip-workspace'] },
  { kind: 'switch', role: 'dispatcher', label: 'Carrier dashboard', activeOn: ['/cd-dashboard', '/cd-trip-workspace'] },
  { kind: 'switch', role: 'driver', label: 'Driver app', activeOn: ['/ct-dashboard', '/ct-trip-workspace'] },
  { kind: 'link', href: '/pd-dashboard', label: 'Pilot dispatch dashboard', activeOn: ['/pd-dashboard', '/pd-trip-workspace'] },
  { kind: 'switch', role: 'admin', label: 'Admin', activeOn: ['/admin/users'] },
]

describe('pilot testing bar highlight', () => {
  it('lights the broker link on the freight broker pages, even though broker has no test account', () => {
    expect(pickActiveItem(items, '/fb-dashboard', 'admin')?.label).toBe('Broker dashboard')
    expect(pickActiveItem(items, '/fb-trip-workspace/HH-2041', 'admin')?.label).toBe('Broker dashboard')
  })
  it('follows the page, not the session role', () => {
    expect(pickActiveItem(items, '/cd-dashboard', 'admin')?.label).toBe('Carrier dashboard')
    expect(pickActiveItem(items, '/pd-trip-workspace/HH-2041', 'admin')?.label).toBe('Pilot dispatch dashboard')
  })
  it('falls back to the session role on pages no item owns', () => {
    expect(pickActiveItem(items, '/billing', 'driver')?.label).toBe('Driver app')
    expect(pickActiveItem(items, '/billing', 'broker')).toBeNull()
  })
})
