Skip to content

Commit

Permalink
add doubleClickDelay config opt tests
Browse files Browse the repository at this point in the history
  • Loading branch information
etpinard committed Jul 22, 2019
1 parent bf794f1 commit 505e6e8
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 1 deletion.
44 changes: 43 additions & 1 deletion test/jasmine/tests/dragelement_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
var mouseEvent = require('../assets/mouse_event');
var touchEvent = require('../assets/touch_event');


describe('dragElement', function() {
'use strict';

Expand Down Expand Up @@ -141,6 +140,49 @@ describe('dragElement', function() {
expect(args[1].type).toBe('mousedown');
});

it('should pass numClicks and event to clickFn on mouseup after no/small mousemove w/ custom doubleClickDelay', function(done) {
var args = [];

this.gd._context.doubleClickDelay = 1000;

var options = {
element: this.element,
gd: this.gd,
clickFn: function() {
args = arguments;
},
moveFn: function() {
expect('should not call moveFn').toBe(true);
},
doneFn: function() {
expect('should not call doneFn').toBe(true);
}
};
dragElement.init(options);

mouseEvent('mousedown', this.x, this.y);
mouseEvent('mouseup', this.x, this.y);

expect(args.length).toBe(2);
expect(args[0]).toEqual(1);
// click gets the mousedown event, as that's guaranteed to have
// the correct target
expect(args[1].type).toBe('mousedown');

var _this = this;
setTimeout(function() {
mouseEvent('mousedown', _this.x, _this.y);
mouseEvent('mousemove', _this.x + 3, _this.y + 3);
mouseEvent('mouseup', _this.x, _this.y);

expect(args.length).toBe(2);
expect(args[0]).toEqual(2);
expect(args[1].type).toBe('mousedown');

done();
}, 500);
});

it('should add a cover slip div to the DOM', function() {
var options = { element: this.element, gd: this.gd };
dragElement.init(options);
Expand Down
68 changes: 68 additions & 0 deletions test/jasmine/tests/legend_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1759,3 +1759,71 @@ describe('legend DOM', function() {
.then(done);
});
});

describe('legend with custom doubleClickDelay', function() {
var gd;

beforeEach(function() {
gd = createGraphDiv();
});

afterEach(destroyGraphDiv);

function click(index) {
return function() {
var item = d3.selectAll('rect.legendtoggle')[0][index];
item.dispatchEvent(new MouseEvent('mousedown'));
item.dispatchEvent(new MouseEvent('mouseup'));
};
}

it('should differentiate clicks and double-clicks according *doubleClickDelay* config', function(done) {
var tLong = 1.5 * DBLCLICKDELAY;
var tShort = 0.75 * DBLCLICKDELAY;

var clickCnt = 0;
var dblClickCnt = 0;

function _assert(msg, _clickCnt, _dblClickCnt) {
return function() {
expect(clickCnt).toBe(_clickCnt, msg + '| clickCnt');
expect(dblClickCnt).toBe(_dblClickCnt, msg + '| dblClickCnt');
clickCnt = 0;
dblClickCnt = 0;
};
}

Plotly.plot(gd, [
{y: [1, 2, 1]},
{y: [2, 1, 2]}
], {}, {
doubleClickDelay: tLong
})
.then(function() {
gd.on('plotly_legendclick', function() { clickCnt++; });
gd.on('plotly_legenddoubleclick', function() { dblClickCnt++; });
})
.then(click(0)).then(delay(tLong / 2))
.then(_assert('[long] after click + (t/2) delay', 1, 0))
.then(delay(tLong + 10))
.then(click(0)).then(delay(DBLCLICKDELAY + 1)).then(click(0))
.then(_assert('[long] after click + (DBLCLICKDELAY+1) delay + click', 2, 1))
.then(delay(tLong + 10))
.then(click(0)).then(delay(1.1 * tLong)).then(click(0))
.then(_assert('[long] after click + (1.1*t) delay + click', 2, 0))
.then(delay(tLong + 10))
.then(function() {
return Plotly.plot(gd, [], {}, {doubleClickDelay: tShort});
})
.then(click(0)).then(delay(tShort / 2))
.then(_assert('[short] after click + (t/2) delay', 1, 0))
.then(delay(tShort + 10))
.then(click(0)).then(delay(DBLCLICKDELAY + 1)).then(click(0))
.then(_assert('[short] after click + (DBLCLICKDELAY+1) delay + click', 2, 0))
.then(delay(tShort + 10))
.then(click(0)).then(delay(1.1 * tShort)).then(click(0))
.then(_assert('[short] after click + (1.1*t) delay + click', 2, 0))
.catch(failTest)
.then(done);
}, 3 * jasmine.DEFAULT_TIMEOUT_INTERVAL);
});

0 comments on commit 505e6e8

Please sign in to comment.