@@ -158,6 +158,45 @@ describe('hover info', function() {
158
158
} ) ;
159
159
} ) ;
160
160
161
+ describe ( 'hover info with bad name' , function ( ) {
162
+ var mockCopy = Lib . extendDeep ( { } , mock ) ;
163
+
164
+ mockCopy . data [ 0 ] . text = [ ] ;
165
+ mockCopy . data [ 0 ] . text [ 17 ] = 'hover text' ;
166
+ mockCopy . data [ 0 ] . hoverinfo = 'all' ;
167
+ mockCopy . data [ 0 ] . name = '<img src=x onerror=y>' ;
168
+ mockCopy . data . push ( {
169
+ x : [ 0.002 , 0.004 ] ,
170
+ y : [ 12.5 , 16.25 ] ,
171
+ mode : 'lines+markers' ,
172
+ name : 'another trace'
173
+ } ) ;
174
+
175
+ beforeEach ( function ( done ) {
176
+ Plotly . plot ( createGraphDiv ( ) , mockCopy . data , mockCopy . layout ) . then ( done ) ;
177
+ } ) ;
178
+
179
+ it ( 'cleans the name' , function ( ) {
180
+ var gd = document . getElementById ( 'graph' ) ;
181
+ Fx . hover ( 'graph' , evt , 'xy' ) ;
182
+
183
+ var hoverTrace = gd . _hoverdata [ 0 ] ;
184
+
185
+ expect ( hoverTrace . curveNumber ) . toEqual ( 0 ) ;
186
+ expect ( hoverTrace . pointNumber ) . toEqual ( 17 ) ;
187
+ expect ( hoverTrace . x ) . toEqual ( 0.388 ) ;
188
+ expect ( hoverTrace . y ) . toEqual ( 1 ) ;
189
+
190
+ expect ( d3 . selectAll ( 'g.axistext' ) . size ( ) ) . toEqual ( 1 ) ;
191
+ expect ( d3 . selectAll ( 'g.hovertext' ) . size ( ) ) . toEqual ( 1 ) ;
192
+ expect ( d3 . selectAll ( 'g.axistext' ) . select ( 'text' ) . html ( ) ) . toEqual ( '0.388' ) ;
193
+ expect ( d3 . selectAll ( 'g.hovertext' ) . select ( 'text.nums' ) . selectAll ( 'tspan' ) . size ( ) ) . toEqual ( 2 ) ;
194
+ expect ( d3 . selectAll ( 'g.hovertext' ) . selectAll ( 'tspan' ) [ 0 ] [ 0 ] . innerHTML ) . toEqual ( '1' ) ;
195
+ expect ( d3 . selectAll ( 'g.hovertext' ) . selectAll ( 'tspan' ) [ 0 ] [ 1 ] . innerHTML ) . toEqual ( 'hover text' ) ;
196
+ expect ( d3 . selectAll ( 'g.hovertext' ) . selectAll ( 'text.name' ) . node ( ) . innerHTML ) . toEqual ( '<img src=x o...' ) ;
197
+ } ) ;
198
+ } ) ;
199
+
161
200
describe ( 'hover info y+text' , function ( ) {
162
201
var mockCopy = Lib . extendDeep ( { } , mock ) ;
163
202
0 commit comments