-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(g-svg): mouseenter and mouseleave should be effective, close antv…
- Loading branch information
1 parent
f2d64d1
commit 2b9b830
Showing
2 changed files
with
90 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
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,60 @@ | ||
const expect = require('chai').expect; | ||
import Canvas from '../../src/canvas'; | ||
|
||
export function simulateMouseEvent(dom, type, cfg) { | ||
const event = new MouseEvent(type, cfg); | ||
dom.dispatchEvent(event); | ||
} | ||
|
||
const dom = document.createElement('div'); | ||
document.body.appendChild(dom); | ||
dom.id = 'c1'; | ||
|
||
describe('#205', () => { | ||
const canvas = new Canvas({ | ||
container: dom, | ||
width: 500, | ||
height: 500, | ||
}); | ||
const el = canvas.get('el'); | ||
|
||
function getClientPoint(x, y) { | ||
const point = canvas.getClientByPoint(x, y); | ||
return { | ||
clientX: point.x, | ||
clientY: point.y, | ||
}; | ||
} | ||
|
||
it('mouseenter and mouseleave should be effective', () => { | ||
const group = canvas.addGroup(); | ||
const shape = group.addShape('circle', { | ||
attrs: { | ||
x: 100, | ||
y: 100, | ||
r: 40, | ||
fill: 'red', | ||
}, | ||
}); | ||
let flag = 0; | ||
|
||
shape.on('mouseenter', () => { | ||
flag = 1; | ||
}); | ||
shape.on('mouseleave', () => { | ||
flag = 2; | ||
}); | ||
|
||
const { clientX, clientY } = getClientPoint(100, 100); | ||
simulateMouseEvent(el, 'mouseenter', { | ||
clientX, | ||
clientY, | ||
}); | ||
expect(flag).eqls(1); | ||
simulateMouseEvent(el, 'mouseleave', { | ||
clientX: clientX + 50, | ||
clientY: clientX + 50, | ||
}); | ||
expect(flag).eqls(2); | ||
}); | ||
}); |