mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Mobile] Tests
Completed ContextMenu and InfoButton Gesture tests where elements/body touch events occur.
This commit is contained in:
parent
0a39984c4f
commit
dcd7d61c9a
@ -29,9 +29,9 @@ define(
|
||||
describe("The info button gesture", function () {
|
||||
var mockTimeout,
|
||||
mockDocument,
|
||||
mockBody,
|
||||
mockAgentService,
|
||||
mockInfoService,
|
||||
testDelay = 12321,
|
||||
mockElement,
|
||||
mockDomainObject,
|
||||
mockEvent,
|
||||
@ -40,19 +40,15 @@ define(
|
||||
testMetadata,
|
||||
mockPromise,
|
||||
mockHide,
|
||||
gesture;
|
||||
|
||||
function fireEvent(evt, value) {
|
||||
mockElement.on.calls.forEach(function (call) {
|
||||
if (call.args[0] === evt) {
|
||||
call.args[1](value);
|
||||
}
|
||||
});
|
||||
}
|
||||
gesture,
|
||||
fireGesture,
|
||||
fireDismissGesture;
|
||||
|
||||
beforeEach(function () {
|
||||
mockTimeout = jasmine.createSpy('$timeout');
|
||||
mockDocument = jasmine.createSpyObj('$document', ['find']);
|
||||
mockBody = jasmine.createSpyObj('body', [ 'on', 'off', 'scope', 'css', 'unbind' ]);
|
||||
mockDocument.find.andReturn(mockBody);
|
||||
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
|
||||
mockInfoService = jasmine.createSpyObj(
|
||||
'infoService',
|
||||
@ -66,20 +62,7 @@ define(
|
||||
'domainObject',
|
||||
[ 'getId', 'getCapability', 'useCapability', 'getModel' ]
|
||||
);
|
||||
mockDocument = jasmine.createSpyObj('$document', ['find']);
|
||||
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile']);
|
||||
mockInfoService = jasmine.createSpyObj(
|
||||
'infoService',
|
||||
[ 'display' ]
|
||||
);
|
||||
mockElement = jasmine.createSpyObj(
|
||||
'element',
|
||||
[ 'on', 'off', 'scope', 'css', 'click' ]
|
||||
);
|
||||
mockDomainObject = jasmine.createSpyObj(
|
||||
'domainObject',
|
||||
[ 'getId', 'getCapability', 'useCapability', 'getModel' ]
|
||||
);
|
||||
|
||||
mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]);
|
||||
mockEvent.pageX = 0;
|
||||
mockEvent.pageY = 0;
|
||||
@ -103,12 +86,58 @@ define(
|
||||
mockElement,
|
||||
mockDomainObject
|
||||
);
|
||||
fireGesture = mockElement.on.mostRecentCall.args[1];
|
||||
});
|
||||
|
||||
it("expect click on the representation", function () {
|
||||
expect(mockElement.on)
|
||||
.toHaveBeenCalledWith('click', jasmine.any(Function));
|
||||
// Fires a click call on element and then
|
||||
// expects the click to have happened
|
||||
fireGesture(mockEvent);
|
||||
expect(mockElement.on).toHaveBeenCalledWith(
|
||||
"click",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
it("expect click then dismiss on the representation", function () {
|
||||
// Fire the click and then expect the click
|
||||
fireGesture(mockEvent);
|
||||
expect(mockElement.on).toHaveBeenCalledWith(
|
||||
"click",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
|
||||
// Get the touch start on the body
|
||||
// and fire the dismiss gesture
|
||||
fireDismissGesture = mockBody.on.mostRecentCall.args[1];
|
||||
fireDismissGesture(mockEvent);
|
||||
// Expect Body to have been touched, event.preventDefault()
|
||||
// to be called, then the mockBody listener to be detached
|
||||
// lastly unbind the touchstart used to dismiss so other
|
||||
// events can be called
|
||||
expect(mockBody.on).toHaveBeenCalledWith(
|
||||
"touchstart",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(mockEvent.preventDefault).toHaveBeenCalled();
|
||||
expect(mockBody.off).toHaveBeenCalledWith(
|
||||
"touchstart",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
expect(mockBody.unbind).toHaveBeenCalledWith(
|
||||
'touchstart'
|
||||
);
|
||||
});
|
||||
|
||||
it("detaches a callback for info bubble events when destroyed", function () {
|
||||
expect(mockElement.off).not.toHaveBeenCalled();
|
||||
|
||||
gesture.destroy();
|
||||
|
||||
expect(mockElement.off).toHaveBeenCalledWith(
|
||||
"click",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
@ -31,7 +31,7 @@ define(
|
||||
"use strict";
|
||||
|
||||
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ],
|
||||
DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability" ];
|
||||
DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability"];
|
||||
|
||||
|
||||
describe("The 'context menu' gesture", function () {
|
||||
@ -40,15 +40,35 @@ define(
|
||||
mockAgentService,
|
||||
mockDomainObject,
|
||||
mockEvent,
|
||||
mockTouchEvent,
|
||||
mockContextMenuAction,
|
||||
mockActionContext,
|
||||
mockTouch,
|
||||
gesture,
|
||||
fireGesture;
|
||||
fireGesture,
|
||||
fireTouchStartGesture,
|
||||
fireTouchEndGesture;
|
||||
|
||||
beforeEach(function () {
|
||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||
mockTimeout = jasmine.createSpy("$timeout");
|
||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||
mockEvent = jasmine.createSpyObj("event", ["preventDefault"]);
|
||||
mockContextMenuAction = jasmine.createSpyObj(
|
||||
"action",
|
||||
[ "perform", "getActions" ]
|
||||
);
|
||||
mockActionContext = jasmine.createSpyObj(
|
||||
"actionContext",
|
||||
[ "" ]
|
||||
);
|
||||
|
||||
mockActionContext = {domainObject: mockDomainObject, event: mockEvent};
|
||||
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
|
||||
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
|
||||
mockAgentService.isMobile.andReturn(false);
|
||||
|
||||
|
||||
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||
|
||||
@ -57,6 +77,8 @@ define(
|
||||
});
|
||||
|
||||
it("attaches a callback for context menu events", function () {
|
||||
// Fire a click and expect it to happen
|
||||
fireGesture();
|
||||
expect(mockElement.on).toHaveBeenCalledWith(
|
||||
"contextmenu",
|
||||
jasmine.any(Function)
|
||||
@ -75,12 +97,32 @@ define(
|
||||
);
|
||||
});
|
||||
|
||||
it("mobile", function () {
|
||||
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);
|
||||
mockAgentService.isMobile.andReturn(true);
|
||||
|
||||
// Then create new (mobile) gesture
|
||||
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||
|
||||
// Capture the contextmenu callback
|
||||
fireGesture = mockElement.on.mostRecentCall.args[1];
|
||||
// Set calls for the touchstart and touchend gestures
|
||||
fireTouchStartGesture = mockElement.on.calls[1].args[1];
|
||||
fireTouchEndGesture = mockElement.on.mostRecentCall.args[1];
|
||||
|
||||
// Fire touchstart and expect touch start to begin
|
||||
fireTouchStartGesture(mockTouchEvent);
|
||||
expect(mockElement.on).toHaveBeenCalledWith(
|
||||
"touchstart",
|
||||
jasmine.any(Function)
|
||||
);
|
||||
|
||||
// Expect timeout to begin and then fireTouchEnd
|
||||
expect(mockTimeout).toHaveBeenCalled();
|
||||
mockTimeout.mostRecentCall.args[0]();
|
||||
fireTouchEndGesture(mockTouchEvent);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user