|
| 1 | +var Plotly = require('@lib'); |
1 | 2 | var Plots = require('@src/plots/plots');
|
2 | 3 | var Lib = require('@src/lib');
|
3 | 4 | var BADNUM = require('@src/constants/numerical').BADNUM;
|
4 | 5 |
|
5 | 6 | var ScatterGeo = require('@src/traces/scattergeo');
|
6 | 7 |
|
| 8 | +var d3 = require('d3'); |
| 9 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 10 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 11 | +var customMatchers = require('../assets/custom_matchers'); |
| 12 | +var mouseEvent = require('../assets/mouse_event'); |
7 | 13 |
|
8 | 14 | describe('Test scattergeo defaults', function() {
|
9 | 15 | var traceIn,
|
@@ -221,3 +227,66 @@ describe('Test scattergeo calc', function() {
|
221 | 227 | ]);
|
222 | 228 | });
|
223 | 229 | });
|
| 230 | + |
| 231 | +describe('Test scattergeo hover', function() { |
| 232 | + var gd; |
| 233 | + |
| 234 | + // we can't mock ScatterGeo.hoverPoints |
| 235 | + // because geo hover relies on mouse event |
| 236 | + // to set the c2p conversion functions |
| 237 | + |
| 238 | + beforeAll(function() { |
| 239 | + jasmine.addMatchers(customMatchers); |
| 240 | + }); |
| 241 | + |
| 242 | + beforeEach(function(done) { |
| 243 | + gd = createGraphDiv(); |
| 244 | + |
| 245 | + Plotly.plot(gd, [{ |
| 246 | + type: 'scattergeo', |
| 247 | + lon: [10, 20, 30], |
| 248 | + lat: [10, 20, 30], |
| 249 | + text: ['A', 'B', 'C'] |
| 250 | + }]) |
| 251 | + .then(done); |
| 252 | + }); |
| 253 | + |
| 254 | + afterEach(destroyGraphDiv); |
| 255 | + |
| 256 | + function assertHoverLabels(expected) { |
| 257 | + var hoverText = d3.selectAll('g.hovertext').selectAll('tspan'); |
| 258 | + |
| 259 | + hoverText.each(function(_, i) { |
| 260 | + expect(this.innerHTML).toEqual(expected[i]); |
| 261 | + }); |
| 262 | + } |
| 263 | + |
| 264 | + it('should generate hover label info (base case)', function() { |
| 265 | + mouseEvent('mousemove', 381, 221); |
| 266 | + assertHoverLabels(['(10°, 10°)', 'A']); |
| 267 | + }); |
| 268 | + |
| 269 | + it('should generate hover label info (\'text\' single value case)', function(done) { |
| 270 | + Plotly.restyle(gd, 'text', 'text').then(function() { |
| 271 | + mouseEvent('mousemove', 381, 221); |
| 272 | + assertHoverLabels(['(10°, 10°)', 'text']); |
| 273 | + }) |
| 274 | + .then(done); |
| 275 | + }); |
| 276 | + |
| 277 | + it('should generate hover label info (\'hovertext\' single value case)', function(done) { |
| 278 | + Plotly.restyle(gd, 'hovertext', 'hovertext').then(function() { |
| 279 | + mouseEvent('mousemove', 381, 221); |
| 280 | + assertHoverLabels(['(10°, 10°)', 'hovertext']); |
| 281 | + }) |
| 282 | + .then(done); |
| 283 | + }); |
| 284 | + |
| 285 | + it('should generate hover label info (\'hovertext\' array case)', function(done) { |
| 286 | + Plotly.restyle(gd, 'hovertext', ['Apple', 'Banana', 'Orange']).then(function() { |
| 287 | + mouseEvent('mousemove', 381, 221); |
| 288 | + assertHoverLabels(['(10°, 10°)', 'Apple']); |
| 289 | + }) |
| 290 | + .then(done); |
| 291 | + }); |
| 292 | +}); |
0 commit comments