Skip to content

Commit 5f33a7b

Browse files
committed
plotly#189 updating preexisting test cases: further updates to proper axis order checking
1 parent 262c747 commit 5f33a7b

File tree

1 file changed

+70
-35
lines changed

1 file changed

+70
-35
lines changed

test/jasmine/tests/calcdata_test.js

+70-35
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('calculated data and points', function() {
3030
});
3131
});
3232

33-
xdescribe('category ordering', function() {
33+
describe('category ordering', function() {
3434

3535
describe('default category ordering reified', function() {
3636

@@ -68,6 +68,8 @@ describe('calculated data and points', function() {
6868

6969
describe('domain alphanumerical category ordering', function() {
7070

71+
// TODO augment test cases with selection on the DOM to ensure that ticks are there in proper order
72+
7173
it('should output categories in ascending domain alphanumerical order', function() {
7274

7375
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
@@ -82,7 +84,7 @@ describe('calculated data and points', function() {
8284
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));
8385
});
8486

85-
fit('should output categories in descending domain alphanumerical order', function() {
87+
it('should output categories in descending domain alphanumerical order', function() {
8688

8789
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
8890
type: 'category',
@@ -104,11 +106,11 @@ describe('calculated data and points', function() {
104106
categorylist: ['b','a','d','e','c'] // These must be ignored. Alternative: error?
105107
}});
106108

107-
expect(gd.calcdata[0][0].y).toEqual(11);
108-
expect(gd.calcdata[0][1].y).toEqual(13);
109-
expect(gd.calcdata[0][2].y).toEqual(15);
110-
expect(gd.calcdata[0][3].y).toEqual(14);
111-
expect(gd.calcdata[0][4].y).toEqual(12);
109+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 2, y: 15}));
110+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 0, y: 11}));
111+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 4, y: 12}));
112+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 1, y: 13}));
113+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));
112114
});
113115

114116
it('should output categories in ascending domain alphanumerical order, excluding undefined', function() {
@@ -118,14 +120,14 @@ describe('calculated data and points', function() {
118120
categorymode: 'category ascending'
119121
}});
120122

121-
expect(gd.calcdata[0][0].y).toEqual(11);
122-
expect(gd.calcdata[0][1].y).toEqual(15);
123-
expect(gd.calcdata[0][2].y).toEqual(14);
124-
expect(gd.calcdata[0][3].y).toEqual(12);
123+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 1, y: 15}));
124+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 3, y: 12}));
125+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
126+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14}));
125127
});
126128
});
127129

128-
describe('codomain numerical category ordering', function() {
130+
xdescribe('codomain numerical category ordering', function() {
129131

130132
it('should output categories in ascending codomain numerical order', function() {
131133

@@ -170,7 +172,7 @@ describe('calculated data and points', function() {
170172
});
171173
});
172174

173-
describe('explicit category ordering', function() {
175+
fdescribe('explicit category ordering', function() {
174176

175177
it('should output categories in explicitly supplied order, independent of trace order', function() {
176178

@@ -180,11 +182,11 @@ describe('calculated data and points', function() {
180182
categorylist: ['b','a','d','e','c']
181183
}});
182184

183-
expect(gd.calcdata[0][0].y).toEqual(13);
184-
expect(gd.calcdata[0][1].y).toEqual(11);
185-
expect(gd.calcdata[0][2].y).toEqual(14);
186-
expect(gd.calcdata[0][3].y).toEqual(12);
187-
expect(gd.calcdata[0][4].y).toEqual(15);
185+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15}));
186+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
187+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 3, y: 12}));
188+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
189+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14}));
188190
});
189191

190192
it('should output categories in explicitly supplied order, independent of trace order, pruned', function() {
@@ -195,41 +197,74 @@ describe('calculated data and points', function() {
195197
categorylist: ['b','a','d','e','c']
196198
}});
197199

198-
expect(gd.calcdata[0][0].y).toEqual(13);
199-
expect(gd.calcdata[0][1].y).toEqual(14);
200-
expect(gd.calcdata[0][2].y).toEqual(15);
200+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 4, y: 15}));
201+
expect(gd.calcdata[0][1]).toEqual({ x: false, y: false});
202+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 3, y: 12}));
203+
expect(gd.calcdata[0][3]).toEqual({ x: false, y: false});
204+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 2, y: 14}));
201205
});
202206

203207
it('should output categories in explicitly supplied order even if not all categories are present', function() {
204208

205209
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
206210
type: 'category',
207211
categorymode: 'array',
208-
categorylist: ['y','b','x','a','d','z','e','c']
212+
categorylist: ['b','x','a','d','z','e','c']
209213
}});
210214

211-
expect(gd.calcdata[0][0].y).toEqual(null);
212-
expect(gd.calcdata[0][1].y).toEqual(13);
213-
expect(gd.calcdata[0][2].y).toEqual(null);
214-
expect(gd.calcdata[0][3].y).toEqual(11);
215-
expect(gd.calcdata[0][4].y).toEqual(14);
216-
expect(gd.calcdata[0][5].y).toEqual(null);
217-
expect(gd.calcdata[0][6].y).toEqual(12);
218-
expect(gd.calcdata[0][7].y).toEqual(15);
215+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 15}));
216+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 2, y: 11}));
217+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 5, y: 12}));
218+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
219+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));
219220
});
220221

221-
it('should output categories in explicitly supplied order first, if not all categories are covered', function() {
222+
it('should output categories in explicitly supplied order even if some missing categories were at the beginning or end of categorylist', function() {
223+
224+
// TODO WARNING: THIS CASE *PASSES* BUT THE UNPOPULATED CATEGORIES AT THE EDGES AREN'T RENDERED IN THE DOM
225+
// TODO enhance test cases with selection on the DOM to ensure that all unpopulated ticks are present
226+
227+
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
228+
type: 'category',
229+
categorymode: 'array',
230+
categorylist: ['s','y','b','x','a','d','z','e','c', 'q', 'k']
231+
}});
232+
233+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 7, y: 15}));
234+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 3, y: 11}));
235+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 6, y: 12}));
236+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 1, y: 13}));
237+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 4, y: 14}));
238+
});
239+
240+
it('should output categories in explicitly supplied order even if not all categories are present, and should interact with a null value orthogonally', function() {
241+
242+
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,null,12,13,14]}], { xaxis: {
243+
type: 'category',
244+
categorymode: 'array',
245+
categorylist: ['b','x','a','d','z','e','c']
246+
}});
247+
248+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 6, y: 15}));
249+
expect(gd.calcdata[0][1]).toEqual({x: false, y: false});
250+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 5, y: 12}));
251+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
252+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 3, y: 14}));
253+
});
254+
255+
fit('should output categories in explicitly supplied order first, if not all categories are covered', function() {
222256

223257
Plotly.plot(gd, [{x: ['c','a','e','b','d'], y: [15,11,12,13,14]}], { xaxis: {
224258
type: 'category',
225259
categorymode: 'array',
226260
categorylist: ['b','a','x','c']
227261
}});
228262

229-
expect(gd.calcdata[0][0].y).toEqual(13);
230-
expect(gd.calcdata[0][1].y).toEqual(11);
231-
expect(gd.calcdata[0][2].y).toEqual(null);
232-
expect(gd.calcdata[0][3].y).toEqual(15);
263+
expect(gd.calcdata[0][0]).toEqual(jasmine.objectContaining({x: 3, y: 15}));
264+
expect(gd.calcdata[0][1]).toEqual(jasmine.objectContaining({x: 1, y: 11}));
265+
expect(gd.calcdata[0][2]).toEqual(jasmine.objectContaining({x: 4, y: 12}));
266+
expect(gd.calcdata[0][3]).toEqual(jasmine.objectContaining({x: 0, y: 13}));
267+
expect(gd.calcdata[0][4]).toEqual(jasmine.objectContaining({x: 5, y: 14}));
233268

234269
// The order of the rest is unspecified, no need to check. Alternative: make _both_ categorymode and
235270
// categories effective; categories would take precedence and the remaining items would be sorted

0 commit comments

Comments
 (0)