1 |
www |
1 |
"use strict";
|
|
|
2 |
|
|
|
3 |
describe("separateDialCode:", function() {
|
|
|
4 |
|
|
|
5 |
beforeEach(function() {
|
|
|
6 |
intlSetup(true);
|
|
|
7 |
input = $("<input>").wrap("div");
|
|
|
8 |
});
|
|
|
9 |
|
|
|
10 |
afterEach(function() {
|
|
|
11 |
intlTeardown();
|
|
|
12 |
});
|
|
|
13 |
|
|
|
14 |
|
|
|
15 |
|
|
|
16 |
// we test with "gb" because the ntl number is different to the intl number (aside from the dial code)
|
|
|
17 |
describe("init plugin with initialCountry=gb", function() {
|
|
|
18 |
|
|
|
19 |
beforeEach(function() {
|
|
|
20 |
iti = window.intlTelInput(input[0], {
|
|
|
21 |
separateDialCode: true,
|
|
|
22 |
initialCountry: "gb",
|
|
|
23 |
});
|
|
|
24 |
});
|
|
|
25 |
|
|
|
26 |
it("sets the classes properly", function() {
|
|
|
27 |
expect(getParentElement()).toHaveClass("iti--separate-dial-code");
|
|
|
28 |
});
|
|
|
29 |
|
|
|
30 |
it("displays the dial code next to the selected flag", function() {
|
|
|
31 |
expect(getSelectedDialCodeElement().text()).toEqual("+44");
|
|
|
32 |
});
|
|
|
33 |
|
|
|
34 |
it("formats the placeholder correctly", function() {
|
|
|
35 |
// international format minus the dial code
|
|
|
36 |
expect(input.attr("placeholder")).toEqual("7400 123456");
|
|
|
37 |
});
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
describe("calling setNumber to a valid intl number", function() {
|
|
|
41 |
|
|
|
42 |
beforeEach(function() {
|
|
|
43 |
iti.setNumber("+447400123456");
|
|
|
44 |
});
|
|
|
45 |
|
|
|
46 |
it("formats the number correctly", function() {
|
|
|
47 |
// international format minus the dial code
|
|
|
48 |
expect(getInputVal()).toEqual("7400 123456");
|
|
|
49 |
});
|
|
|
50 |
|
|
|
51 |
it("calling getNumber returns the full intl number", function() {
|
|
|
52 |
expect(iti.getNumber()).toEqual("+447400123456");
|
|
|
53 |
});
|
|
|
54 |
|
|
|
55 |
});
|
|
|
56 |
|
|
|
57 |
});
|
|
|
58 |
|
|
|
59 |
|
|
|
60 |
// we test with "ca" because we had some bugs with area codes
|
|
|
61 |
describe("init plugin with initialCountry=ca", function() {
|
|
|
62 |
|
|
|
63 |
beforeEach(function() {
|
|
|
64 |
iti = window.intlTelInput(input[0], {
|
|
|
65 |
separateDialCode: true,
|
|
|
66 |
initialCountry: "ca",
|
|
|
67 |
});
|
|
|
68 |
});
|
|
|
69 |
|
|
|
70 |
it("sets the placeholder correctly", function() {
|
|
|
71 |
// used to be '234-5678'
|
|
|
72 |
expect(input.attr("placeholder")).toEqual("506-234-5678");
|
|
|
73 |
});
|
|
|
74 |
|
|
|
75 |
it("calling setNumber will set the number correctly", function() {
|
|
|
76 |
iti.setNumber("+15194971234");
|
|
|
77 |
// used to be '497-1234'
|
|
|
78 |
expect(getInputVal()).toEqual("519-497-1234");
|
|
|
79 |
});
|
|
|
80 |
|
|
|
81 |
});
|
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
// we test with "as" because we had a bug
|
|
|
86 |
describe("init plugin with initialCountry=as", function() {
|
|
|
87 |
|
|
|
88 |
beforeEach(function() {
|
|
|
89 |
iti = window.intlTelInput(input[0], {
|
|
|
90 |
separateDialCode: true,
|
|
|
91 |
initialCountry: "as",
|
|
|
92 |
});
|
|
|
93 |
});
|
|
|
94 |
|
|
|
95 |
it("sets the placeholder correctly", function() {
|
|
|
96 |
expect(input.attr("placeholder")).toEqual("684-733-1234");
|
|
|
97 |
});
|
|
|
98 |
|
|
|
99 |
it("calling setNumber will set the number correctly", function() {
|
|
|
100 |
iti.setNumber("+16847331234");
|
|
|
101 |
expect(getInputVal()).toEqual("684-733-1234");
|
|
|
102 |
});
|
|
|
103 |
|
|
|
104 |
});
|
|
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
// we test with "ru" because we had a bug
|
|
|
109 |
describe("init plugin with initialCountry=ru and valid ntl number", function() {
|
|
|
110 |
|
|
|
111 |
beforeEach(function() {
|
|
|
112 |
input.val("(922) 555-1234");
|
|
|
113 |
iti = window.intlTelInput(input[0], {
|
|
|
114 |
separateDialCode: true,
|
|
|
115 |
initialCountry: "ru",
|
|
|
116 |
});
|
|
|
117 |
});
|
|
|
118 |
|
|
|
119 |
it("formats the number correctly", function() {
|
|
|
120 |
// used to be '8 (922) 555-12-34'
|
|
|
121 |
expect(input.val()).toEqual("922 555-12-34");
|
|
|
122 |
});
|
|
|
123 |
|
|
|
124 |
});
|
|
|
125 |
|
|
|
126 |
});
|