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("geoIpLookup:", function() {
4
  var country = "gb",
5
    resolved = false;
6
 
7
  beforeEach(function() {
8
    intlSetup();
9
    // must be in DOM for geoIpLookup callback to work - it looks for $(".intl-tel-input input")
10
    input = $("<input>").appendTo("body");
11
  });
12
 
13
  afterEach(function() {
14
    intlTeardown();
15
    resolved = false;
16
  });
17
 
18
  describe("init vanilla plugin", function() {
19
    beforeEach(function(done) {
20
      iti = window.intlTelInput(input[0]);
21
      iti.promise.then(function() {
22
        resolved = true;
23
      });
24
      setTimeout(done);
25
    });
26
 
27
    it("does not resolve straight away", function() {
28
      expect(resolved).toEqual(true);
29
    });
30
  });
31
 
32
  describe("init plugin with geoIpLookup", function() {
33
    beforeEach(function() {
34
      iti = window.intlTelInput(input[0], {
35
        initialCountry: "auto",
36
        geoIpLookup: function(callback) {
37
          callback(country);
38
        },
39
      });
40
      iti.promise.then(function() {
41
        resolved = true;
42
      });
43
    });
44
 
45
    it("does not resolve straight away", function() {
46
      expect(resolved).toEqual(false);
47
    });
48
  });
49
 
50
  describe('init plugin with geoIpLookup, and wait for it to finish', function() {
51
    beforeEach(function(done) {
52
      iti = window.intlTelInput(input[0], {
53
        initialCountry: "auto",
54
        geoIpLookup: function(callback) {
55
          callback(country);
56
        },
57
      });
58
      iti.promise.then(function() {
59
        resolved = true;
60
        done();
61
      });
62
    });
63
 
64
    it("does resolve", function() {
65
      expect(resolved).toEqual(true);
66
    });
67
 
68
    describe('init a second instance with geoIpLookup', function() {
69
      var input2,
70
        iti2,
71
        resolved2 = false;
72
 
73
      beforeEach(function(done) {
74
        input2 = $("<input>").appendTo("body");
75
        iti2 = window.intlTelInput(input2[0], {
76
          initialCountry: "auto",
77
          geoIpLookup: function(callback) {
78
            callback(country);
79
          },
80
        });
81
        iti2.promise.then(function() {
82
          resolved2 = true;
83
        });
84
        setTimeout(done);
85
      });
86
 
87
      afterEach(function() {
88
        iti2.destroy();
89
        input2.remove();
90
        input2 = iti2 = null;
91
        resolved2 = false
92
      });
93
 
94
      it("does resolve straight away", function() {
95
        expect(window.intlTelInputGlobals.autoCountry).toEqual(country);
96
        expect(resolved2).toEqual(true);
97
      });
98
    });
99
  });
100
});