Skip to content

Commit 6c72c77

Browse files
committed
test #984 - ensure we never override visibility
1 parent 0bb38e9 commit 6c72c77

File tree

1 file changed

+88
-0
lines changed

1 file changed

+88
-0
lines changed

test/jasmine/tests/page_test.js

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
var Plotly = require('@lib');
2+
var Lib = require('@src/lib');
3+
4+
var d3 = require('d3');
5+
var createGraphDiv = require('../assets/create_graph_div');
6+
var destroyGraphDiv = require('../assets/destroy_graph_div');
7+
var fail = require('../assets/fail_test');
8+
9+
10+
describe('page rendering', function() {
11+
'use strict';
12+
13+
var gd;
14+
15+
afterEach(destroyGraphDiv);
16+
17+
beforeEach(function() {
18+
gd = createGraphDiv();
19+
});
20+
21+
it('should hide all elements if the div is hidden with visibility:hidden', function(done) {
22+
// Note: we don't need to test the case of display: none, because that
23+
// halts all rendering of children, regardless of their display/visibility properties
24+
// and interestingly, unlike `visibility` which gets inherited as a computed style,
25+
// display: none does not propagate through to children so we can't actually see
26+
// that they're invisible - I guess the only way to tell that would be
27+
28+
// make a plot that has pretty much all kinds of plot elements
29+
// start with plot_types, because it has all the subplot types already
30+
var mock = Lib.extendDeep({}, require('@mocks/plot_types.json'));
31+
32+
mock.data.push(
33+
{type: 'contour', z: [[1, 2], [3, 4]], coloring: 'heatmap'}
34+
);
35+
36+
mock.layout.annotations = [
37+
{x: 1, y: 1, text: '$x+y$'},
38+
{x: 1, y: 1, text: 'not math', ax: -20, ay: -20}
39+
];
40+
41+
mock.layout.shapes = [{x0: 0.5, x1: 1.5, y0: 0.5, y1: 1.5}];
42+
43+
mock.layout.images = [{
44+
source: 'https://images.plot.ly/language-icons/api-home/python-logo.png',
45+
xref: 'paper',
46+
yref: 'paper',
47+
x: 0,
48+
y: 1,
49+
sizex: 0.2,
50+
sizey: 0.2,
51+
xanchor: 'right',
52+
yanchor: 'bottom'
53+
}];
54+
55+
// then merge in a few more with other component types
56+
mock.layout.updatemenus = require('@mocks/updatemenus.json').layout.updatemenus;
57+
mock.layout.sliders = require('@mocks/sliders.json').layout.sliders;
58+
59+
mock.layout.xaxis.title = 'XXX';
60+
mock.layout.showlegend = true;
61+
62+
return Plotly.newPlot(gd, mock.data, mock.layout).then(function() {
63+
var gd3 = d3.select(gd);
64+
var allPresentationElements = gd3.selectAll('path,text,rect,image,canvas');
65+
66+
gd3.style('visibility', 'hidden');
67+
68+
// visibility: hidden is inherited by all children (unless overridden
69+
// somewhere in the tree)
70+
allPresentationElements.each(function() {
71+
expect(d3.select(this).style('visibility')).toBe('hidden');
72+
});
73+
74+
gd3.style({visibility: null, display: 'none'});
75+
76+
// display: none is not inherited, but will zero-out the bounding box
77+
// in principle we shouldn't need to do this test, as display: none
78+
// cannot be overridden in a child, but it's included here for completeness.
79+
allPresentationElements.each(function() {
80+
var bBox = this.getBoundingClientRect();
81+
expect(bBox.width).toBe(0);
82+
expect(bBox.height).toBe(0);
83+
});
84+
})
85+
.catch(fail)
86+
.then(done);
87+
});
88+
});

0 commit comments

Comments
 (0)