Proyectos de Subversion LeadersLinked - Antes de SPA

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
693 steven 1
(function() {
2
  if (typeof process === 'object') {
3
    require('mocha-jsdom')();
4
  }
5
 
6
  var root = this;
7
  var assert = (root.chai || require('chai')).assert;
8
 
9
  describe('NProgress', function() {
10
    var $, NProgress;
11
 
12
    beforeEach(function() {
13
      $ = root.jQuery || require('jquery');
14
      NProgress = root.NProgress || require('../nprogress');
15
 
16
      this.settings = $.extend({}, NProgress.settings);
17
    });
18
 
19
    afterEach(function() {
20
      $("#nprogress").remove();
21
      $('html').attr('class', '');
22
      NProgress.status = null;
23
 
24
      // Restore settings
25
      $.extend(NProgress.settings, this.settings);
26
    });
27
 
28
    describe('.set()', function() {
29
      it('.set(0) must render', function(done) {
30
        NProgress.set(0);
31
        assert.equal($("#nprogress").length, 1);
32
        assert.equal($("#nprogress .bar").length, 1);
33
        assert.equal($("#nprogress .peg").length, 1);
34
        assert.equal($("#nprogress .spinner").length, 1);
35
        done();
36
      });
37
 
38
      it('.set(1) should appear and disappear', function(done) {
39
        NProgress.configure({ speed: 10 });
40
        NProgress.set(0).set(1);
41
        assert.equal($("#nprogress").length, 1);
42
 
43
        setTimeout(function() {
44
          assert.equal($("#nprogress").length, 0);
45
          done();
46
        }, 70);
47
      });
48
 
49
      it('must respect minimum', function() {
50
        NProgress.set(0);
51
        assert.equal(NProgress.status, NProgress.settings.minimum);
52
      });
53
 
54
      it('must clamp to minimum', function() {
55
        NProgress.set(-100);
56
        assert.equal(NProgress.status, NProgress.settings.minimum);
57
      });
58
 
59
      it('must clamp to maximum', function() {
60
        NProgress.set(456);
61
        assert.equal(NProgress.status, null);
62
      });
63
    });
64
 
65
    // ----
66
 
67
    describe('.start()', function() {
68
      it('must render', function(done) {
69
        NProgress.start();;
70
        assert.equal($("#nprogress").length, 1);
71
        done();
72
      });
73
 
74
      it('must respect minimum', function() {
75
        NProgress.start();;
76
        assert.equal(NProgress.status, NProgress.settings.minimum);
77
      });
78
 
79
      it('must be attached to specified parent', function() {
80
        var test = $('<div>', {id: 'test'}).appendTo('body');
81
        NProgress.configure({parent: '#test'});
82
        NProgress.start();;
83
        assert.isTrue($("#nprogress").parent().is(test));
84
        assert.isTrue($(NProgress.settings.parent).hasClass("nprogress-custom-parent"));
85
      });
86
    });
87
 
88
    // ----
89
 
90
    describe('.done()', function() {
91
      it('must not render without start', function(done) {
92
        NProgress.done();
93
        assert.equal($("#nprogress").length, 0);
94
        done();
95
      });
96
 
97
      it('.done(true) must render', function(done) {
98
        NProgress.done(true);
99
        assert.equal($("#nprogress").length, 1);
100
        done();
101
      });
102
    });
103
 
104
    // ----
105
 
106
    describe('.remove()', function() {
107
      it('should be removed from the parent', function() {
108
        NProgress.set(1);
109
        NProgress.remove();
110
 
111
        var parent = $(NProgress.settings.parent);
112
        assert.isFalse(parent.hasClass('nprogress-custom-parent'));
113
        assert.equal(parent.find('#nprogress').length, 0);
114
      });
115
    });
116
 
117
    // ----
118
 
119
    describe('.inc()', function() {
120
      it('should render', function() {
121
        NProgress.inc();
122
        assert.equal($("#nprogress").length, 1);
123
      });
124
 
125
      it('should start with minimum', function() {
126
        NProgress.inc();
127
        assert.equal(NProgress.status, NProgress.settings.minimum);
128
      });
129
 
130
      it('should increment', function() {
131
        NProgress.start();;
132
        var start = NProgress.status;
133
 
134
        NProgress.inc();
135
        assert.operator(NProgress.status, '>', start);
136
      });
137
 
138
      it('should never reach 1.0', function() {
139
        for (var i=0; i<100; ++i) { NProgress.inc(); }
140
        assert.operator(NProgress.status, '<', 1.0);
141
      });
142
    });
143
 
144
    // -----
145
 
146
    describe('.configure()', function() {
147
      it('should work', function() {
148
        NProgress.configure({ minimum: 0.5 });
149
        assert.equal(NProgress.settings.minimum, 0.5);
150
      });
151
    });
152
 
153
    // ----
154
 
155
    describe('.configure(showSpinner)', function() {
156
      it('should render spinner by default', function() {
157
        NProgress.start();;
158
 
159
        assert.equal($("#nprogress .spinner").length, 1);
160
      });
161
 
162
      it('should be true by default', function() {
163
        assert.equal(NProgress.settings.showSpinner, true);
164
      });
165
 
166
      it('should hide (on false)', function() {
167
        NProgress.configure({ showSpinner: false });
168
        NProgress.start();;
169
 
170
        assert.equal($("#nprogress .spinner").length, 0);
171
      });
172
    });
173
  });
174
 
175
})();