Skip to content

Commit 505e6e8

Browse files
committed
add doubleClickDelay config opt tests
1 parent bf794f1 commit 505e6e8

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

test/jasmine/tests/dragelement_test.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ var destroyGraphDiv = require('../assets/destroy_graph_div');
66
var mouseEvent = require('../assets/mouse_event');
77
var touchEvent = require('../assets/touch_event');
88

9-
109
describe('dragElement', function() {
1110
'use strict';
1211

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

143+
it('should pass numClicks and event to clickFn on mouseup after no/small mousemove w/ custom doubleClickDelay', function(done) {
144+
var args = [];
145+
146+
this.gd._context.doubleClickDelay = 1000;
147+
148+
var options = {
149+
element: this.element,
150+
gd: this.gd,
151+
clickFn: function() {
152+
args = arguments;
153+
},
154+
moveFn: function() {
155+
expect('should not call moveFn').toBe(true);
156+
},
157+
doneFn: function() {
158+
expect('should not call doneFn').toBe(true);
159+
}
160+
};
161+
dragElement.init(options);
162+
163+
mouseEvent('mousedown', this.x, this.y);
164+
mouseEvent('mouseup', this.x, this.y);
165+
166+
expect(args.length).toBe(2);
167+
expect(args[0]).toEqual(1);
168+
// click gets the mousedown event, as that's guaranteed to have
169+
// the correct target
170+
expect(args[1].type).toBe('mousedown');
171+
172+
var _this = this;
173+
setTimeout(function() {
174+
mouseEvent('mousedown', _this.x, _this.y);
175+
mouseEvent('mousemove', _this.x + 3, _this.y + 3);
176+
mouseEvent('mouseup', _this.x, _this.y);
177+
178+
expect(args.length).toBe(2);
179+
expect(args[0]).toEqual(2);
180+
expect(args[1].type).toBe('mousedown');
181+
182+
done();
183+
}, 500);
184+
});
185+
144186
it('should add a cover slip div to the DOM', function() {
145187
var options = { element: this.element, gd: this.gd };
146188
dragElement.init(options);

test/jasmine/tests/legend_test.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1759,3 +1759,71 @@ describe('legend DOM', function() {
17591759
.then(done);
17601760
});
17611761
});
1762+
1763+
describe('legend with custom doubleClickDelay', function() {
1764+
var gd;
1765+
1766+
beforeEach(function() {
1767+
gd = createGraphDiv();
1768+
});
1769+
1770+
afterEach(destroyGraphDiv);
1771+
1772+
function click(index) {
1773+
return function() {
1774+
var item = d3.selectAll('rect.legendtoggle')[0][index];
1775+
item.dispatchEvent(new MouseEvent('mousedown'));
1776+
item.dispatchEvent(new MouseEvent('mouseup'));
1777+
};
1778+
}
1779+
1780+
it('should differentiate clicks and double-clicks according *doubleClickDelay* config', function(done) {
1781+
var tLong = 1.5 * DBLCLICKDELAY;
1782+
var tShort = 0.75 * DBLCLICKDELAY;
1783+
1784+
var clickCnt = 0;
1785+
var dblClickCnt = 0;
1786+
1787+
function _assert(msg, _clickCnt, _dblClickCnt) {
1788+
return function() {
1789+
expect(clickCnt).toBe(_clickCnt, msg + '| clickCnt');
1790+
expect(dblClickCnt).toBe(_dblClickCnt, msg + '| dblClickCnt');
1791+
clickCnt = 0;
1792+
dblClickCnt = 0;
1793+
};
1794+
}
1795+
1796+
Plotly.plot(gd, [
1797+
{y: [1, 2, 1]},
1798+
{y: [2, 1, 2]}
1799+
], {}, {
1800+
doubleClickDelay: tLong
1801+
})
1802+
.then(function() {
1803+
gd.on('plotly_legendclick', function() { clickCnt++; });
1804+
gd.on('plotly_legenddoubleclick', function() { dblClickCnt++; });
1805+
})
1806+
.then(click(0)).then(delay(tLong / 2))
1807+
.then(_assert('[long] after click + (t/2) delay', 1, 0))
1808+
.then(delay(tLong + 10))
1809+
.then(click(0)).then(delay(DBLCLICKDELAY + 1)).then(click(0))
1810+
.then(_assert('[long] after click + (DBLCLICKDELAY+1) delay + click', 2, 1))
1811+
.then(delay(tLong + 10))
1812+
.then(click(0)).then(delay(1.1 * tLong)).then(click(0))
1813+
.then(_assert('[long] after click + (1.1*t) delay + click', 2, 0))
1814+
.then(delay(tLong + 10))
1815+
.then(function() {
1816+
return Plotly.plot(gd, [], {}, {doubleClickDelay: tShort});
1817+
})
1818+
.then(click(0)).then(delay(tShort / 2))
1819+
.then(_assert('[short] after click + (t/2) delay', 1, 0))
1820+
.then(delay(tShort + 10))
1821+
.then(click(0)).then(delay(DBLCLICKDELAY + 1)).then(click(0))
1822+
.then(_assert('[short] after click + (DBLCLICKDELAY+1) delay + click', 2, 0))
1823+
.then(delay(tShort + 10))
1824+
.then(click(0)).then(delay(1.1 * tShort)).then(click(0))
1825+
.then(_assert('[short] after click + (1.1*t) delay + click', 2, 0))
1826+
.catch(failTest)
1827+
.then(done);
1828+
}, 3 * jasmine.DEFAULT_TIMEOUT_INTERVAL);
1829+
});

0 commit comments

Comments
 (0)