import { describe, it, expect } from 'vitest'
import { buildProjectTabs } from '../project-tabs-config'

describe('buildProjectTabs', () => {
  it('always shows the base tabs including Agenda and OEE', () => {
    const tabs = buildProjectTabs('p1', [])
    const labels = tabs.map((t) => t.label)
    expect(labels).toEqual(['Übersicht', 'Dokumente', 'Team', 'Agenda', 'OEE'])
    expect(tabs.find((t) => t.label === 'Agenda')?.href).toBe('/project/p1/agenda')
    expect(tabs.find((t) => t.label === 'OEE')?.href).toBe('/project/p1/oee')
  })

  it('adds LSC workshop tabs', () => {
    const tabs = buildProjectTabs('p1', ['lsc_workshop'])
    const hrefs = tabs.map((t) => t.href)
    expect(hrefs).toContain('/project/p1/stopwatch')
    expect(hrefs).toContain('/project/p1/qaf')
    expect(hrefs).toContain('/project/p1/export')
  })

  it('adds the Fabrikanalyse tab', () => {
    const tabs = buildProjectTabs('p1', ['fabrikanalyse'])
    expect(tabs.some((t) => t.href === '/project/p1/analyse')).toBe(true)
  })

  it('always adds the OEE tab regardless of records', () => {
    const tabsWithout = buildProjectTabs('p1', [], false)
    expect(tabsWithout.some((t) => t.href === '/project/p1/oee')).toBe(true)
    const tabsWith = buildProjectTabs('p1', [], true)
    expect(tabsWith.some((t) => t.href === '/project/p1/oee')).toBe(true)
  })

  it('never produces duplicate hrefs', () => {
    const tabs = buildProjectTabs('p1', ['lsc_workshop', '360_workshop', 'kapa_workshop'], true)
    const hrefs = tabs.map((t) => t.href)
    expect(new Set(hrefs).size).toBe(hrefs.length)
  })
})
