Skip to content

Make gl plot interaction test more robust #266

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 2 commits into from
Feb 19, 2016
Merged
Show file tree
Hide file tree
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
24 changes: 24 additions & 0 deletions test/jasmine/assets/custom_matchers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module.exports = {

// toBeCloseTo... but for arrays
toBeCloseToArray: function(){
return {
compare: function(actual, expected, precision) {
if(precision !== 0){
precision = Math.pow(10, -precision) / 2 || 0.005;
}

var tested = actual.map(function(element, i) {
return Math.abs(expected[i] - element) < precision;
});

var passed = tested.indexOf(false) < 0;

return {
pass: passed,
message: 'Expected ' + actual + ' to be close to ' + expected + '.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Well done. 🎉

};
}
};
}
};
15 changes: 10 additions & 5 deletions test/jasmine/tests/gl_plot_interact_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var Lib = require('@src/lib');
var createGraphDiv = require('../assets/create_graph_div');
var destroyGraphDiv = require('../assets/destroy_graph_div');
var selectButton = require('../assets/modebar_button');
var customMatchers = require('../assets/custom_matchers');

/*
* WebGL interaction test cases fail on the CircleCI
Expand All @@ -18,6 +19,10 @@ var selectButton = require('../assets/modebar_button');
describe('Test plot structure', function() {
'use strict';

beforeEach(function() {
jasmine.addMatchers(customMatchers);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a way to inject this in the global scope?

That wouldn't have to add this line every time we want to use toBeCloseToArray

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The documentation on it says it should be in beforeEach blocks because it's torn down and rebuilt between specs, but there may be an unofficial way to have it bound globally in the tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

let's keep things in-sync with the officials ways.

});

afterEach(destroyGraphDiv);

describe('gl3d plots', function() {
Expand Down Expand Up @@ -148,7 +153,7 @@ describe('Test plot structure', function() {

describe('buttons resetCameraDefault3d and resetCameraLastSave3d', function() {
// changes in scene objects are not instantaneous
var DELAY = 1000;
var DELAY = 200;
Copy link
Contributor

Choose a reason for hiding this comment

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

nice.


it('should update the scene camera', function(done) {
var sceneLayout = gd._fullLayout.scene,
Expand All @@ -166,22 +171,22 @@ describe('Test plot structure', function() {
expect(sceneLayout.camera.eye)
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
expect(scene.camera.eye)
.toEqual([1.2500000000000002, 1.25, 1.25]);
.toBeCloseToArray([1.25, 1.25, 1.25], 4);
expect(sceneLayout2.camera.eye)
.toEqual({x: 2.5, y: 2.5, z: 2.5}, 'does not change the layout objects');
expect(scene2.camera.eye)
.toEqual([1.2500000000000002, 1.25, 1.25]);
.toBeCloseToArray([1.25, 1.25, 1.25], 4);

selectButton(modeBar, 'resetCameraLastSave3d').click();
setTimeout(function() {
expect(sceneLayout.camera.eye)
.toEqual({x: 0.1, y: 0.1, z: 1}, 'does not change the layout objects');
expect(scene.camera.eye)
.toEqual([ 0.10000000000000016, 0.10000000000000016, 1]);
.toBeCloseToArray([ 0.1, 0.1, 1], 4);
expect(sceneLayout2.camera.eye)
.toEqual({x: 2.5, y: 2.5, z: 2.5}, 'does not change the layout objects');
expect(scene2.camera.eye)
.toEqual([2.500000000000001, 2.5000000000000004, 2.5000000000000004]);
.toBeCloseToArray([2.5, 2.5, 2.5], 4);

done();
}, DELAY);
Expand Down