Skip to content

Commit dae92a8

Browse files
committed
add regression tests
1 parent 716bac1 commit dae92a8

2 files changed

Lines changed: 85 additions & 0 deletions

File tree

test/jasmine/bundle_tests/mathjax_test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,48 @@ describe('Test MathJax v' + mathjaxVersion + ':', function() {
159159
.then(done, done.fail);
160160
});
161161
});
162+
163+
describe('Test tex rendering:', function() {
164+
var gd;
165+
166+
beforeEach(function() {
167+
gd = createGraphDiv();
168+
});
169+
170+
afterEach(destroyGraphDiv);
171+
172+
it('should hand tex titles and tick labels off to MathJax', function(done) {
173+
Plotly.newPlot(gd, {
174+
data: [{
175+
x: ['$\\phi$', '$\\nabla \\cdot \\vec{F}$'],
176+
y: [1, 2]
177+
}],
178+
layout: {
179+
title: { text: '$E = mc^2$' }
180+
}
181+
})
182+
.then(function() {
183+
var gd3 = d3Select(gd);
184+
185+
// '.gtitle-math-group' is only added once MathJax has typeset the
186+
// string, so its presence is what tells us the tex was rendered
187+
expect(gd3.selectAll('.gtitle-math-group').size()).toBe(1, 'title math group');
188+
189+
// tick label math groups carry the default 'text-math-group' class
190+
expect(gd3.selectAll('.text-math-group').size()).toBe(2, 'tick label math groups');
191+
192+
var rendered = [];
193+
gd3.selectAll('[class*=-math-group]').each(function() {
194+
expect(this.getAttribute('data-math')).toBe('Y');
195+
rendered.push(this.getAttribute('data-unformatted'));
196+
});
197+
expect(rendered.sort()).toEqual([
198+
'$E = mc^2$',
199+
'$\\nabla \\cdot \\vec{F}$',
200+
'$\\phi$'
201+
]);
202+
})
203+
.then(done, done.fail);
204+
});
205+
});
162206
});

test/jasmine/tests/svg_text_utils_test.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
var d3Select = require('../../strict-d3').select;
22
var d3SelectAll = require('../../strict-d3').selectAll;
33

4+
var Plotly = require('../../../lib/index');
45
var util = require('../../../src/lib/svg_text_utils');
56

7+
var createGraphDiv = require('../assets/create_graph_div');
8+
var destroyGraphDiv = require('../assets/destroy_graph_div');
9+
610

711
describe('svg+text utils', function() {
812
'use strict';
@@ -619,3 +623,40 @@ describe('sanitizeHTML', function() {
619623
expect(innerHTML).toEqual('<a href="https://example.com/?q=date%20%3E=%202018-01-01">click</a>');
620624
});
621625
});
626+
627+
// regression test for https://github.com/plotly/plotly.js/issues/7926
628+
describe('convertToTspans with an unsupported MathJax version', function() {
629+
'use strict';
630+
631+
var gd;
632+
var mathJaxBefore;
633+
634+
beforeEach(function() {
635+
gd = createGraphDiv();
636+
mathJaxBefore = window.MathJax;
637+
// Fake the presence of MathJax v2 by clearing window.MathJax
638+
// and setting window.MathJax.version to a v2.x version string
639+
window.MathJax = {version: '2.7.9'};
640+
});
641+
642+
afterEach(function() {
643+
if(mathJaxBefore === undefined) delete window.MathJax;
644+
else window.MathJax = mathJaxBefore;
645+
destroyGraphDiv();
646+
});
647+
648+
it('draws the plot with the tex left unevaluated', function(done) {
649+
Plotly.newPlot(gd, [{y: [1, 2, 3]}], {title: {text: '$x^2$'}})
650+
.then(function() {
651+
// whole plot should render except for tex string
652+
expect(d3SelectAll('.scatterlayer .trace').size()).toBe(1, 'trace');
653+
expect(d3SelectAll('.xtick').size()).toBeGreaterThan(0, 'x ticks');
654+
655+
var title = d3Select('.gtitle');
656+
expect(title.size()).toBe(1, 'title');
657+
expect(title.text()).toBe('$x^2$', 'raw tex as title');
658+
expect(title.node().style.display).not.toBe('none', 'title is visible');
659+
})
660+
.then(done, done.fail);
661+
});
662+
});

0 commit comments

Comments
 (0)