-
Notifications
You must be signed in to change notification settings - Fork 11.9k
/
Copy pathglobal.defaults.tests.js
153 lines (142 loc) · 4.21 KB
/
global.defaults.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
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
describe('Default Configs', function() {
describe('Doughnut Chart', function() {
it('should return correct legend label objects', function() {
var chart = window.acquireChart({
type: 'doughnut',
data: {
labels: ['label1', 'label2', 'label3'],
datasets: [{
data: [10, 20, NaN],
backgroundColor: ['red', 'green', 'blue'],
borderWidth: 2,
borderColor: '#000'
}]
},
});
var expected = [{
text: 'label1',
fillStyle: 'red',
fontColor: '#666',
hidden: false,
index: 0,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label2',
fillStyle: 'green',
fontColor: '#666',
hidden: false,
index: 1,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label3',
fillStyle: 'blue',
fontColor: '#666',
hidden: false,
index: 2,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}];
expect(chart.legend.legendItems).toEqual(expected);
});
it('should hide the correct arc when a legend item is clicked', function() {
var config = Chart.overrides.doughnut;
var chart = window.acquireChart({
type: 'doughnut',
data: {
labels: ['label1', 'label2', 'label3'],
datasets: [{
data: [10, 20, NaN],
backgroundColor: ['red', 'green', 'blue'],
borderWidth: 2,
borderColor: '#000'
}]
},
});
spyOn(chart, 'update').and.callThrough();
var legendItem = chart.legend.legendItems[0];
config.plugins.legend.onClick(null, legendItem, chart.legend);
expect(chart.getDataVisibility(0)).toBe(false);
expect(chart.update).toHaveBeenCalled();
config.plugins.legend.onClick(null, legendItem, chart.legend);
expect(chart.getDataVisibility(0)).toBe(true);
});
});
describe('Polar Area Chart', function() {
it('should return correct legend label objects', function() {
var chart = window.acquireChart({
type: 'polarArea',
data: {
labels: ['label1', 'label2', 'label3'],
datasets: [{
data: [10, 20, NaN],
backgroundColor: ['red', 'green', 'blue'],
borderWidth: 2,
borderColor: '#000'
}]
},
});
var expected = [{
text: 'label1',
fillStyle: 'red',
fontColor: '#666',
hidden: false,
index: 0,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label2',
fillStyle: 'green',
fontColor: '#666',
hidden: false,
index: 1,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}, {
text: 'label3',
fillStyle: 'blue',
fontColor: '#666',
hidden: false,
index: 2,
strokeStyle: '#000',
textAlign: undefined,
lineWidth: 2,
pointStyle: undefined
}];
expect(chart.legend.legendItems).toEqual(expected);
});
it('should hide the correct arc when a legend item is clicked', function() {
var config = Chart.overrides.polarArea;
var chart = window.acquireChart({
type: 'polarArea',
data: {
labels: ['label1', 'label2', 'label3'],
datasets: [{
data: [10, 20, NaN],
backgroundColor: ['red', 'green', 'blue'],
borderWidth: 2,
borderColor: '#000'
}]
},
});
spyOn(chart, 'update').and.callThrough();
var legendItem = chart.legend.legendItems[0];
config.plugins.legend.onClick(null, legendItem, chart.legend);
expect(chart.getDataVisibility(0)).toBe(false);
expect(chart.update).toHaveBeenCalled();
config.plugins.legend.onClick(null, legendItem, chart.legend);
expect(chart.getDataVisibility(0)).toBe(true);
});
});
});