Skip to content

Commit

Permalink
#9 added widget rotation spec
Browse files Browse the repository at this point in the history
  • Loading branch information
abbr committed Oct 14, 2017
1 parent bc63320 commit 581efd0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/components/mixins/rotatable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exports.onRotateMouseDown = function(ev, idx, _axis, _operation) {
let axis = _axis || 'z'
let operation = _operation || 'rotate'
// only left mouse button or touchstart
if (ev.button !== 0 && ev.type !== 'touchstart') return
if (ev.buttons !== 1 && ev.type !== 'touchstart') return
document.addEventListener('mousemove', this.onRotateMouseMove)
document.addEventListener('touchmove', this.onRotateMouseMove)
document.addEventListener('mouseup', this.onRotateMouseUp)
Expand Down
46 changes: 46 additions & 0 deletions test/components/widgets/controls/rotateTest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import { appWrapper } from 'helpers/fullRenderHelper'

describe('widgets > controls > rotate', () => {
it('should rotate 90° cw along z axis', () => {
let domComponent = $('.sp-operating-table .sp-ot-slide .sp-component:first')
expect(
domComponent.find('.sp-edit-ctrls .rotate-z span:first').text()
).to.equal('0')
appWrapper
.find('.sp-operating-table .sp-ot-slide .sp-component')
.first()
.simulate('mousedown')
appWrapper
.find('.sp-operating-table .sp-ot-slide .sp-component')
.first()
.simulate('mouseup')
let clientRect = domComponent[0].getBoundingClientRect()
appWrapper
.find('.sp-operating-table .sp-ot-slide .sp-component')
.first()
.find('.sp-edit-ctrls .rotate-z svg')
.simulate('mousedown', {
clientX: clientRect.left + clientRect.width,
clientY: clientRect.top + clientRect.height / 2,
buttons: 1
})
let event = new MouseEvent('mousemove', {
clientX: clientRect.left + clientRect.width / 2,
clientY: clientRect.top + clientRect.height
})
document.dispatchEvent(event)
event = new MouseEvent('mouseup', {
clientX: clientRect.left + clientRect.width / 2,
clientY: clientRect.top + clientRect.height
})
document.dispatchEvent(event)
expect(
Math.abs(
90 -
parseInt(
domComponent.find('.sp-edit-ctrls .rotate-z span:first').text()
)
)
).to.be.below(2)
})
})

0 comments on commit 581efd0

Please sign in to comment.