-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslider-test.js
101 lines (88 loc) · 2.68 KB
/
slider-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
var tape = require('tape');
var jsdom = require('jsdom');
var fs = require('fs');
var path = require('path');
d3 = Object.assign({}, require('d3-selection'), require('../'));
tape('sliderHorizontal() has the expected defaults', function(test) {
var s = d3.sliderHorizontal();
test.equal(s.tickFormat(), null);
test.end();
});
tape('slider.min(value), slider.max(value) set the expected values', function(
test
) {
var s = d3
.sliderHorizontal()
.min(100)
.max(200);
test.equal(s.min(), 100);
test.equal(s.max(), 200);
test.deepEqual(s.domain(), [100, 200]);
test.end();
});
tape('slider.domain([min,max]) sets the expected values', function(test) {
var s = d3.sliderHorizontal().domain([100, 200]);
test.deepEqual(s.domain(), [100, 200]);
test.equal(s.min(), 100);
test.equal(s.max(), 200);
test.end();
});
tape('slider.default(value) sets the default value', function(test) {
var s = d3.sliderHorizontal().default(10);
test.equal(s.value(), 10);
test.equal(s.default(), 10);
test.end();
});
tape('slider.default(value) sets the default range', function(test) {
var s = d3.sliderHorizontal().default([4, 8]);
test.deepEqual(s.value(), [4, 8]);
test.deepEqual(s.default(), [4, 8]);
test.end();
});
tape('sliderVertical(selection) produces the expected result', function(test) {
var window = new jsdom.JSDOM('<!DOCTYPE html><svg><g></g></svg>').window;
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);
var bodyActual = window.document.body;
var bodyExpected = new jsdom.JSDOM(file('slider-horizontal.html')).window
.document.body;
d3.select(bodyActual)
.select('g')
.call(d3.sliderHorizontal());
test.equal(bodyActual.outerHTML, bodyExpected.outerHTML);
test.end();
});
tape('sliderHorizontal(selection) produces the expected result', function(
test
) {
var window = new jsdom.JSDOM('<!DOCTYPE html><svg><g></g></svg>').window;
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js',
};
copyProps(window, global);
var bodyActual = window.document.body;
var bodyExpected = new jsdom.JSDOM(file('slider-vertical.html')).window
.document.body;
d3.select(bodyActual)
.select('g')
.call(d3.sliderVertical());
test.equal(bodyActual.outerHTML, bodyExpected.outerHTML);
test.end();
});
function file(file) {
return fs
.readFileSync(path.join(__dirname, file), 'utf8')
.replace(/\n\s*/gm, '');
}
function copyProps(src, target) {
Object.defineProperties(target, {
...Object.getOwnPropertyDescriptors(src),
...Object.getOwnPropertyDescriptors(target),
});
}