From 906354764b5798e429310f4aa85a6b09617c7676 Mon Sep 17 00:00:00 2001 From: Shivam Dave Date: Wed, 29 Jul 2015 15:06:39 -0700 Subject: [PATCH] [Mobile] Tests Has way to make isMobile call true or false for mobile/nonmobile devices. --- .../test/actions/ContextMenuActionSpec.js | 44 ++++++++++++++++++- .../test/gestures/ContextMenuGestureSpec.js | 13 ++++++ 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js index 8d94a30766..58ba276c80 100644 --- a/platform/representation/test/actions/ContextMenuActionSpec.js +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -49,6 +49,8 @@ define( mockDomainObject, mockEvent, mockActionContext, + mockNavigator, + mockStopPropagation, action; beforeEach(function () { @@ -63,7 +65,7 @@ define( mockScope = {}; mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); - mockEvent = jasmine.createSpyObj("event", ["preventDefault"]); + mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]); mockEvent.pageX = 0; mockEvent.pageY = 0; @@ -73,7 +75,7 @@ define( mockRootScope.$new.andReturn(mockScope); mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; - + action = new ContextMenuAction( mockCompile, mockDocument, @@ -138,6 +140,44 @@ define( // Listener should have been detached from body expect(mockBody.off).toHaveBeenCalled(); }); + + it("keeps a menu when menu is clicked", function () { + // Show the menu + mockEvent + action.perform(); + + // Find and fire body's mousedown listener + mockMenu.on.calls.forEach(function (call) { + if (call.args[0] === 'mousedown') { +// call.args[1](); + } + }); + + // Menu should have been removed + expect(mockMenu.remove).not.toHaveBeenCalled(); + + // Listener should have been detached from body + expect(mockBody.off).not.toHaveBeenCalled(); + }); + + it("mobile", function () { + mockQueryService.isMobile.andReturn(true); + action = new ContextMenuAction( + mockCompile, + mockDocument, + mockWindow, + mockRootScope, + mockQueryService, + mockActionContext + ); + action.perform(); + + mockMenu.on.calls.forEach(function (call) { + if (call.args[0] === 'touchstart') { +// call.args[1](); + } + }); + }); }); } ); \ No newline at end of file diff --git a/platform/representation/test/gestures/ContextMenuGestureSpec.js b/platform/representation/test/gestures/ContextMenuGestureSpec.js index ec687e3983..a9a5986577 100644 --- a/platform/representation/test/gestures/ContextMenuGestureSpec.js +++ b/platform/representation/test/gestures/ContextMenuGestureSpec.js @@ -75,6 +75,19 @@ define( mockDomainObject.calls ); }); + + it("mobile", function () { + mockQueryService.isMobile.andReturn(true); + gesture = new ContextMenuGesture(mockTimeout, mockQueryService, mockElement, mockDomainObject); + + // Capture the contextmenu callback + fireGesture = mockElement.on.mostRecentCall.args[1]; + + expect(mockElement.on).toHaveBeenCalledWith( + "touchstart", + jasmine.any(Function) + ); + }); }); } ); \ No newline at end of file