import { describe, expect, it } from 'vitest'
import { formatUsdValue, getSecondaryDisplayValue } from './displayCurrency'

describe('formatUsdValue', () => {
  it('keeps cents for smaller values', () => {
    expect(formatUsdValue(4.5)).toBe('$4.50')
  })

  it('drops cents for larger rounded values', () => {
    expect(formatUsdValue(1250)).toBe('$1,250')
  })
})

describe('getSecondaryDisplayValue', () => {
  it('returns null when the user prefers native display', () => {
    expect(
      getSecondaryDisplayValue({
        rawAmount: '4500000',
        decimals: 6,
        exchangeRate: 1,
        displayCurrency: 'native',
      }),
    ).toBeNull()
  })

  it('formats a USD secondary value from token units and exchange rate', () => {
    expect(
      getSecondaryDisplayValue({
        rawAmount: '4500000',
        decimals: 6,
        exchangeRate: 1,
        displayCurrency: 'usd',
      }),
    ).toBe('$4.50')
  })

  it('returns null when no usable exchange rate is available', () => {
    expect(
      getSecondaryDisplayValue({
        rawAmount: '4500000',
        decimals: 6,
        exchangeRate: null,
        displayCurrency: 'usd',
      }),
    ).toBeNull()
  })
})
