Skip to content

Commit c89c895

Browse files
committed
move scattergeo & choropleth hover label test trace module suits
1 parent 90e2de1 commit c89c895

File tree

3 files changed

+105
-90
lines changed

3 files changed

+105
-90
lines changed

test/jasmine/tests/choropleth_test.js

+80
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,17 @@
11
var Choropleth = require('@src/traces/choropleth');
2+
3+
var Plotly = require('@lib');
24
var Plots = require('@src/plots/plots');
5+
var Lib = require('@src/lib');
6+
7+
var d3 = require('d3');
8+
var createGraphDiv = require('../assets/create_graph_div');
9+
var destroyGraphDiv = require('../assets/destroy_graph_div');
10+
var mouseEvent = require('../assets/mouse_event');
311

12+
var customAssertions = require('../assets/custom_assertions');
13+
var assertHoverLabelStyle = customAssertions.assertHoverLabelStyle;
14+
var assertHoverLabelContent = customAssertions.assertHoverLabelContent;
415

516
describe('Test choropleth', function() {
617
'use strict';
@@ -45,7 +56,76 @@ describe('Test choropleth', function() {
4556
Choropleth.supplyDefaults(traceIn, traceOut, defaultColor, layout);
4657
expect(traceOut.visible).toBe(false);
4758
});
59+
});
60+
});
61+
62+
describe('Test choropleth hover:', function() {
63+
var gd;
64+
65+
afterEach(destroyGraphDiv);
66+
67+
function run(pos, fig, content, style) {
68+
gd = createGraphDiv();
69+
70+
style = style || {
71+
bgcolor: 'rgb(68, 68, 68)',
72+
bordercolor: 'rgb(255, 255, 255)',
73+
fontColor: 'rgb(255, 255, 255)',
74+
fontSize: 13,
75+
fontFamily: 'Arial'
76+
};
77+
78+
return Plotly.plot(gd, fig).then(function() {
79+
mouseEvent('mousemove', pos[0], pos[1]);
80+
assertHoverLabelContent([content, null]);
81+
assertHoverLabelStyle(d3.select('g.hovertext'), style);
82+
});
83+
}
84+
85+
it('should generate hover label info (base)', function(done) {
86+
var fig = Lib.extendDeep({}, require('@mocks/geo_first.json'));
87+
88+
run(
89+
[400, 160],
90+
fig,
91+
[['RUS', '10', ''], 'trace 1']
92+
)
93+
.then(done);
94+
});
95+
96+
it('should generate hover label info (\'text\' array case)', function(done) {
97+
var fig = Lib.extendDeep({}, require('@mocks/geo_first.json'));
98+
fig.data[1].text = ['tExT', 'TeXt', '-text-'];
99+
fig.data[1].hoverinfo = 'text';
48100

101+
run(
102+
[400, 160],
103+
fig,
104+
['-text-', null]
105+
)
106+
.then(done);
49107
});
50108

109+
it('should generate hover label with custom styling', function(done) {
110+
var fig = Lib.extendDeep({}, require('@mocks/geo_first.json'));
111+
fig.data[1].hoverlabel = {
112+
bgcolor: 'red',
113+
bordercolor: ['blue', 'black', 'green'],
114+
font: {family: 'Roboto'}
115+
};
116+
117+
run(
118+
[400, 160],
119+
fig,
120+
[['RUS', '10', ''], 'trace 1'],
121+
{
122+
bgcolor: 'rgb(255, 0, 0)',
123+
bordercolor: 'rgb(0, 128, 0)',
124+
fontColor: 'rgb(0, 128, 0)',
125+
fontSize: 13,
126+
fontFamily: 'Roboto'
127+
}
128+
)
129+
.then(done);
130+
});
51131
});

test/jasmine/tests/geo_test.js

-90
Original file line numberDiff line numberDiff line change
@@ -553,72 +553,6 @@ describe('Test geo interactions', function() {
553553
Plotly.plot(gd, mockCopy.data, mockCopy.layout).then(done);
554554
});
555555

556-
describe('scattergeo hover labels', function() {
557-
it('should show one hover text group', function() {
558-
mouseEventScatterGeo('mousemove');
559-
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
560-
});
561-
562-
it('should show longitude and latitude values', function() {
563-
mouseEventScatterGeo('mousemove');
564-
565-
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][0];
566-
expect(node.innerHTML).toEqual('(0°, 0°)');
567-
});
568-
569-
it('should show the trace name', function() {
570-
mouseEventScatterGeo('mousemove');
571-
572-
var node = d3.selectAll('g.hovertext').selectAll('text')[0][0];
573-
expect(node.innerHTML).toEqual('trace 0');
574-
});
575-
576-
it('should show *text* (case 1)', function(done) {
577-
Plotly.restyle(gd, 'text', [['A', 'B']]).then(function() {
578-
mouseEventScatterGeo('mousemove');
579-
580-
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
581-
expect(node.innerHTML).toEqual('A');
582-
})
583-
.then(done);
584-
});
585-
586-
it('should show *text* (case 2)', function(done) {
587-
Plotly.restyle(gd, 'text', [[null, 'B']]).then(function() {
588-
mouseEventScatterGeo('mousemove');
589-
590-
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
591-
expect(node).toBeUndefined();
592-
})
593-
.then(done);
594-
});
595-
596-
it('should show *text* (case 3)', function(done) {
597-
Plotly.restyle(gd, 'text', [['', 'B']]).then(function() {
598-
mouseEventScatterGeo('mousemove');
599-
600-
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0][1];
601-
expect(node).toBeUndefined();
602-
})
603-
.then(done);
604-
});
605-
606-
it('should show custom \`hoverlabel\' settings', function(done) {
607-
Plotly.restyle(gd, {
608-
'hoverlabel.bgcolor': 'red',
609-
'hoverlabel.bordercolor': [['blue', 'black', 'green']]
610-
})
611-
.then(function() {
612-
mouseEventScatterGeo('mousemove');
613-
614-
var pathStyle = window.getComputedStyle(d3.select('g.hovertext path').node());
615-
expect(pathStyle.fill).toEqual('rgb(255, 0, 0)', 'bgcolor');
616-
expect(pathStyle.stroke).toEqual('rgb(0, 0, 255)', 'bordecolor[0]');
617-
})
618-
.then(done);
619-
});
620-
});
621-
622556
describe('scattergeo hover events', function() {
623557
var ptData, cnt;
624558

@@ -745,30 +679,6 @@ describe('Test geo interactions', function() {
745679
});
746680
});
747681

748-
describe('choropleth hover labels', function() {
749-
beforeEach(function() {
750-
mouseEventChoropleth('mouseover');
751-
mouseEventChoropleth('mousemove');
752-
});
753-
754-
it('should show one hover text group', function() {
755-
expect(d3.selectAll('g.hovertext').size()).toEqual(1);
756-
});
757-
758-
it('should show location and z values', function() {
759-
var node = d3.selectAll('g.hovertext').selectAll('tspan')[0];
760-
761-
expect(node[0].innerHTML).toEqual('RUS');
762-
expect(node[1].innerHTML).toEqual('10');
763-
});
764-
765-
it('should show the trace name', function() {
766-
var node = d3.selectAll('g.hovertext').selectAll('text')[0][0];
767-
768-
expect(node.innerHTML).toEqual('trace 1');
769-
});
770-
});
771-
772682
describe('choropleth hover events', function() {
773683
var ptData;
774684

test/jasmine/tests/scattergeo_test.js

+25
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,13 @@ describe('Test scattergeo hover', function() {
270270
check([381, 221], [['(10°, 10°)', 'A'], null]);
271271
});
272272

273+
it('should generate hover label info (with trace name)', function(done) {
274+
Plotly.restyle(gd, 'hoverinfo', 'lon+lat+text+name').then(function() {
275+
check([381, 221], [['(10°, 10°)', 'A'], 'trace 0']);
276+
})
277+
.then(done);
278+
});
279+
273280
it('should generate hover label info (\'text\' single value case)', function(done) {
274281
Plotly.restyle(gd, 'text', 'text').then(function() {
275282
check([381, 221], [['(10°, 10°)', 'text'], null]);
@@ -290,4 +297,22 @@ describe('Test scattergeo hover', function() {
290297
})
291298
.then(done);
292299
});
300+
301+
it('should generate hover label with custom styling', function(done) {
302+
Plotly.restyle(gd, {
303+
'hoverlabel.bgcolor': 'red',
304+
'hoverlabel.bordercolor': [['blue', 'black', 'green']]
305+
})
306+
.then(function() {
307+
check([381, 221], [['(10°, 10°)', 'A'], null], {
308+
bgcolor: 'rgb(255, 0, 0)',
309+
bordercolor: 'rgb(0, 0, 255)',
310+
fontColor: 'rgb(0, 0, 255)',
311+
fontSize: 13,
312+
fontFamily: 'Arial'
313+
});
314+
})
315+
.then(done);
316+
});
317+
293318
});

0 commit comments

Comments
 (0)