-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathcustom_assertions.js
95 lines (74 loc) · 3.1 KB
/
custom_assertions.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
'use strict';
var d3 = require('d3');
exports.assertDims = function(dims) {
var traces = d3.selectAll('.trace');
expect(traces.size())
.toEqual(dims.length, 'to have correct number of traces');
traces.each(function(_, i) {
var trace = d3.select(this);
var points = trace.selectAll('.point');
expect(points.size())
.toEqual(dims[i], 'to have correct number of pts in trace ' + i);
});
};
exports.assertStyle = function(dims, color, opacity) {
var N = dims.reduce(function(a, b) {
return a + b;
});
var traces = d3.selectAll('.trace');
expect(traces.size())
.toEqual(dims.length, 'to have correct number of traces');
expect(d3.selectAll('.point').size())
.toEqual(N, 'to have correct total number of points');
traces.each(function(_, i) {
var trace = d3.select(this);
var points = trace.selectAll('.point');
expect(points.size())
.toEqual(dims[i], 'to have correct number of pts in trace ' + i);
points.each(function() {
expect(this.style.fill)
.toEqual(color[i], 'to have correct pt color');
var op = this.style.opacity;
expect(op === undefined ? 1 : +op)
.toEqual(opacity[i], 'to have correct pt opacity');
});
});
};
exports.assertHoverLabelStyle = function(g, expectation, msg, textSelector) {
if(!msg) msg = '';
var path = g.select('path').node();
expect(getComputedStyle(path).fill).toBe(expectation.bgcolor, msg + ': bgcolor');
expect(getComputedStyle(path).stroke).toBe(expectation.bordercolor, msg + ': bordercolor');
var text = g.select(textSelector || 'text.nums').node();
expect(getComputedStyle(text).fontFamily.split(',')[0]).toBe(expectation.fontFamily, msg + ': font.family');
expect(parseInt(getComputedStyle(text).fontSize)).toBe(expectation.fontSize, msg + ': font.size');
expect(getComputedStyle(text).fill).toBe(expectation.fontColor, msg + ': font.color');
};
exports.assertClip = function(sel, isClipped, size, msg) {
expect(sel.size()).toBe(size, msg + ' clip path (selection size)');
sel.each(function(d, i) {
var clipPath = d3.select(this).attr('clip-path');
if(isClipped) {
expect(String(clipPath).substr(0, 4))
.toBe('url(', msg + ' clip path ' + '(item ' + i + ')');
} else {
expect(clipPath)
.toBe(null, msg + ' clip path ' + '(item ' + i + ')');
}
});
};
exports.assertNodeDisplay = function(sel, expectation, msg) {
expect(sel.size())
.toBe(expectation.length, msg + ' display (selection size)');
sel.each(function(d, i) {
expect(d3.select(this).attr('display'))
.toBe(expectation[i], msg + ' display ' + '(item ' + i + ')');
});
};
exports.checkTicks = function(axLetter, vals, msg) {
var selection = d3.selectAll('.' + axLetter + 'tick text');
expect(selection.size()).toBe(vals.length);
selection.each(function(d, i) {
expect(d3.select(this).text()).toBe(vals[i], msg + ': ' + i);
});
};