Skip to content

Commit

Permalink
add interaction test case for double click
Browse files Browse the repository at this point in the history
  • Loading branch information
SlicedSilver committed Jun 29, 2023
1 parent 1eab8a7 commit bdb363d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
5 changes: 4 additions & 1 deletion tests/e2e/helpers/perform-interactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
doVerticalDrag,
} from './mouse-drag-actions';
import { doMouseScroll } from './mouse-scroll-actions';
import { pageTimeout } from './page-timeout';
import { doLongTouch, doPinchZoomTouch, doSwipeTouch } from './touch-actions';
import { doZoomInZoomOut } from './zoom-action';

Expand Down Expand Up @@ -84,7 +85,9 @@ async function performAction(
await target.click({ button: 'left' });
break;
case 'doubleClick':
await target.click({ button: 'left', clickCount: 2 });
await target.click({ button: 'left' });
await pageTimeout(page, 200);
await target.click({ button: 'left' });
break;
case 'outsideClick':
{
Expand Down
78 changes: 78 additions & 0 deletions tests/e2e/interactions/test-cases/mouse/double-click-pane.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
function generateData() {
const res = [];
const time = new Date(Date.UTC(2018, 0, 1, 0, 0, 0, 0));
for (let i = 0; i < 500; ++i) {
res.push({
time: time.getTime() / 1000,
value: i,
});

time.setUTCDate(time.getUTCDate() + 1);
}
return res;
}

function initialInteractionsToPerform() {
return [{ action: 'doubleClick', target: 'pane' }];
}

function finalInteractionsToPerform() {
return [];
}

let chart;
let clickCount = 0;
let dblClickCount = 0;

function beforeInteractions(container) {
chart = LightweightCharts.createChart(container);

const mainSeries = chart.addLineSeries();

const mainSeriesData = generateData();
mainSeries.setData(mainSeriesData);

chart.subscribeDblClick(mouseParams => {
if (!mouseParams) {
return;
}
dblClickCount += 1;
});
chart.subscribeClick(mouseParams => {
if (!mouseParams) {
return;
}
clickCount += 1;
});

return new Promise(resolve => {
requestAnimationFrame(() => {
resolve();
});
});
}

function afterInitialInteractions() {
return new Promise(resolve => {
requestAnimationFrame(resolve);
});
}

function afterFinalInteractions() {
if (clickCount < 1) {
throw new Error('Expected click event handler to be evoked.');
}
if (dblClickCount < 1) {
throw new Error('Expected double click event handler to be evoked.');
}
if (clickCount > 1) {
throw new Error('Expected click event handler to be evoked only once.');
}
if (dblClickCount > 1) {
throw new Error(
'Expected double click event handler to be evoked only once.'
);
}

return Promise.resolve();
}

0 comments on commit bdb363d

Please sign in to comment.