Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 www 1
"use strict";
2
 
3
describe("initial values:", function() {
4
 
5
  beforeEach(function() {
6
    intlSetup();
7
  });
8
 
9
  afterEach(function() {
10
    intlTeardown();
11
  });
12
 
13
 
14
 
15
  describe("init vanilla plugin on empty input", function() {
16
 
17
    beforeEach(function() {
18
      input = $("<input>").wrap("div");
19
      iti = window.intlTelInput(input[0]);
20
    });
21
 
22
    it("creates a container with the right class", function() {
23
      expect(getParentElement()).toHaveClass("iti");
24
    });
25
 
26
    it("has the right number of list items", function() {
27
      expect(getListLength()).toEqual(totalCountries + defaultPreferredCountries);
28
      expect(getPreferredCountriesLength()).toEqual(defaultPreferredCountries);
29
      // only 1 active list item
30
      expect(getActiveListItem().length).toEqual(1);
31
    });
32
 
33
    it("sets the state correctly: selected flag and active list item", function() {
34
      expect(getSelectedFlagElement()).toHaveClass("iti__us");
35
      expect(getActiveListItem().attr("data-country-code")).toEqual("us");
36
    });
37
 
38
  });
39
 
40
 
41
 
42
  describe("init vanilla plugin on input containing valid UK dial code", function() {
43
 
44
    beforeEach(function() {
45
      input = $("<input value='+44 12345'>");
46
      iti = window.intlTelInput(input[0]);
47
    });
48
 
49
    it("sets the state correctly: selected flag and active list item", function() {
50
      expect(getSelectedFlagElement()).toHaveClass("iti__gb");
51
      expect(getActiveListItem().attr("data-country-code")).toEqual("gb");
52
    });
53
 
54
  });
55
 
56
 
57
 
58
  describe("input containing valid regionless NANP number with intl dial code", function() {
59
 
60
    beforeEach(function() {
61
      input = $("<input value='+1 800 123 1234'>");
62
    });
63
 
64
    describe("init plugin with nationalMode enabled", function() {
65
 
66
      beforeEach(function() {
67
        iti = window.intlTelInput(input[0]);
68
      });
69
 
70
      it("defaults to US flag", function() {
71
        expect(getSelectedFlagElement()).toHaveClass("iti__us");
72
      });
73
 
74
    });
75
 
76
    describe("init plugin with nationalMode enabled and an initialCountry", function() {
77
 
78
      var initialCountry = "ca";
79
 
80
      beforeEach(function() {
81
        iti = window.intlTelInput(input[0], {
82
          initialCountry: initialCountry
83
        });
84
      });
85
 
86
      it("defaults to the initialCountry flag", function() {
87
        expect(getSelectedFlagElement()).toHaveClass(`iti__${initialCountry}`);
88
      });
89
 
90
    });
91
 
92
  });
93
 
94
 
95
 
96
  describe("init vanilla plugin on input containing valid Cook Island number with intl dial code", function() {
97
 
98
    beforeEach(function() {
99
      input = $("<input value='+682 21 234'>");
100
      iti = window.intlTelInput(input[0]);
101
    });
102
 
103
    // issue 520
104
    it("sets the selected flag correctly", function() {
105
      expect(getSelectedFlagElement()).toHaveClass("iti__ck");
106
    });
107
 
108
  });
109
 
110
 
111
 
112
  describe("init vanilla plugin on input containing number with invalid dial code", function() {
113
 
114
    beforeEach(function() {
115
      input = $("<input value='+969999'>");
116
      iti = window.intlTelInput(input[0]);
117
    });
118
 
119
    it("does not set the selected flag or the active list item", function() {
120
      expect(getSelectedFlagElement().attr("class")).toBe("iti__flag");
121
      expect(getActiveListItem().length).toEqual(0);
122
    });
123
 
124
  });
125
 
126
 
127
 
128
  describe("init vanilla plugin on input containing number with no dial code", function() {
129
 
130
    beforeEach(function() {
131
      input = $("<input value='8'>");
132
      iti = window.intlTelInput(input[0]);
133
    });
134
 
135
    it("does not set the selected flag or the active list item", function() {
136
      expect(getSelectedFlagElement().attr("class")).toBe("iti__flag");
137
      expect(getActiveListItem().length).toEqual(0);
138
    });
139
 
140
  });
141
 
142
});