lion/packages/input-tel/test/formatters.test.js
gerjanvangeest 7239d60466
Fix/input tel format options (#1733)
* fix(input-tel): remove unwanted characters in parser

* feat(input-tel-dropdown): export getFlagSymbol function

* feat(input-tel): add formatCountryCodeStyle option
2022-06-15 08:11:40 +02:00

66 lines
2.2 KiB
JavaScript

import { expect } from '@open-wc/testing';
import { formatPhoneNumber } from '../src/formatters.js';
import { PhoneUtilManager } from '../src/PhoneUtilManager.js';
describe('formatPhoneNumber', () => {
beforeEach(async () => {
// Wait till PhoneUtilManager has been loaded
await PhoneUtilManager.loadComplete;
});
it('formats a phone number according to provided formatStrategy', () => {
expect(formatPhoneNumber('0707123456', { regionCode: 'SE', formatStrategy: 'e164' })).to.equal(
'+46707123456',
);
expect(
formatPhoneNumber('+46707123456', { regionCode: 'SE', formatStrategy: 'international' }),
).to.equal('+46 70 712 34 56');
expect(
formatPhoneNumber('+46707123456', { regionCode: 'SE', formatStrategy: 'national' }),
).to.equal('070-712 34 56');
expect(
formatPhoneNumber('+46707123456', { regionCode: 'SE', formatStrategy: 'rfc3966' }),
).to.equal('tel:+46-70-712-34-56');
expect(
formatPhoneNumber('+46707123456', { regionCode: 'SE', formatStrategy: 'significant' }),
).to.equal('707123456');
});
it('formats a phone number according to provided formatCountryCodeStyle', () => {
expect(
formatPhoneNumber('0707123456', {
regionCode: 'SE',
formatStrategy: 'e164',
formatCountryCodeStyle: 'parentheses',
}),
).to.equal('(+46)707123456');
expect(
formatPhoneNumber('+46707123456', {
regionCode: 'SE',
formatStrategy: 'international',
formatCountryCodeStyle: 'parentheses',
}),
).to.equal('(+46) 70 712 34 56');
expect(
formatPhoneNumber('+46707123456', {
regionCode: 'SE',
formatStrategy: 'national',
formatCountryCodeStyle: 'parentheses',
}),
).to.equal('070-712 34 56');
expect(
formatPhoneNumber('+46707123456', {
regionCode: 'SE',
formatStrategy: 'rfc3966',
formatCountryCodeStyle: 'parentheses',
}),
).to.equal('tel:(+46)-70-712-34-56');
expect(
formatPhoneNumber('+46707123456', {
regionCode: 'SE',
formatStrategy: 'significant',
formatCountryCodeStyle: 'parentheses',
}),
).to.equal('707123456');
});
});