Skip to content

responsive tests: check size of DOM elements with getBoundingClientRect() #3484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions test/jasmine/tests/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ describe('config argument', function() {

describe('responsive figure', function() {
var gd;
var data = [{x: [1, 2, 3, 4], y: [5, 10, 2, 8]}];
var data = [{type: 'scatter', x: [1, 2, 3, 4], y: [5, 10, 2, 8]}];
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is scatter by default, but it is clearer if we make it explicit.

var width = 960;
var height = 800;

Expand All @@ -580,10 +580,17 @@ describe('config argument', function() {
function checkLayoutSize(width, height) {
expect(gd._fullLayout.width).toBe(width);
expect(gd._fullLayout.height).toBe(height);
}

var svg = document.getElementsByClassName('main-svg')[0];
expect(+svg.getAttribute('width')).toBe(width);
expect(+svg.getAttribute('height')).toBe(height);
function checkElementsSize(nodeList, width, height) {
var i;
for(i = 0; i < nodeList.length; i++) {
var domRect = nodeList[i].getBoundingClientRect();
expect(domRect.width).toBe(width);
expect(domRect.height).toBe(height);
expect(+nodeList[i].getAttribute('width')).toBe(width);
expect(+nodeList[i].getAttribute('height')).toBe(height);
}
}

function testResponsive() {
Expand All @@ -594,6 +601,13 @@ describe('config argument', function() {
.then(delay(RESIZE_DELAY))
.then(function() {
checkLayoutSize(elWidth / 2, elHeight / 2);

var mainSvgs = document.getElementsByClassName('main-svg');
checkElementsSize(mainSvgs, elWidth / 2, elHeight / 2);

var canvases = document.getElementsByTagName('canvas');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checking the size of the canvas elements sandwiched between the SVG elements is also very important.

checkElementsSize(canvases, elWidth / 2, elHeight / 2);

})
.catch(failTest);
}
Expand Down