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