Skip to content

Commit 6ee0c61

Browse files
committed
Add a test for hover()
1 parent ff50849 commit 6ee0c61

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

tests/index.js

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,71 @@ test('select()', async (t) => {
17521752
scatterplot.destroy();
17531753
});
17541754

1755+
test('hover()', async (t) => {
1756+
const scatterplot = createScatterplot({ canvas: createCanvas() });
1757+
1758+
const points = [
1759+
[0, 0],
1760+
[1, 1],
1761+
[1, -1],
1762+
[-1, -1],
1763+
[-1, 1],
1764+
];
1765+
1766+
await scatterplot.draw(points);
1767+
1768+
let hovering;
1769+
const pointoverHandler = (newHovering) => {
1770+
hovering = newHovering;
1771+
};
1772+
const pointoutHandler = () => {
1773+
hovering = undefined;
1774+
};
1775+
scatterplot.subscribe('pointover', pointoverHandler);
1776+
scatterplot.subscribe('pointout', pointoutHandler);
1777+
1778+
scatterplot.hover(0);
1779+
1780+
await wait(0);
1781+
1782+
t.equal(hovering, 0, 'should be hovering point 0');
1783+
1784+
scatterplot.hover();
1785+
1786+
await wait(0);
1787+
1788+
t.equal(hovering, undefined, 'should have stopped hovering point 0');
1789+
1790+
scatterplot.hover(2, { preventEvent: true });
1791+
1792+
await wait(0);
1793+
1794+
t.equal(hovering, undefined, 'should be silently hovering point 2');
1795+
1796+
scatterplot.hover(4);
1797+
scatterplot.hover(undefined, { preventEvent: true });
1798+
1799+
await wait(0);
1800+
1801+
t.deepEqual(hovering, 4, 'should have silently stopped hovering point 4');
1802+
1803+
scatterplot.hover(-1);
1804+
1805+
await wait(0);
1806+
1807+
// Point 4 should still be registered as being hovered
1808+
t.deepEqual(hovering, 4, 'should not be hovering an invalid point');
1809+
1810+
scatterplot.hover(6);
1811+
1812+
await wait(0);
1813+
1814+
// Point 4 should still be registered as being hovered
1815+
t.deepEqual(hovering, 4, 'should not be hovering an invalid point');
1816+
1817+
scatterplot.destroy();
1818+
});
1819+
17551820
/* --------------------------------- Utils ---------------------------------- */
17561821

17571822
test('isNormFloatArray()', async (t) => {

0 commit comments

Comments
 (0)