|
1 | 1 | var Plotly = require('@lib');
|
2 | 2 | var Lib = require('@src/lib');
|
3 | 3 |
|
| 4 | +var d3 = require('d3'); |
4 | 5 | var createGraphDiv = require('../assets/create_graph_div');
|
5 | 6 | var destroyGraphDiv = require('../assets/destroy_graph_div');
|
6 | 7 | var failTest = require('../assets/fail_test');
|
@@ -210,4 +211,38 @@ describe('Plotly.toImage', function() {
|
210 | 211 | .catch(failTest)
|
211 | 212 | .then(done);
|
212 | 213 | });
|
| 214 | + |
| 215 | + it('should work on pages with <base>', function(done) { |
| 216 | + var parser = new DOMParser(); |
| 217 | + |
| 218 | + var base = d3.select('body') |
| 219 | + .append('base') |
| 220 | + .attr('href', 'https://plot.ly'); |
| 221 | + |
| 222 | + Plotly.plot(gd, [{ y: [1, 2, 1] }]) |
| 223 | + .then(function() { |
| 224 | + return Plotly.toImage(gd, {format: 'svg', imageDataOnly: true}); |
| 225 | + }) |
| 226 | + .then(function(svg) { |
| 227 | + var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); |
| 228 | + var gSubplot = svgDOM.getElementsByClassName('plot')[0]; |
| 229 | + var clipPath = gSubplot.getAttribute('clip-path'); |
| 230 | + var len = clipPath.length; |
| 231 | + |
| 232 | + var head = clipPath.substr(0, 4); |
| 233 | + var tail = clipPath.substr(len - 7, len); |
| 234 | + expect(head).toBe('url(', 'subplot clipPath head'); |
| 235 | + expect(tail).toBe('xyplot)', 'subplot clipPath tail'); |
| 236 | + |
| 237 | + var middle = clipPath.substr(4, 10); |
| 238 | + expect(middle.length).toBe(10, 'subplot clipPath uid length'); |
| 239 | + expect(middle.indexOf('http://')).toBe(-1, 'no <base> URL in subplot clipPath!'); |
| 240 | + expect(middle.indexOf('https://')).toBe(-1, 'no <base> URL in subplot clipPath!'); |
| 241 | + }) |
| 242 | + .catch(failTest) |
| 243 | + .then(function() { |
| 244 | + base.remove(); |
| 245 | + done(); |
| 246 | + }); |
| 247 | + }); |
213 | 248 | });
|
0 commit comments