import { describe, it, expect } from 'vitest'
import { buildDefaultTitle } from '../naming'

describe('buildDefaultTitle', () => {
  it('all three parts present', () => {
    expect(buildDefaultTitle({ supplier: 'Fantasiewerk GmbH', project: 'Projekt Falke', variant: 'Variante A' })).toBe(
      'Fantasiewerk GmbH · Projekt Falke · Variante A · QAF-Wertstrom',
    )
  })

  it('only supplier', () => {
    expect(buildDefaultTitle({ supplier: 'Fantasiewerk GmbH' })).toBe('Fantasiewerk GmbH · QAF-Wertstrom')
  })

  it('only project', () => {
    expect(buildDefaultTitle({ project: 'Projekt Falke' })).toBe('Projekt Falke · QAF-Wertstrom')
  })

  it('only variant', () => {
    expect(buildDefaultTitle({ variant: 'Variante A' })).toBe('Variante A · QAF-Wertstrom')
  })

  it('supplier + project', () => {
    expect(buildDefaultTitle({ supplier: 'Fantasiewerk GmbH', project: 'Projekt Falke' })).toBe(
      'Fantasiewerk GmbH · Projekt Falke · QAF-Wertstrom',
    )
  })

  it('supplier + variant', () => {
    expect(buildDefaultTitle({ supplier: 'Fantasiewerk GmbH', variant: 'Variante A' })).toBe('Fantasiewerk GmbH · Variante A · QAF-Wertstrom')
  })

  it('project + variant', () => {
    expect(buildDefaultTitle({ project: 'Projekt Falke', variant: 'Variante A' })).toBe('Projekt Falke · Variante A · QAF-Wertstrom')
  })

  it('nothing present -> just the suffix', () => {
    expect(buildDefaultTitle({})).toBe('QAF-Wertstrom')
  })

  it('whitespace-only parts are treated as absent', () => {
    expect(buildDefaultTitle({ supplier: '   ', project: 'Projekt Falke', variant: '\t' })).toBe('Projekt Falke · QAF-Wertstrom')
  })

  it('trims surrounding whitespace on present parts', () => {
    expect(buildDefaultTitle({ supplier: '  Fantasiewerk GmbH  ' })).toBe('Fantasiewerk GmbH · QAF-Wertstrom')
  })

  it('null/undefined parts are treated as absent', () => {
    expect(buildDefaultTitle({ supplier: null, project: undefined, variant: 'Variante A' })).toBe('Variante A · QAF-Wertstrom')
  })

  it('the source file name is never part of the title (no such parameter exists)', () => {
    const title = buildDefaultTitle({ supplier: 'Fantasiewerk GmbH' })
    expect(title).not.toMatch(/\.xlsx|\.xlsm|\.xls/i)
  })
})
