-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
79 lines (65 loc) · 2.16 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
describe('plugin', function () {
'use strict';
var Progress = require('./progress')
, assume = require('assume')
, plugin = require('./');
describe('Progress', function () {
var element;
beforeEach(function () {
element = {
style: {},
firstChild: {
value: 0,
style: {}
}
};
});
it('is exported as function', function () {
assume(Progress).is.a('function');
});
it('can be initialized without new', function () {
assume(Progress(element)).is.instanceOf(Progress);
});
it('hides the progress element by default', function () {
var progress = new Progress(element);
assume(element.style.opacity).equals(0);
});
describe('#set', function () {
it('hides the progress bar when an amount == 0 || 100 is set', function () {
var progress = new Progress(element);
assume(element.style.opacity).equals(0);
progress.set(10);
assume(element.style.opacity).equals(1);
progress.set(0);
assume(element.style.opacity).equals(0);
progress.set(40);
assume(element.style.opacity).equals(1);
progress.set(100);
assume(element.style.opacity).equals(0);
});
});
it('normalizes values below 0 or above 100', function () {
var progress = new Progress(element);
progress.set(10);
assume(element.firstChild.value).equals(10);
progress.set(-10);
assume(element.firstChild.value).equals(0);
progress.set(10);
assume(element.firstChild.value).equals(10);
progress.set(101);
assume(element.firstChild.value).equals(100);
});
it('sets the style if no value attribute is found', function () {
delete element.firstChild.value;
var progress = new Progress(element);
progress.set(10);
assume(element.firstChild.style.width).equals('10%');
progress.set(-10);
assume(element.firstChild.style.width).equals('0%');
progress.set(10);
assume(element.firstChild.style.width).equals('10%');
progress.set(19);
assume(element.firstChild.style.width).equals('19%');
});
});
});