Skip to content

Commit e80ec91

Browse files
committed
fix sankey test and clean log messages from other tests
1 parent 97821e9 commit e80ec91

File tree

5 files changed

+46
-34
lines changed

5 files changed

+46
-34
lines changed

src/lib/dates.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
var d3 = require('d3');
1313
var isNumeric = require('fast-isnumeric');
1414

15-
var logError = require('./loggers').error;
15+
var Loggers = require('./loggers');
1616
var mod = require('./mod');
1717

1818
var constants = require('../constants/numerical');
@@ -340,7 +340,7 @@ exports.cleanDate = function(v, dflt, calendar) {
340340
// do not allow milliseconds (old) or jsdate objects (inherently
341341
// described as gregorian dates) with world calendars
342342
if(isWorldCalendar(calendar)) {
343-
logError('JS Dates and milliseconds are incompatible with world calendars', v);
343+
Loggers.error('JS Dates and milliseconds are incompatible with world calendars', v);
344344
return dflt;
345345
}
346346

@@ -351,7 +351,7 @@ exports.cleanDate = function(v, dflt, calendar) {
351351
if(!v && dflt !== undefined) return dflt;
352352
}
353353
else if(!exports.isDateTime(v, calendar)) {
354-
logError('unrecognized date', v);
354+
Loggers.error('unrecognized date', v);
355355
return dflt;
356356
}
357357
return v;
@@ -551,7 +551,7 @@ exports.incrementMonth = function(ms, dMonth, calendar) {
551551
return (cDate.toJD() - EPOCHJD) * ONEDAY + timeMs;
552552
}
553553
catch(e) {
554-
logError('invalid ms ' + ms + ' in calendar ' + calendar);
554+
Loggers.error('invalid ms ' + ms + ' in calendar ' + calendar);
555555
// then keep going in gregorian even though the result will be 'Invalid'
556556
}
557557
}

test/jasmine/tests/annotations_test.js

+6
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ describe('Test annotations', function() {
9898
});
9999

100100
it('should clean *xclick* and *yclick* values', function() {
101+
var errors = [];
102+
spyOn(Loggers, 'error').and.callFake(function(msg) {
103+
errors.push(msg);
104+
});
105+
101106
var layoutIn = {
102107
annotations: [{
103108
clicktoshow: 'onoff',
@@ -139,6 +144,7 @@ describe('Test annotations', function() {
139144
expect(layoutOut.annotations[1]._yclick).toBe(undefined, 'invalid date');
140145
expect(layoutOut.annotations[2]._xclick).toBe(2, 'log');
141146
expect(layoutOut.annotations[2]._yclick).toBe('A', 'category');
147+
expect(errors.length).toBe(1);
142148
});
143149
});
144150
});

test/jasmine/tests/axes_test.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var d3 = require('d3');
33

44
var Plots = require('@src/plots/plots');
55
var Lib = require('@src/lib');
6+
var Loggers = require('@src/lib/loggers');
67
var Color = require('@src/components/color');
78
var tinycolor = require('tinycolor2');
89

@@ -1188,19 +1189,25 @@ describe('Test axes', function() {
11881189
expect(axOut.tick0).toBe('2000-01-01');
11891190
expect(axOut.dtick).toBe('M12');
11901191

1192+
var errors = [];
1193+
spyOn(Loggers, 'error').and.callFake(function(msg) {
1194+
errors.push(msg);
1195+
});
1196+
11911197
// now some stuff that shouldn't work, should give defaults
11921198
[
11931199
['next thursday', -1],
11941200
['123-45', 'L1'],
11951201
['', 'M0.5'],
11961202
['', 'M-1'],
11971203
['', '2000-01-01']
1198-
].forEach(function(v) {
1204+
].forEach(function(v, i) {
11991205
axIn = {tick0: v[0], dtick: v[1]};
12001206
axOut = {};
12011207
mockSupplyDefaults(axIn, axOut, 'date');
12021208
expect(axOut.tick0).toBe('2000-01-01');
12031209
expect(axOut.dtick).toBe(oneDay);
1210+
expect(errors.length).toBe(i + 1);
12041211
});
12051212
});
12061213

test/jasmine/tests/lib_date_test.js

+8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var isNumeric = require('fast-isnumeric');
22

33
var Lib = require('@src/lib');
4+
var Loggers = require('@src/lib/loggers');
45
var calComponent = require('@src/components/calendars');
56

67
// use only the parts of world-calendars that we've imported for our tests
@@ -360,6 +361,11 @@ describe('dates', function() {
360361
});
361362

362363
it('should fail numbers & js Dates out of range, and other bad objects', function() {
364+
var errors = [];
365+
spyOn(Loggers, 'error').and.callFake(function(msg) {
366+
errors.push(msg);
367+
});
368+
363369
[
364370
new Date(-20000, 0, 1),
365371
new Date(20000, 0, 1),
@@ -372,6 +378,8 @@ describe('dates', function() {
372378
if(!isNumeric(+v)) expect(Lib.cleanDate(+v)).toBeUndefined();
373379
expect(Lib.cleanDate(v, '2000-01-01')).toBe('2000-01-01');
374380
});
381+
382+
expect(errors.length).toBe(16);
375383
});
376384

377385
it('should not alter valid date strings, even to truncate them', function() {

test/jasmine/tests/sankey_test.js

+20-29
Original file line numberDiff line numberDiff line change
@@ -231,30 +231,19 @@ describe('sankey tests', function() {
231231

232232
var base = { type: 'sankey' };
233233

234-
it('circularity is detected', function() {
234+
describe('remove nodes if encountering circularity', function() {
235+
var errors;
235236

236-
var errors = [];
237-
spyOn(Lib, 'error').and.callFake(function(msg) {
238-
errors.push(msg);
237+
beforeEach(function() {
238+
errors = [];
239+
spyOn(Lib, 'error').and.callFake(function(msg) {
240+
errors.push(msg);
241+
});
239242
});
240243

241-
_calc(Lib.extendDeep({}, base, {
242-
node: {
243-
label: ['a', 'b', 'c']
244-
},
245-
link: {
246-
value: [1, 1, 1],
247-
source: [0, 1, 2],
248-
target: [1, 2, 0]
249-
}
250-
}));
251-
252-
expect(errors.length).toEqual(1);
253-
});
254-
255-
describe('remove nodes if encountering circularity', function() {
256-
257244
it('removing a single self-pointing node', function() {
245+
expect(errors.length).toBe(0);
246+
258247
var fullTrace = _calc(Lib.extendDeep({}, base, {
259248
node: {
260249
label: ['a']
@@ -270,10 +259,12 @@ describe('sankey tests', function() {
270259
expect(fullTrace.link.value).toEqual([], 'link value(s) removed');
271260
expect(fullTrace.link.source).toEqual([], 'link source(s) removed');
272261
expect(fullTrace.link.target).toEqual([], 'link target(s) removed');
273-
262+
expect(errors.length).toBe(1);
274263
});
275264

276265
it('removing everything if detecting a circle', function() {
266+
expect(errors.length).toBe(0);
267+
277268
var fullTrace = _calc(Lib.extendDeep({}, base, {
278269
node: {
279270
label: ['a', 'b', 'c', 'd', 'e']
@@ -289,7 +280,7 @@ describe('sankey tests', function() {
289280
expect(fullTrace.link.value).toEqual([], 'link value(s) removed');
290281
expect(fullTrace.link.source).toEqual([], 'link source(s) removed');
291282
expect(fullTrace.link.target).toEqual([], 'link target(s) removed');
292-
283+
expect(errors.length).toBe(1);
293284
});
294285
});
295286
});
@@ -390,15 +381,15 @@ describe('sankey tests', function() {
390381
_hover(404, 302);
391382

392383
assertLabel(
393-
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
384+
['Solid', 'incoming flow count: 4', 'outgoing flow count: 3', '447TWh'],
394385
['rgb(148, 103, 189)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
395386
);
396387
})
397388
.then(function() {
398389
_hover(450, 300);
399390

400391
assertLabel(
401-
['Source: Solid', 'Target: Industry', '46TWh'],
392+
['source: Solid', 'target: Industry', '46TWh'],
402393
['rgb(0, 0, 96)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
403394
);
404395

@@ -408,15 +399,15 @@ describe('sankey tests', function() {
408399
_hover(404, 302);
409400

410401
assertLabel(
411-
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
402+
['Solid', 'incoming flow count: 4', 'outgoing flow count: 3', '447TWh'],
412403
['rgb(148, 103, 189)', 'rgb(255, 255, 255)', 13, 'Roboto', 'rgb(255, 255, 255)']
413404
);
414405
})
415406
.then(function() {
416407
_hover(450, 300);
417408

418409
assertLabel(
419-
['Source: Solid', 'Target: Industry', '46TWh'],
410+
['source: Solid', 'target: Industry', '46TWh'],
420411
['rgb(0, 0, 96)', 'rgb(255, 255, 255)', 13, 'Roboto', 'rgb(255, 255, 255)']
421412
);
422413

@@ -431,15 +422,15 @@ describe('sankey tests', function() {
431422
_hover(404, 302);
432423

433424
assertLabel(
434-
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
425+
['Solid', 'incoming flow count: 4', 'outgoing flow count: 3', '447TWh'],
435426
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 20, 'Roboto', 'rgb(0, 0, 0)']
436427
);
437428
})
438429
.then(function() {
439430
_hover(450, 300);
440431

441432
assertLabel(
442-
['Source: Solid', 'Target: Industry', '46TWh'],
433+
['source: Solid', 'target: Industry', '46TWh'],
443434
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 20, 'Roboto', 'rgb(0, 0, 0)']
444435
);
445436
})
@@ -463,7 +454,7 @@ describe('sankey tests', function() {
463454
_hover(450, 300);
464455

465456
assertLabel(
466-
['Source: Solid', 'Target: Industry', '46TWh'],
457+
['source: Solid', 'target: Industry', '46TWh'],
467458
['rgb(0, 0, 96)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
468459
);
469460
})

0 commit comments

Comments
 (0)