Files
gridpilot.gg/apps/website/lib/formatters/CountryFlagFormatter.test.ts
Marc Mintel 3db2209d2a
Some checks failed
CI / lint-typecheck (push) Failing after 4m52s
CI / tests (push) Has been skipped
CI / contract-tests (push) Has been skipped
CI / e2e-tests (push) Has been skipped
CI / comment-pr (push) Has been skipped
CI / commit-types (push) Has been skipped
formatter tests
2026-01-25 11:17:47 +01:00

66 lines
2.7 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { CountryFlagFormatter } from './CountryFlagFormatter';
describe('CountryFlagFormatter', () => {
describe('fromCountryCode', () => {
it('should return flag emoji for valid 2-letter country code', () => {
const formatter = CountryFlagFormatter.fromCountryCode('US');
expect(formatter.toString()).toBe('🇺🇸');
});
it('should handle lowercase country codes', () => {
const formatter = CountryFlagFormatter.fromCountryCode('us');
expect(formatter.toString()).toBe('🇺🇸');
});
it('should return default flag for null', () => {
const formatter = CountryFlagFormatter.fromCountryCode(null);
expect(formatter.toString()).toBe('🏁');
});
it('should return default flag for undefined', () => {
const formatter = CountryFlagFormatter.fromCountryCode(undefined);
expect(formatter.toString()).toBe('🏁');
});
it('should return default flag for empty string', () => {
const formatter = CountryFlagFormatter.fromCountryCode('');
expect(formatter.toString()).toBe('🏁');
});
it('should return default flag for invalid length code', () => {
const formatter = CountryFlagFormatter.fromCountryCode('USA');
expect(formatter.toString()).toBe('🏁');
});
it('should return default flag for single character code', () => {
const formatter = CountryFlagFormatter.fromCountryCode('U');
expect(formatter.toString()).toBe('🏁');
});
it('should handle various country codes', () => {
expect(CountryFlagFormatter.fromCountryCode('GB').toString()).toBe('🇬🇧');
expect(CountryFlagFormatter.fromCountryCode('DE').toString()).toBe('🇩🇪');
expect(CountryFlagFormatter.fromCountryCode('FR').toString()).toBe('🇫🇷');
expect(CountryFlagFormatter.fromCountryCode('IT').toString()).toBe('🇮🇹');
expect(CountryFlagFormatter.fromCountryCode('ES').toString()).toBe('🇪🇸');
expect(CountryFlagFormatter.fromCountryCode('JP').toString()).toBe('🇯🇵');
expect(CountryFlagFormatter.fromCountryCode('AU').toString()).toBe('🇦🇺');
expect(CountryFlagFormatter.fromCountryCode('CA').toString()).toBe('🇨🇦');
expect(CountryFlagFormatter.fromCountryCode('BR').toString()).toBe('🇧🇷');
});
});
describe('toString', () => {
it('should return the flag emoji', () => {
const formatter = CountryFlagFormatter.fromCountryCode('US');
expect(formatter.toString()).toBe('🇺🇸');
});
it('should return the default flag for invalid codes', () => {
const formatter = CountryFlagFormatter.fromCountryCode('XX');
expect(formatter.toString()).toBe('🏁');
});
});
});