-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add interaction test case for double click
- Loading branch information
1 parent
1eab8a7
commit bdb363d
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
tests/e2e/interactions/test-cases/mouse/double-click-pane.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |