This repository has been archived by the owner on May 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 179
/
piechart-tests.js
73 lines (57 loc) · 2.36 KB
/
piechart-tests.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
'use strict';
var expect = require('chai').expect;
var React = require('react/addons');
var PieChart = require('../src/piechart').PieChart;
var generatePartsOfWhole = require('./utils/datagen').generatePartsOfWhole;
var TestUtils = React.addons.TestUtils;
describe('PieChart', function() {
var data = generatePartsOfWhole();
var values = data.map( (item) => item.value );
it('renders piechart', function() {
// Render a piechart using array data
var piechart = TestUtils.renderIntoDocument(
<PieChart data={data} width={400} height={200} />
);
// Verify that it has the same number of pies as the array's length
var pie = TestUtils.findRenderedDOMComponentWithClass(
piechart, 'rd3-piechart');
expect(pie).to.exist;
expect(pie.tagName).to.equal('g');
var pieGroup = TestUtils.findRenderedDOMComponentWithClass(piechart, 'rd3-piechart-pie');
expect(pieGroup).to.exist;
var chartSeries = TestUtils.scryRenderedDOMComponentsWithClass(piechart, 'rd3-piechart-arc');
expect(chartSeries.length).to.equal(values.length);
});
it('format value text from valueTextFormatter prop', function() {
// prefix our value text with $ sign by valueTextFormatter prop
var piechart = TestUtils.renderIntoDocument(
<PieChart
data={data} width={400} height={200}
valueTextFormatter={val=>'$'+val}
/>
);
var formattedValueTexts = TestUtils.scryRenderedDOMComponentsWithClass(piechart, 'rd3-piechart-value');
expect(formattedValueTexts.length).to.equal(values.length);
expect(formattedValueTexts[0].getDOMNode().textContent).to.contain('$');
});
it('doesnt show inner labels if not specified', function() {
var piechart = TestUtils.renderIntoDocument(
<PieChart
data={data} width={400} height={200}
showInnerLabels={false}
/>
);
var labels = TestUtils.scryRenderedDOMComponentsWithClass(piechart, 'rd3-piechart-value');
expect(labels.length).to.equal(0);
});
it('doesnt show outer labels if not specified', function() {
var piechart = TestUtils.renderIntoDocument(
<PieChart
data={data} width={400} height={200}
showOuterLabels={false}
/>
);
var labels = TestUtils.scryRenderedDOMComponentsWithClass(piechart, 'rd3-piechart-label');
expect(labels.length).to.equal(0);
});
});