Skip to content

Commit

Permalink
Added fix and tests for angular-ui#205
Browse files Browse the repository at this point in the history
  • Loading branch information
mackenzieajudd committed Apr 20, 2016
1 parent 5e23ee9 commit b28adb6
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ui-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ angular.module('ui.layout', [])
(mouseEvent.originalEvent && mouseEvent.originalEvent[ctrl.sizeProperties.mouseProperty]) ||
// jQuery does touches weird, see #82
($window.jQuery ?
(mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) :
(mouseEvent.originalEvent ? mouseEvent.originalEvent.targetTouches && mouseEvent.originalEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0) :
(mouseEvent.targetTouches ? mouseEvent.targetTouches[0][ctrl.sizeProperties.mouseProperty] : 0));

lastPos = mousePos - offset($element)[ctrl.sizeProperties.offsetPos];
Expand Down
76 changes: 76 additions & 0 deletions test/uiLayoutCtrl.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,81 @@ describe('Controller: uiLayoutCtrl', function () {
expect(uic.isLayoutElement(tagContainer)).toEqual(true);
expect(uic.isLayoutElement(notUiEl)).toEqual(false);
});

describe('mouseMoveHandler', function(){

var controller, window;

beforeEach(function(){

window = {};

controller = $controller('uiLayoutCtrl', {
$scope: scope,
$attrs: {},
$element: angular.element('<div></div>'),
$window: window
});
});

it('should handle standard mouse event without exception', function(){
var mockMouseEvent = {};
mockMouseEvent[controller.sizeProperties.mouseProperty] = 0;

controller.mouseMoveHandler(mockMouseEvent);
});

it('should handle jQuery mouse event without exception', function(){
var mockMouseEvent = {
originalEvent: {}
};
mockMouseEvent.originalEvent[controller.sizeProperties.mouseProperty] = 0;

controller.mouseMoveHandler(mockMouseEvent);
});

it('should handle standard touch event without exception', function(){
var mockMouseEvent = {
targetTouches: []
};
mockMouseEvent.targetTouches[0] = {};
mockMouseEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;

controller.mouseMoveHandler(mockMouseEvent);
});

it('should handle unrecognised standard event without exception', function(){
var mockMouseEvent = {};

controller.mouseMoveHandler(mockMouseEvent);
});

it('should handle jQuery touch event without exception', function(){

window.jQuery = true;

var mockMouseEvent = {
originalEvent: {
targetTouches: []
}
};

mockMouseEvent.originalEvent.targetTouches[0] = {};
mockMouseEvent.originalEvent.targetTouches[0][controller.sizeProperties.mouseProperty] = 0;

controller.mouseMoveHandler(mockMouseEvent);
});

it('should handle unrecognised jQuery event without exception', function(){

window.jQuery = true;

var mockMouseEvent = {
originalEvent: {}
};

controller.mouseMoveHandler(mockMouseEvent);
});
});
});
});

0 comments on commit b28adb6

Please sign in to comment.