|
1 | 1 | var Plotly = require('@lib/index');
|
2 | 2 | var Lib = require('@src/lib');
|
| 3 | +var Drawing = require('@src/components/drawing'); |
3 | 4 |
|
4 | 5 | var d3 = require('d3');
|
5 | 6 | var createGraphDiv = require('../assets/create_graph_div');
|
@@ -367,5 +368,37 @@ describe('Plotly.Snapshot', function() {
|
367 | 368 | .catch(failTest)
|
368 | 369 | .then(done);
|
369 | 370 | });
|
| 371 | + |
| 372 | + it('should work on pages with <base>', function(done) { |
| 373 | + delete Drawing.baseUrl; |
| 374 | + var base = d3.select('body') |
| 375 | + .append('base') |
| 376 | + .attr('href', 'https://plot.ly'); |
| 377 | + |
| 378 | + Plotly.plot(gd, [{ y: [1, 2, 1] }], {}, {staticPlot: true}) |
| 379 | + .then(function() { return Plotly.Snapshot.toSVG(gd); }) |
| 380 | + .then(function(svg) { |
| 381 | + var svgDOM = parser.parseFromString(svg, 'image/svg+xml'); |
| 382 | + var gSubplot = svgDOM.getElementsByClassName('plot')[0]; |
| 383 | + var clipPath = gSubplot.getAttribute('clip-path'); |
| 384 | + var len = clipPath.length; |
| 385 | + |
| 386 | + var head = clipPath.substr(0, 4); |
| 387 | + var tail = clipPath.substr(len - 7, len); |
| 388 | + expect(head).toBe('url(', 'subplot clipPath head'); |
| 389 | + expect(tail).toBe('xyplot)', 'subplot clipPath tail'); |
| 390 | + |
| 391 | + var middle = clipPath.substr(5, 10); |
| 392 | + expect(middle.length).toBe(10, 'subplot clipPath uid length'); |
| 393 | + expect(middle.indexOf('http://')).toBe(-1, 'no <base> URL in subplot clipPath!'); |
| 394 | + expect(middle.indexOf('https://')).toBe(-1, 'no <base> URL in subplot clipPath!'); |
| 395 | + }) |
| 396 | + .catch(failTest) |
| 397 | + .then(function() { |
| 398 | + base.remove(); |
| 399 | + delete Drawing.baseUrl; |
| 400 | + done(); |
| 401 | + }); |
| 402 | + }); |
370 | 403 | });
|
371 | 404 | });
|
0 commit comments