1 |
www |
1 |
"use strict";
|
|
|
2 |
|
|
|
3 |
describe("onlyCountries option:", function() {
|
|
|
4 |
|
|
|
5 |
var onlyCountries;
|
|
|
6 |
|
|
|
7 |
beforeEach(function() {
|
|
|
8 |
intlSetup();
|
|
|
9 |
input = $("<input>").wrap("div");
|
|
|
10 |
});
|
|
|
11 |
|
|
|
12 |
afterEach(function() {
|
|
|
13 |
intlTeardown();
|
|
|
14 |
});
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
|
|
|
18 |
describe("init plugin with onlyCountries set to japan, china and korea", function() {
|
|
|
19 |
|
|
|
20 |
var chinaCountryCode = "cn";
|
|
|
21 |
|
|
|
22 |
beforeEach(function() {
|
|
|
23 |
// China and Japan (note that none of the default preferredCountries are included here, so wont be in the list)
|
|
|
24 |
onlyCountries = ['jp', chinaCountryCode, 'kr'];
|
|
|
25 |
iti = window.intlTelInput(input[0], {
|
|
|
26 |
onlyCountries: onlyCountries,
|
|
|
27 |
});
|
|
|
28 |
});
|
|
|
29 |
|
|
|
30 |
it("defaults to the first onlyCountries alphabetically", function() {
|
|
|
31 |
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
|
|
|
32 |
});
|
|
|
33 |
|
|
|
34 |
it("has the right number of list items", function() {
|
|
|
35 |
expect(getListLength()).toEqual(onlyCountries.length);
|
|
|
36 |
});
|
|
|
37 |
|
|
|
38 |
});
|
|
|
39 |
|
|
|
40 |
|
|
|
41 |
describe("init plugin with onlyCountries for Afghanistan, Kazakhstan and Russia", function() {
|
|
|
42 |
|
|
|
43 |
beforeEach(function() {
|
|
|
44 |
iti = window.intlTelInput(input[0], {
|
|
|
45 |
preferredCountries: [],
|
|
|
46 |
onlyCountries: ["af", "kz", "ru"],
|
|
|
47 |
});
|
|
|
48 |
});
|
|
|
49 |
|
|
|
50 |
it("entering +7 defaults to the top priority country (Russia)", function() {
|
|
|
51 |
input.val("+");
|
|
|
52 |
triggerKeyOnInput("7");
|
|
|
53 |
expect(getSelectedFlagElement()).toHaveClass("iti__ru");
|
|
|
54 |
});
|
|
|
55 |
|
|
|
56 |
});
|
|
|
57 |
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
describe("init plugin on 2 different inputs with different onlyCountries and nationalMode = false", function() {
|
|
|
61 |
|
|
|
62 |
var input2,
|
|
|
63 |
iti2;
|
|
|
64 |
|
|
|
65 |
beforeEach(function() {
|
|
|
66 |
input2 = $("<input>").wrap("div");
|
|
|
67 |
// japan
|
|
|
68 |
iti = window.intlTelInput(input[0], {
|
|
|
69 |
onlyCountries: ['jp'],
|
|
|
70 |
nationalMode: false,
|
|
|
71 |
});
|
|
|
72 |
// korea
|
|
|
73 |
iti2 = window.intlTelInput(input2[0], {
|
|
|
74 |
onlyCountries: ['kr'],
|
|
|
75 |
nationalMode: false,
|
|
|
76 |
});
|
|
|
77 |
$("body").append(getParentElement(input)).append(getParentElement(input2));
|
|
|
78 |
});
|
|
|
79 |
|
|
|
80 |
afterEach(function() {
|
|
|
81 |
iti2.destroy();
|
|
|
82 |
input2.remove();
|
|
|
83 |
input2 = iti2 = null;
|
|
|
84 |
});
|
|
|
85 |
|
|
|
86 |
it("they both display their respective only country option as the selected flag", function() {
|
|
|
87 |
expect(getSelectedFlagElement()).toHaveClass("iti__jp");
|
|
|
88 |
expect(getSelectedFlagElement(input2)).toHaveClass("iti__kr");
|
|
|
89 |
});
|
|
|
90 |
|
|
|
91 |
});
|
|
|
92 |
|
|
|
93 |
});
|