1 |
www |
1 |
"use strict";
|
|
|
2 |
|
|
|
3 |
|
|
|
4 |
describe("nationalMode:", function() {
|
|
|
5 |
|
|
|
6 |
beforeEach(function() {
|
|
|
7 |
intlSetup();
|
|
|
8 |
});
|
|
|
9 |
|
|
|
10 |
afterEach(function() {
|
|
|
11 |
intlTeardown();
|
|
|
12 |
});
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
describe("init plugin with no value", function() {
|
|
|
17 |
|
|
|
18 |
beforeEach(function() {
|
|
|
19 |
// must be in DOM for focus to work
|
|
|
20 |
input = $("<input>").appendTo("body");
|
|
|
21 |
iti = window.intlTelInput(input[0], {
|
|
|
22 |
nationalMode: true,
|
|
|
23 |
});
|
|
|
24 |
});
|
|
|
25 |
|
|
|
26 |
it("defaults to no dial code", function() {
|
|
|
27 |
expect(getInputVal()).toEqual("");
|
|
|
28 |
});
|
|
|
29 |
|
|
|
30 |
it("focusing the input does not insert the dial code", function() {
|
|
|
31 |
triggerInputEvent("focus");
|
|
|
32 |
expect(getInputVal()).toEqual("");
|
|
|
33 |
});
|
|
|
34 |
|
|
|
35 |
it("selecting another country does not insert the dial code", function() {
|
|
|
36 |
selectFlag("gb");
|
|
|
37 |
expect(getInputVal()).toEqual("");
|
|
|
38 |
});
|
|
|
39 |
|
|
|
40 |
it("but typing a dial code does still update the selected country", function() {
|
|
|
41 |
input.val("+");
|
|
|
42 |
triggerKeyOnInput("4");
|
|
|
43 |
triggerKeyOnInput("4");
|
|
|
44 |
expect(getSelectedFlagElement()).toHaveClass("iti__gb");
|
|
|
45 |
});
|
|
|
46 |
|
|
|
47 |
});
|
|
|
48 |
|
|
|
49 |
|
|
|
50 |
|
|
|
51 |
describe("init plugin with US national number and setCountry=us", function() {
|
|
|
52 |
|
|
|
53 |
var nationalNum = "702 418 1234";
|
|
|
54 |
|
|
|
55 |
beforeEach(function() {
|
|
|
56 |
input = $("<input value='" + nationalNum + "'>");
|
|
|
57 |
iti = window.intlTelInput(input[0], {
|
|
|
58 |
nationalMode: true,
|
|
|
59 |
});
|
|
|
60 |
iti.setCountry("us");
|
|
|
61 |
});
|
|
|
62 |
|
|
|
63 |
it("displays the number and has US flag selected", function() {
|
|
|
64 |
expect(getInputVal()).toEqual(nationalNum);
|
|
|
65 |
expect(getSelectedFlagElement()).toHaveClass("iti__us");
|
|
|
66 |
});
|
|
|
67 |
|
|
|
68 |
it("changing to canadian area code updates flag", function() {
|
|
|
69 |
input.val("204 555 555");
|
|
|
70 |
triggerKeyOnInput("5"); // trigger update flag
|
|
|
71 |
expect(getSelectedFlagElement()).toHaveClass("iti__ca");
|
|
|
72 |
});
|
|
|
73 |
|
|
|
74 |
});
|
|
|
75 |
|
|
|
76 |
|
|
|
77 |
|
|
|
78 |
describe("init plugin with intl number", function() {
|
|
|
79 |
|
|
|
80 |
var intlNumber = "+44 7733 123456";
|
|
|
81 |
|
|
|
82 |
beforeEach(function() {
|
|
|
83 |
input = $("<input value='" + intlNumber + "'>");
|
|
|
84 |
iti = window.intlTelInput(input[0], {
|
|
|
85 |
nationalMode: true,
|
|
|
86 |
});
|
|
|
87 |
});
|
|
|
88 |
|
|
|
89 |
it("displays the number and selects the right flag", function() {
|
|
|
90 |
expect(getInputVal()).toEqual(intlNumber);
|
|
|
91 |
expect(getSelectedFlagElement()).toHaveClass("iti__gb");
|
|
|
92 |
});
|
|
|
93 |
|
|
|
94 |
it("changing to another intl number updates the flag", function() {
|
|
|
95 |
input.val("+34 5555555");
|
|
|
96 |
triggerKeyOnInput("5"); // trigger update flag
|
|
|
97 |
expect(getSelectedFlagElement()).toHaveClass("iti__es");
|
|
|
98 |
});
|
|
|
99 |
|
|
|
100 |
});
|
|
|
101 |
|
|
|
102 |
});
|