Skip to content

Commit

Permalink
fix(phone-number): flag enum & list iso codes
Browse files Browse the repository at this point in the history
  • Loading branch information
aesteves60 authored and dpellier committed Sep 25, 2023
1 parent f018ef5 commit 3d1f67f
Show file tree
Hide file tree
Showing 12 changed files with 311 additions and 48 deletions.
13 changes: 7 additions & 6 deletions packages/common/core/src/i18n/ods-country-iso-codes.types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ODS_COUNTRY_ISO_CODE {
enum ODS_COUNTRY_ISO_CODE {
AD = 'ad', // Andorra
AE = 'ae', // United Arab Emirates
AF = 'af', // Afghanistan
Expand Down Expand Up @@ -68,7 +68,6 @@ export enum ODS_COUNTRY_ISO_CODE {
ER = 'er', // Eritrea
ES = 'es', // Spain
ET = 'et', // Ethiopia
EU = 'eu', // Europe
FI = 'fi', // Finland
FJ = 'fj', // Fiji
FK = 'fk', // Falkland Islands (Malvinas)
Expand Down Expand Up @@ -232,8 +231,6 @@ export enum ODS_COUNTRY_ISO_CODE {
UA = 'ua', // Ukraine
UG = 'ug', // Uganda
UM = 'um', // United States Minor Outlying Islands
UN = 'un', // United Nations
UNIA = 'unia', // Pan-Africa
US = 'us', // United States of America
UY = 'uy', // Uruguay
UZ = 'uz', // Uzbekistan
Expand All @@ -246,12 +243,16 @@ export enum ODS_COUNTRY_ISO_CODE {
VU = 'vu', // Vanuatu
WF = 'wf', // Wallis and Futuna
WS = 'ws', // Samoa
XK = 'xk', // Kosovo
YE = 'ye', // Yemen
YT = 'yt', // Mayotte
ZA = 'za', // South Africa
ZM = 'zm', // Zambia
ZW = 'zw', // Zimbabwe
}

export const ODS_COUNTRY_ISO_CODES = Object.freeze(Object.keys(ODS_COUNTRY_ISO_CODE));
const ODS_COUNTRY_ISO_CODES = Object.freeze(Object.values(ODS_COUNTRY_ISO_CODE));

export {
ODS_COUNTRY_ISO_CODE,
ODS_COUNTRY_ISO_CODES,
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { OdsFlagAttribute } from '../interfaces/attributes';
import { ODS_COUNTRY_ISO_CODE } from '@ovhcloud/ods-common-core';
import { ODS_FLAG_ISO_CODE } from './flag-iso-code';

/**
* default attribute values of flag
*/
const DEFAULT_ATTRIBUTE: OdsFlagAttribute = Object.freeze({
iso: ODS_COUNTRY_ISO_CODE.FR,
iso: ODS_FLAG_ISO_CODE.FR,
lazy: false,
src: '',
assetPath: '',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
enum ODS_FLAG_ISO_CODE {
AD = 'ad', // Andorra
AE = 'ae', // United Arab Emirates
AF = 'af', // Afghanistan
AG = 'ag', // Antigua and Barbuda
AL = 'al', // Albania
AO = 'ao', // Angola
AI = 'ai', // Anguilla
AM = 'am', // Armenia
AR = 'ar', // Argentina
AS = 'as', // American Samoa
AT = 'at', // Austria
AU = 'au', // Australia
AW = 'aw', // Aruba
AX = 'ax', // Åland Islands
AQ = 'aq', // Antarctica
AZ = 'az', // Azerbaijan
BA = 'ba', // Bosnia and Herzegovina
BB = 'bb', // Barbados
BD = 'bd', // Bangladesh
BE = 'be', // Belgium
BF = 'bf', // Burkina Faso
BG = 'bg', // Bulgaria
BH = 'bh', // Bahrain
BI = 'bi', // Burundi
BJ = 'bj', // Benin
BL = 'bl', // Saint Barthélemy
BM = 'bm', // Bermuda
BN = 'bn', // Brunei Darussalam
BO = 'bo', // Bolivia (Plurinational State of)
BQ = 'bq', // Bonaire, Sint Eustatius and Saba
BR = 'br', // Brazil
BS = 'bs', // Bahamas
BT = 'bt', // Bhutan
BV = 'bv', // Bouvet Island
BW = 'bw', // Botswana
BY = 'by', // Belarus
BZ = 'bz', // Belize
CA = 'ca', // Canada
CC = 'cc', // Cocos (Keeling) Islands
CD = 'cd', // Congo, Democratic Republic of the
CF = 'cf', // Central African Republic
CG = 'cg', // Congo
CH = 'ch', // Switzerland
CI = 'ci', // Côte d\'Ivoire
CK = 'ck', // Cook Islands
CL = 'cl', // Chile
CM = 'cm', // Cameroon
CN = 'cn', // China
CO = 'co', // Colombia
CR = 'cr', // Costa Rica
CU = 'cu', // Cuba
CV = 'cv', // Cabo Verde
CW = 'cw', // Curaçao
CX = 'cx', // Christmas Island
CY = 'cy', // Cyprus
CZ = 'cz', // Czechia
DE = 'de', // Germany
DJ = 'dj', // Djibouti
DK = 'dk', // Denmark
DM = 'dm', // Dominica
DO = 'do', // Dominican Republic
DZ = 'dz', // Algeria
EC = 'ec', // Ecuador
EE = 'ee', // Estonia
EG = 'eg', // Egypt
EH = 'eh', // Western Sahara
ER = 'er', // Eritrea
ES = 'es', // Spain
ET = 'et', // Ethiopia
EU = 'eu', // Europe
FI = 'fi', // Finland
FJ = 'fj', // Fiji
FK = 'fk', // Falkland Islands (Malvinas)
FM = 'fm', // Micronesia (Federated States of)
FO = 'fo', // Faroe Islands
FR = 'fr', // France
GA = 'ga', // Gabon
GB = 'gb', // United Kingdom of Great Britain and Northern Ireland
GD = 'gd', // Grenada
GE = 'ge', // Georgia
GF = 'gf', // French Guiana
GG = 'gg', // Guernsey
GH = 'gh', // Ghana
GI = 'gi', // Gibraltar
GL = 'gl', // Greenland
GM = 'gm', // Gambia
GN = 'gn', // Guinea
GP = 'gp', // Guadeloupe
GQ = 'gq', // Equatorial Guinea
GR = 'gr', // Greece
GS = 'gs', // South Georgia and the South Sandwich Islands
GT = 'gt', // Guatemala
GU = 'gu', // Guam
GW = 'gw', // Guinea-Bissau
GY = 'gy', // Guyana
HK = 'hk', // Hong Kong
HN = 'hn', // Honduras
HM = 'hm', // Heard Island and McDonald Islands
HR = 'hr', // Croatia
HT = 'ht', // Haiti
HU = 'hu', // Hungary
ID = 'id', // Indonesia
IE = 'ie', // Ireland
IL = 'il', // Israel
IM = 'im', // Isle of Man
IN = 'in', // India
IO = 'io', // British Indian Ocean Territory
IQ = 'iq', // Iraq
IR = 'ir', // Iran (Islamic Republic of)
IS = 'is', // Iceland
IT = 'it', // Italy
JE = 'je', // Jersey
JM = 'jm', // Jamaica
JO = 'jo', // Jordan
JP = 'jp', // Japan
KE = 'ke', // Kenya
KG = 'kg', // Kiribati
KH = 'kh', // Cambodia
KI = 'ki', // Kiribati
KN = 'kn', // Saint Kitts and Nevis
KM = 'km', // Comoros
KP = 'kp', // orea (Democratic People\'s Republic of)
KR = 'kr', // Korea, Republic of
KW = 'kw', // Kuwait
KY = 'ky', // Cayman Islands
KZ = 'kz', // Kazakhstan
LA = 'la', // ao People\'s Democratic Republic
LB = 'lb', // Lebanon
LC = 'lc', // Saint Lucia
LI = 'li', // Liechtenstein
LK = 'lk', // Sri lanka
LR = 'lr', // Liberia
LS = 'ls', // Lesotho
LT = 'lt', // Lithuania
LU = 'lu', // Luxembourg
LV = 'lv', // Latvia
LY = 'ly', // Libya
MA = 'ma', // Morocco
MC = 'mc', // Monaco
MD = 'md', // Moldova, Republic of
ME = 'me', // Montenegro
MF = 'mf', // Saint Martin (French part)
MG = 'mg', // Madagascar
MH = 'mh', // Marshall Islands
MK = 'mk', // North Macedonia
ML = 'ml', // Mali
MM = 'mm', // Myanmar
MN = 'mn', // Mongolia
MO = 'mo', // Macao
MP = 'mp', // Northern Mariana Islands
MQ = 'mq', // Martinique
MR = 'mr', // Mauritania
MS = 'ms', // Montserrat
MT = 'mt', // Malta
MU = 'mu', // Mauritius
MV = 'mv', // Maldives
MW = 'mw', // Malawi
MX = 'mx', // Mexico
MY = 'my', // Malaysia
MZ = 'mz', // Mozambique
NA = 'na', // Namibia
NC = 'nc', // New Caledonia
NE = 'ne', // Niger
NF = 'nf', // Norfolk Island
NG = 'ng', // Nigeria
NI = 'ni', // Nicaragua
NL = 'nl', // Netherlands
NO = 'no', // Norway
NP = 'np', // Nepal
NR = 'nr', // Nauru
NU = 'nu', // Niue
NZ = 'nz', // New Zealand
OM = 'om', // Oman
PA = 'pa', // Panama
PE = 'pe', // Peru
PF = 'pf', // French Polynesia
PG = 'pg', // Papua New Guinea
PH = 'ph', // Philippines
PK = 'pk', // Pakistan
PL = 'pl', // Poland
PM = 'pm', // Saint Pierre and Miquelon
PN = 'pn', // Pitcairn
PR = 'pr', // Puerto Rico
PS = 'ps', // Palestine, State of
PT = 'pt', // Portugal
PW = 'pw', // Palau
PY = 'py', // Paraguay
QA = 'qa', // Qatar
RE = 're', // Réunion
RO = 'ro', // Romania
RS = 'rs', // Serbia
RU = 'ru', // Russian Federation
RW = 'rw', // Rwanda
SA = 'sa', // Saudi Arabia
SB = 'sb', // Solomon Islands
SC = 'sc', // Seychelles
SD = 'sd', // Sudan
SE = 'se', // Sweden
SG = 'sg', // Singapore
SH = 'sh', // Saint Helena, Ascension and Tristan da Cunha
SI = 'si', // Slovenia
SJ = 'sj', // Svalbard and Jan Mayen
SK = 'sk', // Slovakia
SL = 'sl', // Sierra Leone
SM = 'sm', // San Marino
SN = 'sn', // Senegal
SO = 'so', // Somalia
SR = 'sr', // Suriname
SS = 'ss', // South Sudan
ST = 'st', // Sao Tome and Principe
SV = 'sv', // El Salvador
SX = 'sx', // Sint Maarten (Dutch part)
SY = 'sy', // Syrian Arab Republic
SZ = 'sz', // Eswatini
TC = 'tc', // Turks and Caicos Islands
TD = 'td', // Chad
TF = 'tf', // French Southern Territories
TG = 'tg', // Togo
TH = 'th', // Thailand
TJ = 'tj', // Tajikistan
TK = 'tk', // Tokelau
TL = 'tl', // Timor-Leste
TM = 'tm', // Turkmenistan
TN = 'tn', // Tunisia
TO = 'to', // Tonga
TR = 'tr', // Turkey
TT = 'tt', // Trinidad and Tobago
TV = 'tv', // Tuvalu
TW = 'tw', // Taiwan, Province of China
TZ = 'tz', // Tanzania, United Republic of
UA = 'ua', // Ukraine
UG = 'ug', // Uganda
UM = 'um', // United States Minor Outlying Islands
UN = 'un', // United Nations
US = 'us', // United States of America
UY = 'uy', // Uruguay
UZ = 'uz', // Uzbekistan
VA = 'va', // Holy See
VC = 'vc', // Saint Vincent and the Grenadines
VE = 've', // Venezuela (Bolivarian Republic of)
VG = 'vg', // Virgin Islands (British)
VI = 'vi', // Virgin Islands (U.S.)
VN = 'vn', // Viet Nam
VU = 'vu', // Vanuatu
WF = 'wf', // Wallis and Futuna
WS = 'ws', // Samoa
XK = 'xk', // Kosovo
YE = 'ye', // Yemen
YT = 'yt', // Mayotte
ZA = 'za', // South Africa
ZM = 'zm', // Zambia
ZW = 'zw', // Zimbabwe
}

const ODS_FLAG_ISO_CODES = Object.freeze(Object.values(ODS_FLAG_ISO_CODE));

export {
ODS_FLAG_ISO_CODE,
ODS_FLAG_ISO_CODES,
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ import {
OdsLogger,
odsGetAssetPath,
odsGetSrc,
ODS_COUNTRY_ISO_CODE,
ODS_COUNTRY_ISO_CODES,
} from '@ovhcloud/ods-common-core';
import { OsdsFlag } from '../osds-flag';
import { OdsFlagController } from './controller';
import { ODS_FLAG_ISO_CODE, ODS_FLAG_ISO_CODES } from '../constants/flag-iso-code';

class OdsFlagMock extends OsdsFlag {
constructor(attribute: Partial<OsdsFlag>) {
Expand Down Expand Up @@ -71,24 +70,24 @@ describe('ods-flag-controller', () => {

describe('methods', () => {
describe('validateISO', () => {
const expected = `The iso attribute must be one of those values ${ODS_COUNTRY_ISO_CODES}`;
const expected = `The iso attribute must be one of those values ${ODS_FLAG_ISO_CODES}`;

beforeEach(() => {
setup();
});

it('should clean up the wrong iso code', () => {
controller.validateISO('test' as ODS_COUNTRY_ISO_CODE);
controller.validateISO('test' as ODS_FLAG_ISO_CODE);
expect(component.iso).toEqual(undefined);
});

it('should not call console.warn with correct iso', () => {
controller.validateISO(ODS_COUNTRY_ISO_CODE.FR);
controller.validateISO(ODS_FLAG_ISO_CODE.FR);
expect(loggerSpyReferences.methodSpies.warn).not.toHaveBeenCalled();
});

it('should call console.warn with wrong iso', () => {
controller.validateISO('ods' as ODS_COUNTRY_ISO_CODE);
controller.validateISO('ods' as ODS_FLAG_ISO_CODE);
expect(loggerSpyReferences.methodSpies.warn).toHaveBeenCalledWith(expected);
expect(loggerSpyReferences.methodSpies.warn).toHaveBeenCalledTimes(1);
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import type { OsdsFlag } from '../osds-flag';

import {
ODS_COUNTRY_ISO_CODE,
ODS_COUNTRY_ISO_CODES,
OdsLogger,
odsIsTermInEnum,
OdsLoadContent,
OdsSvgValidator,
odsGetSrc,
odsGetAssetPath
} from '@ovhcloud/ods-common-core';
import { ODS_FLAG_ISO_CODE, ODS_FLAG_ISO_CODES } from '../constants/flag-iso-code';

/**
* common controller logic for flag component used by the different implementations.
Expand Down Expand Up @@ -65,11 +64,11 @@ class OdsFlagController {
* not blocking.
* @param iso - iso code
*/
validateISO(iso?: ODS_COUNTRY_ISO_CODE): void {
console.log('iso', iso, odsIsTermInEnum(iso, ODS_COUNTRY_ISO_CODE))
if (!iso || !odsIsTermInEnum(iso, ODS_COUNTRY_ISO_CODE)) {
validateISO(iso?: ODS_FLAG_ISO_CODE): void {
console.log('iso', iso, odsIsTermInEnum(iso, ODS_FLAG_ISO_CODE))
if (!iso || !odsIsTermInEnum(iso, ODS_FLAG_ISO_CODE)) {
this.component.iso = undefined;
this.logger.warn(`The iso attribute must be one of those values ${ODS_COUNTRY_ISO_CODES}`);
this.logger.warn(`The iso attribute must be one of those values ${ODS_FLAG_ISO_CODES}`);
}
}

Expand Down
Loading

0 comments on commit 3d1f67f

Please sign in to comment.