import { describe, expect, test } from 'vitest'
import { formatSeconds, formatDuration } from '@/utils/app'

describe('function: formatSeconds', () => {
  test('传入 number 时，返回当天 23:59:59 的秒级时间戳 number', () => {
    const result = formatSeconds(1705285230)
    expect(result).toBe(1705334399)
  })

  test('传入 string 时，返回当天 23:59:59 的秒级时间戳 string', () => {
    const result = formatSeconds('1705285230')
    expect(result).toBe('1705334399')
  })
})

describe('function: formatDuration', () => {
  test('把秒数格式化为 m:ss，并对秒数补 0', () => {
    const result1 = formatDuration(120)
    expect(result1).toBe('2:00')

    const result2 = formatDuration(8)
    expect(result2).toBe('0:08')

    const result3 = formatDuration(61)
    expect(result3).toBe('1:01')
  })

  test.each([
    [120, '2:00'],
    [8, '0:08'],
    [61, '1:01'],
  ])('把秒数格式化为 m:ss，并对秒数补 0', (seconds, expected) => {
    expect(formatDuration(seconds)).toBe(expected)
  })
})
