|
| 1 | +var d3 = require('d3'); |
| 2 | + |
| 3 | +var Plotly = require('@src/index'); |
| 4 | +var Fx = require('@src/plots/cartesian/graph_interact'); |
| 5 | +var Lib = require('@src/lib'); |
| 6 | + |
| 7 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 8 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 9 | + |
| 10 | +describe('hover info', function() { |
| 11 | + 'use strict'; |
| 12 | + |
| 13 | + var mock = require('@mocks/14.json'), |
| 14 | + evt = { |
| 15 | + clientX: mock.layout.width/ 2, |
| 16 | + clientY: mock.layout.height / 2 |
| 17 | + }; |
| 18 | + |
| 19 | + afterEach(destroyGraphDiv); |
| 20 | + |
| 21 | + describe('hover info', function() { |
| 22 | + var mockCopy = Lib.extendDeep({}, mock); |
| 23 | + |
| 24 | + beforeEach(function(done) { |
| 25 | + Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); |
| 26 | + }); |
| 27 | + |
| 28 | + it('responds to hover', function() { |
| 29 | + var gd = document.getElementById('graph'); |
| 30 | + Fx.hover('graph', evt, 'xy'); |
| 31 | + |
| 32 | + var hoverTrace = gd._hoverdata[0]; |
| 33 | + |
| 34 | + expect(hoverTrace.curveNumber).toEqual(0); |
| 35 | + expect(hoverTrace.pointNumber).toEqual(17); |
| 36 | + expect(hoverTrace.x).toEqual(0.388); |
| 37 | + expect(hoverTrace.y).toEqual(1); |
| 38 | + |
| 39 | + expect(d3.selectAll('g.axistext').size()).toEqual(1); |
| 40 | + expect(d3.selectAll('g.hovertext').size()).toEqual(1); |
| 41 | + expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); |
| 42 | + expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1'); |
| 43 | + }); |
| 44 | + }); |
| 45 | + |
| 46 | + describe('hover info x', function() { |
| 47 | + var mockCopy = Lib.extendDeep({}, mock); |
| 48 | + |
| 49 | + mockCopy.data[0].hoverinfo = 'x'; |
| 50 | + |
| 51 | + beforeEach(function(done) { |
| 52 | + Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); |
| 53 | + }); |
| 54 | + |
| 55 | + it('responds to hover x', function() { |
| 56 | + var gd = document.getElementById('graph'); |
| 57 | + Fx.hover('graph', evt, 'xy'); |
| 58 | + |
| 59 | + var hoverTrace = gd._hoverdata[0]; |
| 60 | + |
| 61 | + expect(hoverTrace.curveNumber).toEqual(0); |
| 62 | + expect(hoverTrace.pointNumber).toEqual(17); |
| 63 | + expect(hoverTrace.x).toEqual(0.388); |
| 64 | + expect(hoverTrace.y).toEqual(1); |
| 65 | + |
| 66 | + expect(d3.selectAll('g.axistext').size()).toEqual(1); |
| 67 | + expect(d3.selectAll('g.hovertext').size()).toEqual(0); |
| 68 | + expect(d3.selectAll('g.axistext').select('text').html()).toEqual('0.388'); |
| 69 | + }); |
| 70 | + }); |
| 71 | + |
| 72 | + describe('hover info y', function() { |
| 73 | + var mockCopy = Lib.extendDeep({}, mock); |
| 74 | + |
| 75 | + mockCopy.data[0].hoverinfo = 'y'; |
| 76 | + |
| 77 | + beforeEach(function(done) { |
| 78 | + Plotly.plot(createGraphDiv(), mockCopy.data, mockCopy.layout).then(done); |
| 79 | + }); |
| 80 | + |
| 81 | + it('responds to hover y', function() { |
| 82 | + var gd = document.getElementById('graph'); |
| 83 | + Fx.hover('graph', evt, 'xy'); |
| 84 | + |
| 85 | + var hoverTrace = gd._hoverdata[0]; |
| 86 | + |
| 87 | + expect(hoverTrace.curveNumber).toEqual(0); |
| 88 | + expect(hoverTrace.pointNumber).toEqual(17); |
| 89 | + expect(hoverTrace.x).toEqual(0.388); |
| 90 | + expect(hoverTrace.y).toEqual(1); |
| 91 | + |
| 92 | + expect(d3.selectAll('g.axistext').size()).toEqual(0); |
| 93 | + expect(d3.selectAll('g.hovertext').size()).toEqual(1); |
| 94 | + expect(d3.selectAll('g.hovertext').select('text').html()).toEqual('1'); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments