2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2016, United States Government
|
2015-05-13 23:42:35 +00:00
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT is licensed under the Apache License, Version 2.0 (the
|
2015-05-13 23:42:35 +00:00
|
|
|
* "License"); you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0.
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT includes source code licensed under additional open source
|
2015-05-13 23:42:35 +00:00
|
|
|
* licenses. See the Open Source Licenses file (LICENSES.md) included with
|
|
|
|
* this source code distribution or the Licensing information page available
|
|
|
|
* at runtime from the About dialog for additional information.
|
|
|
|
*****************************************************************************/
|
2014-11-22 18:11:06 +00:00
|
|
|
|
2014-11-22 17:36:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Module defining ContextMenuGestureSpec. Created by vwoeltje on 11/22/14.
|
|
|
|
*/
|
|
|
|
define(
|
2015-07-02 19:50:48 +00:00
|
|
|
["../../src/gestures/ContextMenuGesture"],
|
|
|
|
function (ContextMenuGesture) {
|
2014-11-22 17:36:30 +00:00
|
|
|
|
2016-05-19 18:29:13 +00:00
|
|
|
var JQLITE_FUNCTIONS = ["on", "off", "find", "append", "remove"],
|
|
|
|
DOMAIN_OBJECT_METHODS = ["getId", "getModel", "getCapability", "hasCapability", "useCapability"];
|
2014-11-22 18:11:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe("The 'context menu' gesture", function () {
|
2015-07-29 17:00:03 +00:00
|
|
|
var mockTimeout,
|
|
|
|
mockElement,
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService,
|
2014-11-22 18:11:06 +00:00
|
|
|
mockDomainObject,
|
|
|
|
mockEvent,
|
2015-08-06 20:43:56 +00:00
|
|
|
mockTouchEvent,
|
|
|
|
mockContextMenuAction,
|
|
|
|
mockActionContext,
|
|
|
|
mockTouch,
|
2014-11-22 18:11:06 +00:00
|
|
|
gesture,
|
2015-08-06 20:43:56 +00:00
|
|
|
fireGesture,
|
|
|
|
fireTouchStartGesture,
|
|
|
|
fireTouchEndGesture;
|
2014-11-22 18:11:06 +00:00
|
|
|
|
|
|
|
beforeEach(function () {
|
2015-07-29 17:00:03 +00:00
|
|
|
mockTimeout = jasmine.createSpy("$timeout");
|
2015-08-06 20:43:56 +00:00
|
|
|
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
2014-11-22 18:11:06 +00:00
|
|
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
|
|
|
mockEvent = jasmine.createSpyObj("event", ["preventDefault"]);
|
2015-08-06 20:43:56 +00:00
|
|
|
mockContextMenuAction = jasmine.createSpyObj(
|
|
|
|
"action",
|
2016-05-19 18:29:13 +00:00
|
|
|
["perform", "getActions"]
|
2015-08-06 20:43:56 +00:00
|
|
|
);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
mockActionContext = {domainObject: mockDomainObject, event: mockEvent};
|
|
|
|
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
|
|
|
|
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
|
|
|
|
mockAgentService.isMobile.andReturn(false);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
|
|
|
|
2016-03-23 03:17:23 +00:00
|
|
|
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
2014-11-22 18:11:06 +00:00
|
|
|
|
|
|
|
// Capture the contextmenu callback
|
|
|
|
fireGesture = mockElement.on.mostRecentCall.args[1];
|
|
|
|
});
|
|
|
|
|
|
|
|
it("attaches a callback for context menu events", function () {
|
2015-08-06 20:43:56 +00:00
|
|
|
// Fire a click and expect it to happen
|
|
|
|
fireGesture();
|
2014-11-22 18:11:06 +00:00
|
|
|
expect(mockElement.on).toHaveBeenCalledWith(
|
|
|
|
"contextmenu",
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("detaches a callback for context menu events when destroyed", function () {
|
|
|
|
expect(mockElement.off).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
gesture.destroy();
|
|
|
|
|
|
|
|
expect(mockElement.off).toHaveBeenCalledWith(
|
|
|
|
"contextmenu",
|
2015-07-02 21:00:54 +00:00
|
|
|
//mockElement.on.mostRecentCall.args[1]
|
|
|
|
mockDomainObject.calls
|
2014-11-22 18:11:06 +00:00
|
|
|
);
|
|
|
|
});
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
it("attaches a callback for context menu events on mobile", function () {
|
|
|
|
// Mock touch event and set to mobile device
|
|
|
|
mockTouchEvent = jasmine.createSpyObj("event", ["preventDefault", "touches"]);
|
|
|
|
mockTouch = jasmine.createSpyObj("touch", ["length"]);
|
|
|
|
mockTouch.length = 1;
|
|
|
|
mockTouchEvent.touches.andReturn(mockTouch);
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService.isMobile.andReturn(true);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
// Then create new (mobile) gesture
|
2016-03-23 03:17:23 +00:00
|
|
|
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
// Set calls for the touchstart and touchend gestures
|
|
|
|
fireTouchStartGesture = mockElement.on.calls[1].args[1];
|
|
|
|
fireTouchEndGesture = mockElement.on.mostRecentCall.args[1];
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
// Fire touchstart and expect touch start to begin
|
|
|
|
fireTouchStartGesture(mockTouchEvent);
|
|
|
|
expect(mockElement.on).toHaveBeenCalledWith(
|
|
|
|
"touchstart",
|
|
|
|
jasmine.any(Function)
|
|
|
|
);
|
2016-05-19 18:29:13 +00:00
|
|
|
|
2015-08-06 20:43:56 +00:00
|
|
|
// Expect timeout to begin and then fireTouchEnd
|
|
|
|
expect(mockTimeout).toHaveBeenCalled();
|
|
|
|
mockTimeout.mostRecentCall.args[0]();
|
|
|
|
fireTouchEndGesture(mockTouchEvent);
|
2015-07-29 22:06:39 +00:00
|
|
|
});
|
2014-11-22 18:11:06 +00:00
|
|
|
});
|
2014-11-22 17:36:30 +00:00
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|