Skip to content

Commit f8258cb

Browse files
committed
add sankey hover label style tests
1 parent e50886c commit f8258cb

File tree

1 file changed

+87
-15
lines changed

1 file changed

+87
-15
lines changed

test/jasmine/tests/sankey_test.js

+87-15
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var Sankey = require('@src/traces/sankey');
99

1010
var createGraphDiv = require('../assets/create_graph_div');
1111
var destroyGraphDiv = require('../assets/destroy_graph_div');
12+
var fail = require('../assets/fail_test');
1213
var mouseEvent = require('../assets/mouse_event');
1314

1415
describe('sankey tests', function() {
@@ -257,15 +258,8 @@ describe('sankey tests', function() {
257258
});
258259

259260
describe('lifecycle methods', function() {
260-
261261
afterEach(destroyGraphDiv);
262262

263-
function wait() {
264-
return new Promise(function(resolve) {
265-
setTimeout(resolve, 60);
266-
});
267-
}
268-
269263
it('Plotly.deleteTraces with two traces removes the deleted plot', function(done) {
270264

271265
var gd = createGraphDiv();
@@ -317,24 +311,102 @@ describe('sankey tests', function() {
317311
done();
318312
});
319313
});
314+
});
315+
316+
describe('Test hover/click interactions:', function() {
317+
afterEach(destroyGraphDiv);
318+
319+
function assertLabel(content, style) {
320+
var g = d3.selectAll('.hovertext');
321+
var lines = g.selectAll('.nums .line');
322+
var name = g.selectAll('.name');
323+
324+
expect(lines.size()).toBe(content.length - 1);
325+
326+
lines.each(function(_, i) {
327+
expect(d3.select(this).text()).toBe(content[i]);
328+
});
329+
330+
expect(name.text()).toBe(content[content.length - 1]);
331+
332+
var path = g.select('path');
333+
expect(path.style('fill')).toEqual(style[0], 'bgcolor');
334+
expect(path.style('stroke')).toEqual(style[1], 'bordercolor');
335+
336+
var text = g.select('text.nums');
337+
expect(parseInt(text.style('font-size'))).toEqual(style[2], 'font.size');
338+
expect(text.style('font-family').split(',')[0]).toEqual(style[3], 'font.family');
339+
expect(text.style('fill')).toEqual(style[4], 'font.color');
340+
}
320341

321-
it('Plotly.plot shows and removes tooltip on node, link', function(done) {
342+
it('should shows the correct hover labels', function(done) {
322343
var gd = createGraphDiv();
323344
var mockCopy = Lib.extendDeep({}, mock);
324345

346+
function _hover(px, py) {
347+
mouseEvent('mousemove', px, py);
348+
mouseEvent('mouseover', px, py);
349+
delete gd._lastHoverTime;
350+
}
351+
325352
Plotly.plot(gd, mockCopy).then(function() {
326-
mouseEvent('mousemove', 400, 300);
327-
mouseEvent('mouseover', 400, 300);
353+
_hover(400, 300);
354+
355+
assertLabel(
356+
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
357+
['rgb(148, 103, 189)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
358+
);
359+
})
360+
.then(function() {
361+
_hover(450, 300);
362+
363+
assertLabel(
364+
['Source: Solid', 'Target: Industry', '46TWh'],
365+
['rgb(0, 0, 96)', 'rgb(255, 255, 255)', 13, 'Arial', 'rgb(255, 255, 255)']
366+
);
367+
368+
return Plotly.relayout(gd, 'hoverlabel.font.family', 'Roboto');
369+
})
370+
.then(function() {
371+
_hover(400, 300);
372+
373+
assertLabel(
374+
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
375+
['rgb(148, 103, 189)', 'rgb(255, 255, 255)', 13, 'Roboto', 'rgb(255, 255, 255)']
376+
);
328377
})
329-
.then(wait)
330378
.then(function() {
331-
expect(d3.select('.hoverlayer>.hovertext>text').node().innerHTML)
332-
.toEqual('447TWh', 'tooltip present');
379+
_hover(450, 300);
380+
381+
assertLabel(
382+
['Source: Solid', 'Target: Industry', '46TWh'],
383+
['rgb(0, 0, 96)', 'rgb(255, 255, 255)', 13, 'Roboto', 'rgb(255, 255, 255)']
384+
);
385+
386+
return Plotly.restyle(gd, {
387+
'hoverlabel.bgcolor': 'red',
388+
'hoverlabel.bordercolor': 'blue',
389+
'hoverlabel.font.size': 20,
390+
'hoverlabel.font.color': 'black'
391+
});
333392
})
334393
.then(function() {
335-
mouseEvent('mousemove', 450, 300);
336-
mouseEvent('mouseover', 450, 300);
394+
_hover(400, 300);
395+
396+
assertLabel(
397+
['Solid', 'Incoming flow count: 4', 'Outgoing flow count: 3', '447TWh'],
398+
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 20, 'Roboto', 'rgb(0, 0, 0)']
399+
);
400+
})
401+
.then(function() {
402+
_hover(450, 300);
403+
404+
assertLabel(
405+
['Source: Solid', 'Target: Industry', '46TWh'],
406+
['rgb(255, 0, 0)', 'rgb(0, 0, 255)', 20, 'Roboto', 'rgb(0, 0, 0)']
407+
);
337408
})
409+
.catch(fail)
338410
.then(done);
339411
});
340412
});

0 commit comments

Comments
 (0)