1 |
www |
1 |
"use strict";
|
|
|
2 |
|
|
|
3 |
describe("multiple instances: init plugin (with nationalMode=false) to test multiple instances", function() {
|
|
|
4 |
|
|
|
5 |
var input2,
|
|
|
6 |
iti2,
|
|
|
7 |
afghanistanCountryCode = "af",
|
|
|
8 |
albaniaCountryCode = "al",
|
|
|
9 |
chinaCountryCode = "cn",
|
|
|
10 |
chinaDialCode = "+86";
|
|
|
11 |
|
|
|
12 |
beforeEach(function() {
|
|
|
13 |
intlSetup();
|
|
|
14 |
input = $("<input>").wrap("div");
|
|
|
15 |
input2 = $("<input>").wrap("div");
|
|
|
16 |
// japan and china
|
|
|
17 |
iti = window.intlTelInput(input[0], {
|
|
|
18 |
onlyCountries: [chinaCountryCode, afghanistanCountryCode],
|
|
|
19 |
nationalMode: false,
|
|
|
20 |
});
|
|
|
21 |
// korea, china and russia
|
|
|
22 |
iti2 = window.intlTelInput(input2[0], {
|
|
|
23 |
onlyCountries: ['kr', chinaCountryCode, 'ru', albaniaCountryCode],
|
|
|
24 |
nationalMode: false,
|
|
|
25 |
});
|
|
|
26 |
$("body").append(getParentElement(input)).append(getParentElement(input2));
|
|
|
27 |
});
|
|
|
28 |
|
|
|
29 |
afterEach(function() {
|
|
|
30 |
intlTeardown();
|
|
|
31 |
iti2.destroy();
|
|
|
32 |
input2.remove();
|
|
|
33 |
input2 = iti2 = null;
|
|
|
34 |
});
|
|
|
35 |
|
|
|
36 |
it("instances have different country lists", function() {
|
|
|
37 |
expect(getListLength()).toEqual(2);
|
|
|
38 |
expect(getListLength(input2)).toEqual(4);
|
|
|
39 |
});
|
|
|
40 |
|
|
|
41 |
it("instances have different default countries selected", function() {
|
|
|
42 |
expect(getSelectedFlagElement()).toHaveClass(`iti__${afghanistanCountryCode}`);
|
|
|
43 |
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
|
|
|
44 |
});
|
|
|
45 |
|
|
|
46 |
it("selecting an item from the first input dropdown only updates the flag on that input", function() {
|
|
|
47 |
selectFlag(chinaCountryCode);
|
|
|
48 |
expect(getInputVal()).toEqual(chinaDialCode);
|
|
|
49 |
expect(getInputVal(input2)).toEqual("");
|
|
|
50 |
});
|
|
|
51 |
|
|
|
52 |
it("updating the number on the first input only updates the flag on that input", function() {
|
|
|
53 |
input.val(chinaDialCode + " 123456");
|
|
|
54 |
triggerKeyOnInput(" ");
|
|
|
55 |
expect(getSelectedFlagElement()).toHaveClass(`iti__${chinaCountryCode}`);
|
|
|
56 |
expect(getSelectedFlagElement(input2)).toHaveClass(`iti__${albaniaCountryCode}`);
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
describe("clicking open dropdown on the first input", function() {
|
|
|
62 |
|
|
|
63 |
beforeEach(function() {
|
|
|
64 |
getSelectedFlagContainer()[0].click();
|
|
|
65 |
});
|
|
|
66 |
|
|
|
67 |
it("only opens the dropdown on that input", function() {
|
|
|
68 |
expect(getListElement()).toBeVisible();
|
|
|
69 |
expect(getListElement(input2)).not.toBeVisible();
|
|
|
70 |
});
|
|
|
71 |
|
|
|
72 |
it("then clicking open dropdown on the second will close the first and open the second", function() {
|
|
|
73 |
getSelectedFlagContainer(input2)[0].click();
|
|
|
74 |
expect(getListElement()).not.toBeVisible();
|
|
|
75 |
expect(getListElement(input2)).toBeVisible();
|
|
|
76 |
});
|
|
|
77 |
|
|
|
78 |
});
|
|
|
79 |
|
|
|
80 |
});
|