Skip to content

Commit

Permalink
add jasmine tests for parcoords to lock issue 4086
Browse files Browse the repository at this point in the history
  • Loading branch information
archmoj committed Jul 30, 2019
1 parent 8a2d707 commit b30f07e
Showing 1 changed file with 92 additions and 6 deletions.
98 changes: 92 additions & 6 deletions test/jasmine/tests/parcoords_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ function mouseTo(x, y) {
mouseEvent('mouseover', x, y);
}

function mostOfDrag(x1, y1, x2, y2) {
mouseTo(x1, y1);
mouseEvent('mousedown', x1, y1);
mouseEvent('mousemove', x2, y2);
}

function purgeGraphDiv(done) {
var gd = d3.select('.js-plotly-plot').node();
if(gd) Plotly.purge(gd);
Expand Down Expand Up @@ -1301,7 +1307,7 @@ describe('parcoords react more attributes', function() {
});
});

describe('parcoords constraint interactions', function() {
describe('parcoords constraint interactions - without defined axis ranges', function() {
var gd, initialDashArray0, initialDashArray1;

function initialFigure() {
Expand Down Expand Up @@ -1365,11 +1371,6 @@ describe('parcoords constraint interactions', function() {
return highlight.attributes['stroke-dasharray'].value.split(',').map(Number);
}

function mostOfDrag(x1, y1, x2, y2) {
mouseTo(x1, y1);
mouseEvent('mousedown', x1, y1);
mouseEvent('mousemove', x2, y2);
}

function checkDashCount(dashArray, intervals) {
// no-selection dasharrays have 2 entries:
Expand Down Expand Up @@ -1539,3 +1540,88 @@ describe('parcoords constraint interactions', function() {
.then(done);
});
});

describe('parcoords constraint interactions - with defined axis ranges', function() {
function initialFigure() {
return {
data: [{
type: 'parcoords',
dimensions: [{
values: [0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1],

}, {
values: [0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9],
tickvals: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
ticktext: ['a', 'b', 'c', 'd', 'e', 'f', 'i', 'j', 'k', 'l'],
range: [3, 7],
constraintrange: [4, 6]
}]
}],
layout: {
width: 400,
height: 400,
margin: {t: 100, b: 100, l: 100, r: 100}
}
};
}

var gd;
var initialSnapDuration;
var shortenedSnapDuration = 20;
var noSnapDelay = 20;
beforeAll(function() {
initialSnapDuration = PC.bar.snapDuration;
PC.bar.snapDuration = shortenedSnapDuration;
});

afterAll(function() {
purgeGraphDiv();
PC.bar.snapDuration = initialSnapDuration;
});

beforeEach(function(done) {
var hasGD = !!gd;
if(!hasGD) gd = createGraphDiv();

Plotly.react(gd, initialFigure())
.catch(failTest)
.then(done);
});

it('@noCI @gl updates constraints above and below axis ranges', function(done) {
expect(gd.data[0].dimensions[1].constraintrange).toBeCloseToArray([4, 6]);

var x = 295;

// first: move above range
mostOfDrag(x, 200, x, 100);
mouseEvent('mouseup', x, 100);
delay(noSnapDelay)()
.then(function() {
expect(gd.data[0].dimensions[1].constraintrange).toBeCloseToArray([5.75, 8.25]);
// move back
mostOfDrag(x, 110, x, 210);
mouseEvent('mouseup', x, 210);
})
.then(delay(noSnapDelay))
.then(function() {
expect(gd.data[0].dimensions[1].constraintrange).toBeCloseToArray([3.75, 6.25]);
// move below range
mostOfDrag(x, 200, x, 300);
mouseEvent('mouseup', x, 300);
})
.then(delay(noSnapDelay))
.then(function() {
expect(gd.data[0].dimensions[1].constraintrange).toBeCloseToArray([1.75, 4.25]);
// move back
mostOfDrag(x, 290, x, 190);
mouseEvent('mouseup', x, 190);
})
.then(delay(noSnapDelay))
.then(function() {
expect(gd.data[0].dimensions[1].constraintrange).toBeCloseToArray([3.75, 6.25]);
})
.catch(failTest)
.then(done);
});
});

0 comments on commit b30f07e

Please sign in to comment.