-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(g-base): add name attr for event, close #249
- Loading branch information
1 parent
859da22
commit 765a591
Showing
5 changed files
with
240 additions
and
16 deletions.
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
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
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,179 @@ | ||
const expect = require('chai').expect; | ||
import Canvas from '../../src/canvas'; | ||
import { simulateMouseEvent, getClientPoint } from '../util'; | ||
|
||
const dom = document.createElement('div'); | ||
document.body.appendChild(dom); | ||
dom.id = 'c1'; | ||
|
||
describe('#249', () => { | ||
it('event attrs should be correct when emit event on shape', () => { | ||
const canvas = new Canvas({ | ||
container: dom, | ||
width: 600, | ||
height: 600, | ||
}); | ||
|
||
const el = canvas.get('el'); | ||
const group = canvas.addGroup({ | ||
name: 'group', | ||
}); | ||
const circle = group.addShape('circle', { | ||
name: 'circle', | ||
attrs: { | ||
x: 50, | ||
y: 50, | ||
r: 50, | ||
fill: 'red', | ||
}, | ||
}); | ||
|
||
canvas.on('*', (e) => { | ||
expect(e.name).eqls('*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('mousedown', (e) => { | ||
expect(e.name).eqls('mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(canvas); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('group:*', (e) => { | ||
expect(e.name).eqls('group:*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(group); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('group:mousedown', (e) => { | ||
expect(e.name).eqls('group:mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(group); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('circle:*', (e) => { | ||
expect(e.name).eqls('circle:*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('circle:mousedown', (e) => { | ||
expect(e.name).eqls('circle:mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
group.on('*', (e) => { | ||
expect(e.name).eqls('*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(group); | ||
}); | ||
|
||
group.on('mousedown', (e) => { | ||
expect(e.name).eqls('mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(group); | ||
expect(e.delegateTarget).eqls(group); | ||
}); | ||
|
||
group.on('circle:*', (e) => { | ||
expect(e.name).eqls('circle:*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(group); | ||
}); | ||
|
||
group.on('circle:mousedown', (e) => { | ||
expect(e.name).eqls('circle:mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(group); | ||
}); | ||
|
||
circle.on('*', (e) => { | ||
expect(e.name).eqls('*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(circle); | ||
}); | ||
|
||
circle.on('mousedown', (e) => { | ||
expect(e.name).eqls('mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(circle); | ||
expect(e.currentTarget).eqls(circle); | ||
expect(e.delegateTarget).eqls(circle); | ||
}); | ||
|
||
// emit event on shape | ||
const { clientX, clientY } = getClientPoint(canvas, 50, 50); | ||
simulateMouseEvent(el, 'mousedown', { | ||
clientX, | ||
clientY, | ||
}); | ||
}); | ||
|
||
it('event attrs should be correct when emit event on canvas', () => { | ||
const canvas = new Canvas({ | ||
container: dom, | ||
width: 600, | ||
height: 600, | ||
}); | ||
|
||
const el = canvas.get('el'); | ||
const group = canvas.addGroup({ | ||
name: 'group', | ||
}); | ||
group.addShape('circle', { | ||
name: 'circle', | ||
attrs: { | ||
x: 50, | ||
y: 50, | ||
r: 50, | ||
fill: 'red', | ||
}, | ||
}); | ||
|
||
canvas.on('*', (e) => { | ||
expect(e.name).eqls('*'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(canvas); | ||
expect(e.currentTarget).eqls(canvas); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
canvas.on('mousedown', (e) => { | ||
expect(e.name).eqls('mousedown'); | ||
expect(e.type).eqls('mousedown'); | ||
expect(e.target).eqls(canvas); | ||
expect(e.currentTarget).eqls(canvas); | ||
expect(e.delegateTarget).eqls(canvas); | ||
}); | ||
|
||
// emit event on canvas | ||
const { clientX, clientY } = getClientPoint(canvas, 100, 100); | ||
simulateMouseEvent(el, 'mousedown', { | ||
clientX, | ||
clientY, | ||
}); | ||
}); | ||
}); |