2015-06-04 23:27:41 +00:00
|
|
|
/*****************************************************************************
|
2017-04-05 21:35:12 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2017, United States Government
|
2015-06-04 23:27:41 +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-06-04 23:27:41 +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-06-04 23:27:41 +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.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
define(
|
|
|
|
['../../src/gestures/InfoGesture'],
|
|
|
|
function (InfoGesture) {
|
|
|
|
|
|
|
|
describe("The info gesture", function () {
|
|
|
|
var mockTimeout,
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService,
|
2015-06-04 23:27:41 +00:00
|
|
|
mockInfoService,
|
|
|
|
testDelay = 12321,
|
|
|
|
mockElement,
|
|
|
|
mockDomainObject,
|
|
|
|
mockScope,
|
|
|
|
mockOff,
|
2015-06-05 13:31:23 +00:00
|
|
|
testMetadata,
|
|
|
|
mockPromise,
|
|
|
|
mockHide,
|
2015-06-04 23:27:41 +00:00
|
|
|
gesture;
|
|
|
|
|
2015-06-05 13:31:23 +00:00
|
|
|
function fireEvent(evt, value) {
|
|
|
|
mockElement.on.calls.forEach(function (call) {
|
|
|
|
if (call.args[0] === evt) {
|
|
|
|
call.args[1](value);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-06-04 23:27:41 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockTimeout = jasmine.createSpy('$timeout');
|
2015-06-05 13:31:23 +00:00
|
|
|
mockTimeout.cancel = jasmine.createSpy('cancel');
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService = jasmine.createSpyObj('agentService', ['isMobile']);
|
2015-06-04 23:27:41 +00:00
|
|
|
mockInfoService = jasmine.createSpyObj(
|
|
|
|
'infoService',
|
2016-05-19 18:29:13 +00:00
|
|
|
['display']
|
2015-06-04 23:27:41 +00:00
|
|
|
);
|
|
|
|
mockElement = jasmine.createSpyObj(
|
|
|
|
'element',
|
2016-05-19 18:29:13 +00:00
|
|
|
['on', 'off', 'scope', 'css']
|
2015-06-04 23:27:41 +00:00
|
|
|
);
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
2016-05-19 18:29:13 +00:00
|
|
|
['getId', 'getCapability', 'useCapability', 'getModel']
|
2015-06-04 23:27:41 +00:00
|
|
|
);
|
2016-05-19 18:29:13 +00:00
|
|
|
mockScope = jasmine.createSpyObj('$scope', ['$on']);
|
2015-06-04 23:27:41 +00:00
|
|
|
mockOff = jasmine.createSpy('$off');
|
2016-05-19 18:29:13 +00:00
|
|
|
testMetadata = [{ name: "Test name", value: "Test value" }];
|
2015-06-05 13:31:23 +00:00
|
|
|
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
|
|
|
mockHide = jasmine.createSpy('hide');
|
2015-06-04 23:27:41 +00:00
|
|
|
|
2015-06-05 13:31:23 +00:00
|
|
|
mockDomainObject.getModel.andReturn({ name: "Test Object" });
|
|
|
|
mockDomainObject.useCapability.andCallFake(function (c) {
|
|
|
|
return (c === 'metadata') ? testMetadata : undefined;
|
|
|
|
});
|
2015-06-04 23:27:41 +00:00
|
|
|
mockElement.scope.andReturn(mockScope);
|
|
|
|
mockScope.$on.andReturn(mockOff);
|
2015-06-05 13:31:23 +00:00
|
|
|
mockTimeout.andReturn(mockPromise);
|
|
|
|
mockInfoService.display.andReturn(mockHide);
|
2015-06-04 23:27:41 +00:00
|
|
|
|
|
|
|
gesture = new InfoGesture(
|
|
|
|
mockTimeout,
|
2015-08-04 17:11:25 +00:00
|
|
|
mockAgentService,
|
2015-06-04 23:27:41 +00:00
|
|
|
mockInfoService,
|
|
|
|
testDelay,
|
|
|
|
mockElement,
|
|
|
|
mockDomainObject
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("listens for mouseenter on the representation", function () {
|
|
|
|
expect(mockElement.on)
|
|
|
|
.toHaveBeenCalledWith('mouseenter', jasmine.any(Function));
|
|
|
|
});
|
|
|
|
|
2015-06-05 13:31:23 +00:00
|
|
|
it("displays an info bubble on a delay after mouseenter", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
expect(mockTimeout)
|
|
|
|
.toHaveBeenCalledWith(jasmine.any(Function), testDelay);
|
|
|
|
mockTimeout.mostRecentCall.args[0]();
|
|
|
|
expect(mockInfoService.display).toHaveBeenCalledWith(
|
|
|
|
jasmine.any(String),
|
|
|
|
"Test Object",
|
|
|
|
testMetadata,
|
2016-05-19 18:29:13 +00:00
|
|
|
[1977, 42]
|
2015-06-05 13:31:23 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("does not display info bubble if mouse leaves too soon", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
fireEvent("mouseleave", { clientX: 1977, clientY: 42 });
|
|
|
|
expect(mockTimeout.cancel).toHaveBeenCalledWith(mockPromise);
|
|
|
|
expect(mockInfoService.display).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides a shown bubble when mouse leaves", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
mockTimeout.mostRecentCall.args[0]();
|
|
|
|
expect(mockHide).not.toHaveBeenCalled(); // verify precondition
|
|
|
|
fireEvent("mouseleave", {});
|
|
|
|
expect(mockHide).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("tracks mouse position", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
fireEvent("mousemove", { clientX: 1999, clientY: 11 });
|
|
|
|
fireEvent("mousemove", { clientX: 1984, clientY: 11 });
|
|
|
|
mockTimeout.mostRecentCall.args[0]();
|
|
|
|
// Should have displayed at the latest observed mouse position
|
|
|
|
expect(mockInfoService.display).toHaveBeenCalledWith(
|
|
|
|
jasmine.any(String),
|
|
|
|
"Test Object",
|
|
|
|
testMetadata,
|
2016-05-19 18:29:13 +00:00
|
|
|
[1984, 11]
|
2015-06-05 13:31:23 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("hides shown bubbles when destroyed", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
mockTimeout.mostRecentCall.args[0]();
|
|
|
|
expect(mockHide).not.toHaveBeenCalled(); // verify precondition
|
|
|
|
gesture.destroy();
|
|
|
|
expect(mockHide).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("detaches listeners when destroyed", function () {
|
|
|
|
fireEvent("mouseenter", { clientX: 1977, clientY: 42 });
|
|
|
|
gesture.destroy();
|
|
|
|
mockElement.on.calls.forEach(function (call) {
|
|
|
|
expect(mockElement.off).toHaveBeenCalledWith(
|
|
|
|
call.args[0],
|
|
|
|
call.args[1]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
2015-06-04 23:27:41 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2015-06-10 23:38:49 +00:00
|
|
|
);
|