import { describe, it, expect } from 'vitest'
import { hashColor, fnv1a } from './hashColor'

describe('fnv1a', () => {
  it('returns a number for any string', () => {
    expect(typeof fnv1a('test')).toBe('number')
  })

  it('returns consistent hash for same input', () => {
    expect(fnv1a('order-service')).toBe(fnv1a('order-service'))
  })

  it('returns different hashes for different inputs', () => {
    expect(fnv1a('order-service')).not.toBe(fnv1a('payment-service'))
  })
})

describe('hashColor', () => {
  it('returns bg, text, and border properties', () => {
    const result = hashColor('test')
    expect(result).toHaveProperty('bg')
    expect(result).toHaveProperty('text')
    expect(result).toHaveProperty('border')
  })

  it('returns HSL color strings', () => {
    const result = hashColor('order-service')
    expect(result.bg).toMatch(/^hsl\(\d+,\s*\d+%,\s*\d+%\)$/)
    expect(result.text).toMatch(/^hsl\(\d+,\s*\d+%,\s*\d+%\)$/)
    expect(result.border).toMatch(/^hsl\(\d+,\s*\d+%,\s*\d+%\)$/)
  })

  it('returns consistent colors for same name', () => {
    const a = hashColor('VIEWER')
    const b = hashColor('VIEWER')
    expect(a).toEqual(b)
  })

  it('returns different hues for different names', () => {
    const a = hashColor('VIEWER')
    const b = hashColor('OPERATOR')
    expect(a.bg).not.toBe(b.bg)
  })

  it('accepts dark mode parameter', () => {
    const light = hashColor('test', 'light')
    const dark = hashColor('test', 'dark')
    expect(light.bg).not.toBe(dark.bg)
  })
})
