66 lines
2.7 KiB
TypeScript
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('🏁');
|
|
});
|
|
});
|
|
});
|