-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.test.js
More file actions
63 lines (54 loc) · 2.29 KB
/
Copy pathindex.test.js
File metadata and controls
63 lines (54 loc) · 2.29 KB
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
import test from 'ava';
import dthree from './index';
test('dthree should be an object', t => {
t.is(typeof dthree, 'object');
});
test('dthree.selectAll should be a function', t => {
t.is(typeof dthree.selectAll, 'function');
});
test('dthree.selectAll called without parameter should throw an error', t => {
t.throws(() => {
dthree.selectAll();
})
});
test('dthree.selectAll called with a parameter namespace should not throw an error', t => {
t.notThrows(() => {
dthree.selectAll('toto');
})
});
test('dthree.selectAll should return an object Selection', t => {
t.is(typeof dthree.selectAll('namespace'), 'object');
});
test('dthree.selectAll should return the same object Selection with a similar namespace param', t => {
t.is(dthree.selectAll('test'), dthree.selectAll('test'));
});
test('selections.data should populate a Selection', t => {
const sel = dthree.selectAll('test1').data([1, 2, 3]);
t.deepEqual(sel.enter(), [1, 2, 3]);
t.deepEqual(sel.update(), []);
t.deepEqual(sel.exit(), []);
t.deepEqual(sel.all(), [1, 2, 3]);
});
test('selections.data should update an existing selection', t => {
dthree.selectAll('test2').data([1, 2, 3, 4]);
dthree.selectAll('test2').data([1, 2, 3]);
t.deepEqual(dthree.selectAll('test2').enter(), []);
t.deepEqual(dthree.selectAll('test2').update(), [1, 2, 3]);
t.deepEqual(dthree.selectAll('test2').exit(), [4]);
t.deepEqual(dthree.selectAll('test2').all(), [1, 2, 3]);
dthree.selectAll('test2').data([1, 2, 4, 5]);
t.deepEqual(dthree.selectAll('test2').enter(), [5]);
t.deepEqual(dthree.selectAll('test2').update(), [1,2,4]);
t.deepEqual(dthree.selectAll('test2').exit(), []);
t.deepEqual(dthree.selectAll('test2').all(), [1,2,4,5]);
});
test('selections.data should update an existing selection with getKey', t => {
dthree.selectAll('test3').data([1, 2, 3, 4], (value, index) => `${value}_${index}`);
t.deepEqual(dthree.selectAll('test3').enter(), [1,2,3,4]);
t.deepEqual(dthree.selectAll('test3').update(), []);
t.deepEqual(dthree.selectAll('test3').exit(), []);
dthree.selectAll('test3').data([1, 3, 4, 5], (value, index) => `${value}_${index}`);
t.deepEqual(dthree.selectAll('test3').enter(), [3,4,5]);
t.deepEqual(dthree.selectAll('test3').update(), [1]);
t.deepEqual(dthree.selectAll('test3').exit(), [2,3,4]);
});