-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use vue-directive-normalizer and refactor drag, with extra …
…test cases
- Loading branch information
Showing
3 changed files
with
129 additions
and
83 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { mount } from '@vue/test-utils' | ||
import drag from '@/directives/drag' | ||
|
||
describe('directives/drag', () => { | ||
it(`should receive correct params inside callbacks`, done => { | ||
let results = [] | ||
const wrapper = mount({ | ||
directives: { drag }, | ||
template: `<div v-drag="{ | ||
dragstart: handleStart, | ||
drag: handleMove, | ||
dragend: handleEnd | ||
}">foo</div>`, | ||
methods: { | ||
handleStart ({ event }) { | ||
results.push({ | ||
x: event.clientX, | ||
y: event.clientY | ||
}) | ||
}, | ||
handleMove ({ event, distanceX, distanceY }) { | ||
results.push({ | ||
x: event.clientX, | ||
y: event.clientY, | ||
dx: distanceX, | ||
dy: distanceY | ||
}) | ||
}, | ||
handleEnd ({ event, distanceX, distanceY }) { | ||
results.push({ | ||
x: event.clientX, | ||
y: event.clientY, | ||
dx: distanceX, | ||
dy: distanceY | ||
}) | ||
|
||
expect(results).toEqual([ | ||
{ x: 5, y: 5 }, | ||
{ x: 105, y: 105, dx: 100, dy: 100 }, | ||
{ x: 205, y: 205, dx: 200, dy: 200 }, | ||
{ x: 205, y: 205, dx: 200, dy: 200 } | ||
]) | ||
|
||
done() | ||
} | ||
} | ||
}) | ||
|
||
wrapper.find('div').trigger('mousedown', { | ||
clientX: 5, | ||
clientY: 5 | ||
}) | ||
window.dispatchEvent( | ||
new MouseEvent('mousemove', { | ||
clientX: 105, | ||
clientY: 105 | ||
}) | ||
) | ||
window.dispatchEvent( | ||
new MouseEvent('mousemove', { | ||
clientX: 205, | ||
clientY: 205 | ||
}) | ||
) | ||
window.dispatchEvent( | ||
new MouseEvent('mouseup', { | ||
clientX: 205, | ||
clientY: 205 | ||
}) | ||
) | ||
}) | ||
}) |