import { describe, expect, it } from 'vitest'
import {
  formatBitrate,
  formatBytes,
  formatRuntime,
  formatSeconds,
  formatTimecode,
  ticksToSeconds,
} from './format'

describe('format helpers', () => {
  it('converts Jellyfin ticks to seconds', () => {
    expect(ticksToSeconds(25_000_000)).toBe(2.5)
    expect(ticksToSeconds(null)).toBe(0)
  })

  it('formats runtimes and timecodes', () => {
    expect(formatRuntime(90 * 60 * 10_000_000)).toBe('1h 30m')
    expect(formatRuntime(45 * 60 * 10_000_000)).toBe('45m')
    expect(formatTimecode(3725 * 10_000_000)).toBe('1:02:05')
    expect(formatSeconds(125)).toBe('2:05')
  })

  it('formats sizes and bitrates', () => {
    expect(formatBytes(1024)).toBe('1 KB')
    expect(formatBytes(5 * 1024 * 1024)).toBe('5 MB')
    expect(formatBitrate(320_000)).toBe('320 kbps')
    expect(formatBitrate(6_400_000)).toBe('6.4 Mbps')
  })
})
