-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathinitialization.js
659 lines (508 loc) · 18.2 KB
/
initialization.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
(function(){
var ProgressBar = kendo.ui.ProgressBar,
container;
function moduleSetup() {
container = document.createElement("div");
$(container).appendTo(QUnit.fixture);
}
function moduleTeardown() {
kendo.destroy(QUnit.fixture);
}
// -----------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------
module("Initialization", {
setup: moduleSetup,
teardown: moduleTeardown
});
test("kendoProgressBar attaches a progressbar object to target", function() {
var dom = $('<div/>');
dom.appendTo(QUnit.fixture);
var pb = dom.kendoProgressBar();
ok(pb.data("kendoProgressBar") instanceof ProgressBar);
});
test("The element of the progressbar is set to the target from which it was initialized", function() {
var pb = new ProgressBar(container);
equal(pb.element[0], container);
});
test("Wrapper field is initialized", function() {
var pb = new ProgressBar(container);
equal(pb.wrapper[0], container);
});
test("Css classes are added to the wrapper", function() {
var pb = new ProgressBar(container);
ok(pb.wrapper.hasClass("k-widget"));
ok(pb.wrapper.hasClass("k-progressbar"));
});
test("Correct css classes for horizontal progressbar are added to the wrapper", function() {
var pb = new ProgressBar(container, {
orientation: "horizontal"
});
ok(pb.wrapper.hasClass("k-progressbar-horizontal"));
});
test("Correct css classes for vertical progressbar are added to the wrapper", function() {
var pb = new ProgressBar(container, {
orientation: "vertical"
});
ok(pb.wrapper.hasClass("k-progressbar-vertical"));
});
test("Correct css classes for horizontal reverse progressbar are added to the wrapper", function() {
var pb = new ProgressBar(container, {
reverse: true
});
ok(pb.wrapper.hasClass("k-progressbar-horizontal"));
ok(pb.wrapper.hasClass("k-progressbar-reverse"));
});
test("Correct css classes for vertical reverse progressbar are added to the wrapper", function() {
var pb = new ProgressBar(container, {
reverse: true,
orientation: "vertical"
});
ok(pb.wrapper.hasClass("k-progressbar-vertical"));
ok(pb.wrapper.hasClass("k-progressbar-reverse"));
});
test("Initial value is normalized correctly when it is less than min", function() {
var pb = new ProgressBar(container, {
min: 10,
max: 100,
value: 0
});
equal(pb.options.value, pb.options.min);
});
test("Initial value is normalized correctly when it is more than max", function() {
var pb = new ProgressBar(container, {
min: 10,
max: 100,
value: 1000
});
equal(pb.options.value, pb.options.max);
});
asyncTest("Start event is not fired on initialization when value is more than min", function() {
var startFired = false,
pb = new ProgressBar(container, {
min: 10,
max: 100,
value: 30,
start: function(){
startFired = true;
}
});
setTimeout(function() {
ok(!startFired);
start();
}, 50);
});
test("Progress property is set to width when orientation is horizontal", function() {
var pb = new ProgressBar(container, {
orientation: "horizontal"
});
equal(pb._progressProperty, "width");
});
test("Progress property is set to height when orientation is vertical", function() {
var pb = new ProgressBar(container, {
orientation: "vertical"
});
equal(pb._progressProperty, "height");
});
test("Animation duration is equal to default animation duration when not specified", function() {
var pb = new ProgressBar(container, { }),
defaultAnimationDuration = 400;
equal(pb._animation.duration, defaultAnimationDuration);
});
test("Animation is correctly set to false", function() {
var pb = new ProgressBar(container, {
animation: false
});
ok(!pb.options.animation);
});
test("Animation duration is overriden when specified by user", function() {
var pb = new ProgressBar(container, {
animation: {
duration: 789
}
});
equal(pb.options.animation.duration, 789);
});
test("k-progressbar-indeterminate class is set correctly when initial value is false (type='value')", function() {
var pb = new ProgressBar(container, {
value: false,
type: "value"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-progressbar-indeterminate class is set correctly when initial value is false (type='percent')", function() {
var pb = new ProgressBar(container, {
value: false,
type: "percent"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-progressbar-indeterminate class is set correctly when initial value is false (type='chunk')", function() {
var pb = new ProgressBar(container, {
value: false,
type: "chunk"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-progressbar-indeterminate class is not set when initial value is not false (type='value')", function() {
var pb = new ProgressBar(container, {
value: 20,
type: "value"
});
ok(!pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-progressbar-indeterminate class is not set when initial value is not false (type='percent')", function() {
var pb = new ProgressBar(container, {
value: 20,
type: "percent"
});
ok(!pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-progressbar-indeterminate class is not set when initial value is not false (type='chunk')", function() {
var pb = new ProgressBar(container, {
value: 20,
type: "chunk"
});
ok(!pb.wrapper.hasClass("k-progressbar-indeterminate"));
});
test("k-state-disabled class is added when ProgressBar is disabled initially", function() {
var pb = new ProgressBar(container, {
enable: false
});
ok(pb.wrapper.hasClass("k-state-disabled"));
});
test("Initial value is set correctly to false", function() {
var pb = new ProgressBar(container, {
value: false
});
equal(pb.value(), false);
});
test("Initial value false correctly sets status holder text to min (type='value')", function() {
var pb = new ProgressBar(container, {
value: false,
type: "value"
});
equal(pb.wrapper.children(".k-progress-status-wrap").text(), pb.options.min);
});
test("Initial value false correctly sets status holder text to min (type='percent')", function() {
var pb = new ProgressBar(container, {
value: false,
type: "percent"
});
equal(pb.wrapper.children(".k-progress-status-wrap").text(), pb.options.min + "%");
});
test("Progress wrapper is not added when initial value is false", function() {
var pb = new ProgressBar(container, {
value: false
});
equal(pb.wrapper.find(".k-state-selected").length, 0);
});
test("ProgressBar is correctly disabled and initial value is set to false (type='value')", 3, function() {
var pb = new ProgressBar(container, {
value: false,
enable: false,
type: "value"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
ok(pb.wrapper.hasClass("k-state-disabled"));
equal(pb.options.value, false);
});
test("ProgressBar is correctly disabled and initial value is set to false (type='percent')", 3, function() {
var pb = new ProgressBar(container, {
value: false,
enable: false,
type: "percent"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
ok(pb.wrapper.hasClass("k-state-disabled"));
equal(pb.options.value, false);
});
test("ProgressBar is correctly disabled and initial value is set to false (type='chunk')", 3, function() {
var pb = new ProgressBar(container, {
value: false,
enable: false,
type: "chunk"
});
ok(pb.wrapper.hasClass("k-progressbar-indeterminate"));
ok(pb.wrapper.hasClass("k-state-disabled"));
equal(pb.options.value, false);
});
test("_isStarted is set to false initially when value is equal to min", function(){
var pb = new ProgressBar(container, {
value: 0,
min: 0
});
equal(pb._isStarted, false);
});
test("_isStarted is set to false initially when value is not equal to min", function(){
var pb = new ProgressBar(container, {
value: 10,
min: 0
});
equal(pb._isStarted, false);
});
test("ProgressBar is initialized correctly via data attribute", function() {
var dom = $("<div data-role='progressbar'></div>");
$(container).append(dom);
kendo.init($(container));
ok($(container.firstChild).data("kendoProgressBar") instanceof ProgressBar);
});
test("ProgressBar value is set correctly via data attribute", function() {
var dom = $("<div data-role='progressbar' data-value='25'></div>");
$(container).append(dom);
kendo.init($(container));
equal($(container.firstChild).data("kendoProgressBar").value(), 25);
});
test("ProgressBar type is set correctly via data attribute", function() {
var dom = $("<div data-role='progressbar' data-type='chunk'></div>");
$(container).append(dom);
kendo.init($(container));
equal($(container.firstChild).data("kendoProgressBar").options.type, "chunk");
});
test("ProgressBar events are raised when set via data attribute", function() {
var dom = $("<div data-role='progressbar' data-bind='events: {change: onPbChange}' data-animation='false'></div>");
var fired = false;
$(container).append(dom);
var observable = kendo.observable({
onPbChange: function(e){
ok(true);
}
});
kendo.bind($(container), observable);
dom.data("kendoProgressBar").value(10);
});
test("Error is thrown when invalid type is passed", function() {
throws(function() {
var pb = new ProgressBar(container, {
type: "invalid"
});
});
});
test("Error is not thrown when type is 'value'", function() {
var pb = new ProgressBar(container, {
type: "value"
});
ok(true);
});
test("Error is not thrown when type is 'percent'", function() {
var pb = new ProgressBar(container, {
type: "percent"
});
ok(true);
});
test("Error is not thrown when type is 'chunk'", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(true);
});
test("progressStatus field is set when showStatus is true and value is equal to min (type='value')", function() {
var pb = new ProgressBar(container, {
type: "value"
});
equal(pb.progressStatus.length, 1);
});
test("progressStatus field is set when showStatus is true and value is equal to min (type='percent')", function() {
var pb = new ProgressBar(container, {
type: "percent"
});
equal(pb.progressStatus.length, 1);
});
test("progressStatus field is set when showStatus is true and value is not equal to min (type='value')", function() {
var pb = new ProgressBar(container, {
type: "value",
min: 0,
max: 10,
value: 5
});
equal(pb.progressStatus.length, 2);
});
test("progressStatus field is set when showStatus is true and value is not equal to min (type='percent')", function() {
var pb = new ProgressBar(container, {
type: "percent",
min: 0,
max: 10,
value: 5
});
equal(pb.progressStatus.length, 2);
});
test("progressStatus field is set to empty jQuery object when type is 'chunk'", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(pb.progressStatus instanceof jQuery);
});
test("progressWrapper field is set to empty jQuery object when type is 'chunk'", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(pb.progressWrapper instanceof jQuery);
});
test("progressWrapper field is set to empty jQuery object when value is equal to min (type='value')", function() {
var pb = new ProgressBar(container, {
type: "value",
min: 5,
value: 5
});
ok(pb.progressWrapper instanceof jQuery);
});
test("progressWrapper field is set to empty jQuery object when value is equal to min (type='percent')", function() {
var pb = new ProgressBar(container, {
type: "percent",
min: 5,
value: 5
});
ok(pb.progressWrapper instanceof jQuery);
});
test("progressWrapper field is set when value is not equal to min (type='value')", function() {
var pb = new ProgressBar(container, {
type: "value",
min: 5,
value: 10
});
ok(pb.hasOwnProperty("progressWrapper"));
});
test("progressWrapper field is set when value is not equal to min (type='percent')", function() {
var pb = new ProgressBar(container, {
type: "percent",
min: 5,
value: 10
});
ok(pb.hasOwnProperty("progressWrapper"));
});
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
module("Initialization / Regular ProgressBar", {
setup: moduleSetup,
teardown: moduleTeardown
});
test("ProgressBar wrapper is empty when value is equal to min and showStatus is false", function() {
var pb = new ProgressBar(container, {
min: 10,
value: 10,
showStatus: false
});
ok(pb.wrapper.is(":empty"));
});
test("ProgressBar contains empty div for progress wrapper when value is not equal to min and showStatus is false", function() {
var pb = new ProgressBar(container, {
min: 10,
value: 20,
showStatus: false
});
var progressWrapper = pb.wrapper.find(".k-state-selected");
equal(progressWrapper.length, 1);
ok(progressWrapper.is(":empty"));
});
test("Size of progress wrapper div reflects value when value is not equal to min and showStatus is false", function() {
var pb = new ProgressBar(container, {
min: 0,
max: 1000,
value: 200,
showStatus: false
});
var progressWrapperExpectedSize = pb._calculatePercentage().toFixed(2);
var actualProgressWrapperSize = parseFloat(pb.wrapper.find(".k-state-selected")[0].style.width).toFixed(2);
equal(actualProgressWrapperSize, progressWrapperExpectedSize);
});
test("ProgressBar wrapper contains progress status holder when value is equal to min and showStatus is true", function() {
var pb = new ProgressBar(container, {
showStatus: true
});
var progressStatusHolder = pb.wrapper.children("span.k-progress-status-wrap");
equal(progressStatusHolder.length, 1);
});
test("ProgressBar wrapper contains progress status holder and progress wrapper when value is not equal to min and showStatus is true", 3, function() {
var pb = new ProgressBar(container, {
min: 10,
max: 200,
value: 50,
showStatus: true
});
var progressStatusHolder = pb.wrapper.children("span.k-progress-status-wrap");
var progressWrapper = pb.wrapper.find(".k-state-selected");
var progressWrapperStatusHolder = $("span.k-progress-status-wrap", progressWrapper);
equal(progressStatusHolder.length, 1);
equal(progressWrapper.length, 1);
equal(progressWrapperStatusHolder.length, 1);
});
test("Status holder text is set correctly when value is not equal to min and showStatus is true", function() {
var pb = new ProgressBar(container, {
min: 10,
max: 200,
value: 50,
showStatus: true
});
equal(pb.wrapper.children("span.k-progress-status-wrap").text(), pb.options.value);
});
//-----------------------------------------------------------------------
//-----------------------------------------------------------------------
module("Initialization / Chunk ProgressBar", {
setup: moduleSetup,
teardown: moduleTeardown
});
test("Chunk ProgressBar contains a single ul element to hold the chunks", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
equal(pb.wrapper.find("ul.k-reset").length, 1);
});
test("Chunk ProgressBar contains a li element for each chunk", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
equal(pb.wrapper.find("li.k-item").length, pb.options.chunkCount);
});
test("Correct css class is added to each upcoming chunk", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(pb.wrapper.find("li.k-item").hasClass("k-state-default"));
});
test("Correct css class is added to the first chunk", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(pb.wrapper.find("li.k-item:first").hasClass("k-first"));
});
test("Correct css class is added to the last chunk", function() {
var pb = new ProgressBar(container, {
type: "chunk"
});
ok(pb.wrapper.find("li.k-item:last").hasClass("k-last"));
});
test("Correct css class is added to the completed chunks", function() {
var pb = new ProgressBar(container, {
type: "chunk",
value: 45
});
var completedChunks = pb.wrapper.find("li.k-item:lt(2)");
equal(pb.wrapper.find("li.k-item.k-state-selected").length, completedChunks.length);
});
test("Chunk size is calculated correctly according to chunk count", function() {
var pb = new ProgressBar(container, {
type: "chunk",
chunkCount: 17
});
var chunkCount = pb.options.chunkCount;
var chunkWrapperSize = pb.wrapper.find("ul.k-reset").width();
var expectedChunkSize = parseFloat(pb.wrapper.find("ul.k-reset li.k-item:first")[0].style.width).toFixed(2);
var actualChunkSize = (100 / pb.options.chunkCount).toFixed(2);
equal(actualChunkSize, expectedChunkSize);
});
test("Chunk count is reset to default if negative chunk count is passed", function() {
var pb = new ProgressBar(container, {
type: "chunk",
chunkCount: -5
});
var chunkCount = pb.options.chunkCount;
equal(chunkCount, 5);
});
test("Chunk count is reset to default if chunk count is less than two", function() {
var pb = new ProgressBar(container, {
type: "chunk",
chunkCount: 1
});
var chunkCount = pb.options.chunkCount;
equal(chunkCount, 5);
});
})();