Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

978 B
Raw Blame
import { describe, it, expect } from 'vitest'
import { countryFlag } from './country-flag'

describe('countryFlag', () => {
  it('derives the flag from the country code', () => {
    expect(countryFlag('BR')).toBe('πŸ‡§πŸ‡·')
    expect(countryFlag('DE')).toBe('πŸ‡©πŸ‡ͺ')
    expect(countryFlag('US')).toBe('πŸ‡ΊπŸ‡Έ')
  })

  it('accepts lowercase and surrounding space', () => {
    expect(countryFlag('br')).toBe('πŸ‡§πŸ‡·')
    expect(countryFlag(' gb ')).toBe('πŸ‡¬πŸ‡§')
  })

  it('returns nothing for anything that is not a country code', () => {
    // `tax_jurisdiction` may hold a regime code, which has no flag. Emitting
    // one anyway would render as unrelated boxes.
    for (const value of ['', 'MEI', 'B', 'BRA', '12', 'B1']) {
      expect(countryFlag(value)).toBe('')
    }
  })

  it('needs no lookup table, so a new pack gets a flag for free', () => {
    expect(countryFlag('JP')).toBe('πŸ‡―πŸ‡΅')
    expect(countryFlag('ZA')).toBe('πŸ‡ΏπŸ‡¦')
  })
})