-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.es6
101 lines (83 loc) · 3.02 KB
/
test.es6
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
import assert from 'assert';
import always from 'fj-always';
import { select, selectOne } from 'fd-select';
import { addClass, removeClass, toggleClass, hasClass } from './';
describe('fd-class', () => {
const HTML = `
<ul data-foo="bar" class="fruits">
<li class="fruit yummie tastie red">apple</li>
<li class="fruit yummie tastie red">orange</li>
<li class="fruit yummie tastie">plum</li>
</ul>
`;
let fixture, lis, li;
beforeEach(() => {
while (document.body.hasChildNodes()) {
document.body.removeChild(document.body.lastChild);
}
fixture = document.createElement('div');
fixture.innerHTML=HTML;
document.body.appendChild(fixture);
lis = select('.fruit');
li = selectOne('.fruit');
});
it('#addClass', () => {
addClass(always('hide'), [li])
assert(li.classList.contains('hide'));
assert(!lis[1].classList.contains('hide'));
assert(!lis[2].classList.contains('hide'));
addClass(always('blue'), lis)
assert(lis[0].classList.contains('blue'));
assert(lis[1].classList.contains('blue'));
assert(lis[2].classList.contains('blue'));
});
it('#removeClass', () => {
removeClass(always('yummie'), [li])
assert(!li.classList.contains('yummie'));
assert(lis[1].classList.contains('yummie'));
assert(lis[2].classList.contains('yummie'));
removeClass(always('tastie'), lis)
assert(!lis[0].classList.contains('tastie'));
assert(!lis[1].classList.contains('tastie'));
assert(!lis[2].classList.contains('tastie'));
});
it('#toggleClass', () => {
toggleClass(always('hide'), [li])
assert(li.classList.contains('hide'));
assert(!lis[1].classList.contains('hide'));
assert(!lis[2].classList.contains('hide'));
toggleClass(always('blue'), lis)
assert(lis[0].classList.contains('blue'));
assert(lis[1].classList.contains('blue'));
assert(lis[2].classList.contains('blue'));
toggleClass(always('hide'), [li])
assert(!li.classList.contains('hide'));
assert(!lis[1].classList.contains('hide'));
assert(!lis[2].classList.contains('hide'));
toggleClass(always('blue'), lis)
assert(!lis[0].classList.contains('blue'));
assert(!lis[1].classList.contains('blue'));
assert(!lis[2].classList.contains('blue'));
});
it('#hasClass', () => {
assert(hasClass(always('fruit'))(lis));
assert(!hasClass(always('red'))(lis));
});
it('#getClass should get the index of the element', () => {
function rowClass(idx) {
return 'row-' + idx;
}
addClass(rowClass, lis)
assert(lis[0].classList.contains('row-0'));
assert(lis[1].classList.contains('row-1'));
assert(lis[2].classList.contains('row-2'));
removeClass(rowClass, lis)
assert(!lis[0].classList.contains('row-0'));
assert(!lis[1].classList.contains('row-1'));
assert(!lis[2].classList.contains('row-2'));
toggleClass(rowClass, lis)
assert(lis[0].classList.contains('row-0'));
assert(lis[1].classList.contains('row-1'));
assert(lis[2].classList.contains('row-2'));
});
});