-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
303 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = { | ||
'presets': [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
'targets': { | ||
'node': 'current', | ||
}, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import {testInstances} from './bootstrap'; | ||
|
||
describe.each(testInstances)('%s', (name1, Nette1) => { | ||
describe.each(testInstances)('%s', (name2, Nette2) => { | ||
if (name1 === name2) { | ||
return; | ||
} | ||
|
||
test('getPhoneNumber', () => { | ||
expect(Nette1.getPhoneNumber).toBeDefined(); | ||
expect(Nette1.getPhoneNumber) | ||
.not.toBe(Nette2.getPhoneNumber); | ||
}); | ||
|
||
test('validatePhoneNumber', () => { | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber).toBeDefined(); | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber) | ||
.not.toBe(Nette2.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber); | ||
}); | ||
|
||
test('validatePhoneNumberStrict', () => { | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict).toBeDefined(); | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict) | ||
.not.toBe(Nette2.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict); | ||
}); | ||
|
||
test('validatePhoneNumberRegion', () => { | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion).toBeDefined(); | ||
expect(Nette1.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion) | ||
.not.toBe(Nette2.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import metadata from 'libphonenumber-js/metadata.full'; | ||
import init from '../../dist/commonjs/index.cjs'; | ||
import NetteFactory from './netteFactory'; | ||
|
||
const Nette = NetteFactory(); | ||
init(Nette, metadata); | ||
|
||
export default Nette; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import metadata from 'libphonenumber-js/metadata.full'; | ||
import init from '../../src/assets/index.esm'; | ||
import NetteFactory from './netteFactory'; | ||
|
||
const Nette = NetteFactory(); | ||
init(Nette, metadata); | ||
|
||
export default Nette; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import NetteCjs from './bootstrap.cjs'; | ||
import NetteEsm from './bootstrap.esm'; | ||
import NetteUmd from './bootstrap.umd'; | ||
|
||
const testInstances = [ | ||
['src/assets/index.esm.js', NetteEsm], | ||
['dist/commonjs/index.cjs.js', NetteCjs], | ||
['dist/phone-number-input.js', NetteUmd], | ||
]; | ||
|
||
export {testInstances}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import '../../dist/phone-number-input'; | ||
import NetteFactory from './netteFactory'; | ||
|
||
export default NetteFactory(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import {testInstances} from './bootstrap'; | ||
|
||
describe.each(testInstances)('%s', (name, Nette) => { | ||
test('no default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
let phoneNumber; | ||
|
||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber).toBeNull(); | ||
|
||
input.value = 'abcdef'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber).toBeNull(); | ||
|
||
input.value = '800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber).toBeNull(); | ||
|
||
input.value = '+420 800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber.country).toBe('CZ'); | ||
expect(phoneNumber.number).toBe('+420800123456'); | ||
|
||
input.value = '+421 800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber.country).toBe('SK'); | ||
expect(phoneNumber.number).toBe('+421800123456'); | ||
}); | ||
|
||
test('CZ default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone" data-default-region-code="CZ"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
let phoneNumber; | ||
|
||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber).toBeNull(); | ||
|
||
input.value = 'abcdef'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber).toBeNull(); | ||
|
||
input.value = '800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber.country).toBe('CZ'); | ||
expect(phoneNumber.number).toBe('+420800123456'); | ||
|
||
input.value = '+420 800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber.country).toBe('CZ'); | ||
expect(phoneNumber.number).toBe('+420800123456'); | ||
|
||
input.value = '+421 800 12 34 56'; | ||
phoneNumber = Nette.getPhoneNumber(input); | ||
expect(phoneNumber.country).toBe('SK'); | ||
expect(phoneNumber.number).toBe('+421800123456'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import Nette from 'nette-forms'; | ||
|
||
export default () => { | ||
const clone = Object.assign({}, Nette); | ||
clone.validators = Object.assign({}, clone.validators); | ||
return clone; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {testInstances} from './bootstrap'; | ||
|
||
describe.each(testInstances)('%s', (name, Nette) => { | ||
test('no default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = '+42012'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = '+420 212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(true); | ||
|
||
input.value = '+420111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(true); | ||
}); | ||
|
||
test('CZ default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone" data-default-region-code="CZ"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = '+42012'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(true); | ||
|
||
input.value = '+420 212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(true); | ||
|
||
input.value = '+420111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumber(input)).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {testInstances} from './bootstrap'; | ||
|
||
describe.each(testInstances)('%s', (name, Nette) => { | ||
test('no default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'CZ'])).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'SK')).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'SK'])).toBe(false); | ||
|
||
input.value = '+421111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'CZ'])).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'SK')).toBe(true); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'SK'])).toBe(true); | ||
}); | ||
|
||
test('CZ default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone" data-default-region-code="CZ"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(true); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'CZ'])).toBe(true); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'SK')).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'SK'])).toBe(false); | ||
|
||
input.value = '+421111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'CZ')).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'CZ'])).toBe(false); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, 'SK')).toBe(true); | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberRegion(input, ['US', 'SK'])).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {testInstances} from './bootstrap'; | ||
|
||
describe.each(testInstances)('%s', (name, Nette) => { | ||
test('no default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = '+42012'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = '+420 212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(true); | ||
|
||
input.value = '+420111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
}); | ||
|
||
test('CZ default region', () => { | ||
document.body.innerHTML = '<form><input type="tel" name="phone" data-default-region-code="CZ"></form>'; | ||
const form = document.forms[0]; | ||
const input = form.elements[0]; | ||
|
||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = 'abcdef'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = '+42012'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
|
||
input.value = '212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(true); | ||
|
||
input.value = '+420 212 345 678'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(true); | ||
|
||
input.value = '+420111111111'; | ||
expect(Nette.validators.NepadaPhoneNumberInputValidator_validatePhoneNumberStrict(input)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/* eslint-disable no-undef */ | ||
module.exports = { | ||
transformIgnorePatterns: [], | ||
}; |