@@ -3,6 +3,7 @@ var Plotly = require('@lib/index');
33var d3 = require ( 'd3' ) ;
44var createGraphDiv = require ( '../assets/create_graph_div' ) ;
55var destroyGraphDiv = require ( '../assets/destroy_graph_div' ) ;
6+ var fail = require ( '../assets/fail_test' ) ;
67
78var subplotMock = require ( '../../image/mocks/multiple_subplots.json' ) ;
89var annotationMock = require ( '../../image/mocks/annotations.json' ) ;
@@ -191,16 +192,15 @@ describe('Plotly.Snapshot', function() {
191192 } ) ;
192193
193194 describe ( 'toSVG' , function ( ) {
194- var parser = new DOMParser ( ) ,
195- gd ;
195+ var parser = new DOMParser ( ) ;
196+ var gd ;
196197
197198 beforeEach ( function ( ) {
198199 gd = createGraphDiv ( ) ;
199200 } ) ;
200201
201202 afterEach ( destroyGraphDiv ) ;
202203
203-
204204 it ( 'should not return any nested svg tags of plots' , function ( done ) {
205205 Plotly . plot ( gd , subplotMock . data , subplotMock . layout ) . then ( function ( ) {
206206 return Plotly . Snapshot . toSVG ( gd ) ;
@@ -245,5 +245,53 @@ describe('Plotly.Snapshot', function() {
245245 done ( ) ;
246246 } ) ;
247247 } ) ;
248+
249+ it ( 'should handle quoted style properties' , function ( done ) {
250+ Plotly . plot ( gd , [ {
251+ y : [ 1 , 2 , 1 ] ,
252+ marker : {
253+ gradient : {
254+ type : 'radial' ,
255+ color : '#fff'
256+ } ,
257+ color : [ 'red' , 'blue' , 'green' ]
258+ }
259+ } ] , {
260+ font : { family : 'Times New Roman' }
261+ } )
262+ . then ( function ( ) {
263+ d3 . selectAll ( 'text' ) . each ( function ( ) {
264+ var tx = d3 . select ( this ) ;
265+ expect ( tx . style ( 'font-family' ) ) . toEqual ( '\"Times New Roman\"' ) ;
266+ } ) ;
267+
268+ d3 . selectAll ( '.point' ) . each ( function ( ) {
269+ var pt = d3 . select ( this ) ;
270+ expect ( pt . style ( 'fill' ) . substr ( 0 , 6 ) ) . toEqual ( 'url(\"#' ) ;
271+ } ) ;
272+
273+ return Plotly . Snapshot . toSVG ( gd ) ;
274+ } )
275+ . then ( function ( svg ) {
276+ var svgDOM = parser . parseFromString ( svg , 'image/svg+xml' ) ;
277+ var i ;
278+
279+ var textElements = svgDOM . getElementsByTagName ( 'text' ) ;
280+ expect ( textElements . length ) . toEqual ( 11 ) ;
281+
282+ for ( i = 0 ; i < textElements . length ; i ++ ) {
283+ expect ( textElements [ i ] . style [ 'font-family' ] ) . toEqual ( '\"Times New Roman\"' ) ;
284+ }
285+
286+ var pointElements = svgDOM . getElementsByClassName ( 'point' ) ;
287+ expect ( pointElements . length ) . toEqual ( 3 ) ;
288+
289+ for ( i = 0 ; i < pointElements . length ; i ++ ) {
290+ expect ( pointElements [ i ] . style . fill . substr ( 0 , 6 ) ) . toEqual ( 'url(\"#' ) ;
291+ }
292+ } )
293+ . catch ( fail )
294+ . then ( done ) ;
295+ } ) ;
248296 } ) ;
249297} ) ;
0 commit comments