Skip to content

Commit 581efd0

Browse files
committed
#9 added widget rotation spec
1 parent bc63320 commit 581efd0

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

src/components/mixins/rotatable.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.onRotateMouseDown = function(ev, idx, _axis, _operation) {
1414
let axis = _axis || 'z'
1515
let operation = _operation || 'rotate'
1616
// only left mouse button or touchstart
17-
if (ev.button !== 0 && ev.type !== 'touchstart') return
17+
if (ev.buttons !== 1 && ev.type !== 'touchstart') return
1818
document.addEventListener('mousemove', this.onRotateMouseMove)
1919
document.addEventListener('touchmove', this.onRotateMouseMove)
2020
document.addEventListener('mouseup', this.onRotateMouseUp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { appWrapper } from 'helpers/fullRenderHelper'
2+
3+
describe('widgets > controls > rotate', () => {
4+
it('should rotate 90° cw along z axis', () => {
5+
let domComponent = $('.sp-operating-table .sp-ot-slide .sp-component:first')
6+
expect(
7+
domComponent.find('.sp-edit-ctrls .rotate-z span:first').text()
8+
).to.equal('0')
9+
appWrapper
10+
.find('.sp-operating-table .sp-ot-slide .sp-component')
11+
.first()
12+
.simulate('mousedown')
13+
appWrapper
14+
.find('.sp-operating-table .sp-ot-slide .sp-component')
15+
.first()
16+
.simulate('mouseup')
17+
let clientRect = domComponent[0].getBoundingClientRect()
18+
appWrapper
19+
.find('.sp-operating-table .sp-ot-slide .sp-component')
20+
.first()
21+
.find('.sp-edit-ctrls .rotate-z svg')
22+
.simulate('mousedown', {
23+
clientX: clientRect.left + clientRect.width,
24+
clientY: clientRect.top + clientRect.height / 2,
25+
buttons: 1
26+
})
27+
let event = new MouseEvent('mousemove', {
28+
clientX: clientRect.left + clientRect.width / 2,
29+
clientY: clientRect.top + clientRect.height
30+
})
31+
document.dispatchEvent(event)
32+
event = new MouseEvent('mouseup', {
33+
clientX: clientRect.left + clientRect.width / 2,
34+
clientY: clientRect.top + clientRect.height
35+
})
36+
document.dispatchEvent(event)
37+
expect(
38+
Math.abs(
39+
90 -
40+
parseInt(
41+
domComponent.find('.sp-edit-ctrls .rotate-z span:first').text()
42+
)
43+
)
44+
).to.be.below(2)
45+
})
46+
})

0 commit comments

Comments
 (0)