mirror of
https://github.com/nasa/openmct.git
synced 2025-06-02 07:30:49 +00:00
Merge remote-tracking branch 'origin/mobile_3' into mobile
This commit is contained in:
commit
7ac1d2458a
@ -29,9 +29,9 @@ define(
|
|||||||
describe("The info button gesture", function () {
|
describe("The info button gesture", function () {
|
||||||
var mockTimeout,
|
var mockTimeout,
|
||||||
mockDocument,
|
mockDocument,
|
||||||
|
mockBody,
|
||||||
mockAgentService,
|
mockAgentService,
|
||||||
mockInfoService,
|
mockInfoService,
|
||||||
testDelay = 12321,
|
|
||||||
mockElement,
|
mockElement,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockEvent,
|
mockEvent,
|
||||||
@ -40,19 +40,15 @@ define(
|
|||||||
testMetadata,
|
testMetadata,
|
||||||
mockPromise,
|
mockPromise,
|
||||||
mockHide,
|
mockHide,
|
||||||
gesture;
|
gesture,
|
||||||
|
fireGesture,
|
||||||
function fireEvent(evt, value) {
|
fireDismissGesture;
|
||||||
mockElement.on.calls.forEach(function (call) {
|
|
||||||
if (call.args[0] === evt) {
|
|
||||||
call.args[1](value);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockTimeout = jasmine.createSpy('$timeout');
|
mockTimeout = jasmine.createSpy('$timeout');
|
||||||
mockDocument = jasmine.createSpyObj('$document', ['find']);
|
mockDocument = jasmine.createSpyObj('$document', ['find']);
|
||||||
|
mockBody = jasmine.createSpyObj('body', [ 'on', 'off', 'scope', 'css', 'unbind' ]);
|
||||||
|
mockDocument.find.andReturn(mockBody);
|
||||||
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
|
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile', 'isPhone']);
|
||||||
mockInfoService = jasmine.createSpyObj(
|
mockInfoService = jasmine.createSpyObj(
|
||||||
'infoService',
|
'infoService',
|
||||||
@ -66,20 +62,7 @@ define(
|
|||||||
'domainObject',
|
'domainObject',
|
||||||
[ 'getId', 'getCapability', 'useCapability', 'getModel' ]
|
[ '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 = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]);
|
||||||
mockEvent.pageX = 0;
|
mockEvent.pageX = 0;
|
||||||
mockEvent.pageY = 0;
|
mockEvent.pageY = 0;
|
||||||
@ -103,12 +86,58 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
mockDomainObject
|
mockDomainObject
|
||||||
);
|
);
|
||||||
|
fireGesture = mockElement.on.mostRecentCall.args[1];
|
||||||
});
|
});
|
||||||
|
|
||||||
it("expect click on the representation", function () {
|
it("expect click on the representation", function () {
|
||||||
expect(mockElement.on)
|
// Fires a click call on element and then
|
||||||
.toHaveBeenCalledWith('click', jasmine.any(Function));
|
// 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";
|
"use strict";
|
||||||
|
|
||||||
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ],
|
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 () {
|
describe("The 'context menu' gesture", function () {
|
||||||
@ -40,15 +40,35 @@ define(
|
|||||||
mockAgentService,
|
mockAgentService,
|
||||||
mockDomainObject,
|
mockDomainObject,
|
||||||
mockEvent,
|
mockEvent,
|
||||||
|
mockTouchEvent,
|
||||||
|
mockContextMenuAction,
|
||||||
|
mockActionContext,
|
||||||
|
mockTouch,
|
||||||
gesture,
|
gesture,
|
||||||
fireGesture;
|
fireGesture,
|
||||||
|
fireTouchStartGesture,
|
||||||
|
fireTouchEndGesture;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
|
||||||
mockTimeout = jasmine.createSpy("$timeout");
|
mockTimeout = jasmine.createSpy("$timeout");
|
||||||
|
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
|
||||||
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
|
||||||
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
|
||||||
mockEvent = jasmine.createSpyObj("event", ["preventDefault"]);
|
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);
|
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||||
|
|
||||||
@ -57,6 +77,8 @@ define(
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("attaches a callback for context menu events", function () {
|
it("attaches a callback for context menu events", function () {
|
||||||
|
// Fire a click and expect it to happen
|
||||||
|
fireGesture();
|
||||||
expect(mockElement.on).toHaveBeenCalledWith(
|
expect(mockElement.on).toHaveBeenCalledWith(
|
||||||
"contextmenu",
|
"contextmenu",
|
||||||
jasmine.any(Function)
|
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);
|
mockAgentService.isMobile.andReturn(true);
|
||||||
|
|
||||||
|
// Then create new (mobile) gesture
|
||||||
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
|
||||||
|
|
||||||
// Capture the contextmenu callback
|
// Set calls for the touchstart and touchend gestures
|
||||||
fireGesture = mockElement.on.mostRecentCall.args[1];
|
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…
x
Reference in New Issue
Block a user