2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
2018-05-14 22:46:17 +00:00
|
|
|
* Open MCT, Copyright (c) 2014-2018, 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-25 22:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/OverlayService"],
|
|
|
|
function (OverlayService) {
|
|
|
|
|
2015-01-14 21:09:41 +00:00
|
|
|
describe("The overlay service", function () {
|
2014-11-25 23:59:04 +00:00
|
|
|
var mockDocument,
|
|
|
|
mockCompile,
|
|
|
|
mockRootScope,
|
|
|
|
mockBody,
|
|
|
|
mockTemplate,
|
|
|
|
mockElement,
|
|
|
|
mockScope,
|
2019-03-29 22:38:39 +00:00
|
|
|
mockTimeout,
|
2014-11-25 23:59:04 +00:00
|
|
|
overlayService;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
2016-05-19 18:29:13 +00:00
|
|
|
mockDocument = jasmine.createSpyObj("$document", ["find"]);
|
2014-11-25 23:59:04 +00:00
|
|
|
mockCompile = jasmine.createSpy("$compile");
|
2016-05-19 18:29:13 +00:00
|
|
|
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
|
2019-03-29 22:38:39 +00:00
|
|
|
mockBody = jasmine.createSpyObj("body", ["append"]);
|
2014-11-25 23:59:04 +00:00
|
|
|
mockTemplate = jasmine.createSpy("template");
|
2016-05-19 18:29:13 +00:00
|
|
|
mockElement = jasmine.createSpyObj("element", ["remove"]);
|
|
|
|
mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
|
2019-03-29 22:38:39 +00:00
|
|
|
mockTimeout = function (callback) {
|
|
|
|
callback();
|
|
|
|
}
|
2014-11-25 23:59:04 +00:00
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockDocument.find.and.returnValue(mockBody);
|
|
|
|
mockCompile.and.returnValue(mockTemplate);
|
|
|
|
mockRootScope.$new.and.returnValue(mockScope);
|
|
|
|
mockTemplate.and.returnValue(mockElement);
|
2014-11-25 23:59:04 +00:00
|
|
|
|
|
|
|
overlayService = new OverlayService(
|
|
|
|
mockDocument,
|
|
|
|
mockCompile,
|
2019-03-29 22:38:39 +00:00
|
|
|
mockRootScope,
|
|
|
|
mockTimeout
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
});
|
2014-11-25 22:44:16 +00:00
|
|
|
|
|
|
|
it("prepends an mct-include to create overlays", function () {
|
2015-01-14 21:09:41 +00:00
|
|
|
overlayService.createOverlay("test", {});
|
2014-11-25 23:59:04 +00:00
|
|
|
expect(mockCompile).toHaveBeenCalled();
|
2018-06-30 00:32:59 +00:00
|
|
|
expect(mockCompile.calls.mostRecent().args[0].indexOf("mct-include"))
|
2014-11-25 23:59:04 +00:00
|
|
|
.not.toEqual(-1);
|
|
|
|
});
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
it("adds the templated element to the body", function () {
|
2015-01-14 21:09:41 +00:00
|
|
|
overlayService.createOverlay("test", {});
|
2019-03-29 22:38:39 +00:00
|
|
|
expect(mockBody.append).toHaveBeenCalledWith(mockElement);
|
2014-11-25 23:59:04 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("places the provided model/key in its template's scope", function () {
|
2015-01-14 21:09:41 +00:00
|
|
|
overlayService.createOverlay("test", { someKey: 42 });
|
2014-11-25 23:59:04 +00:00
|
|
|
expect(mockScope.overlay).toEqual({ someKey: 42 });
|
|
|
|
expect(mockScope.key).toEqual("test");
|
|
|
|
|
|
|
|
// Make sure this is actually what was rendered, too
|
|
|
|
expect(mockTemplate).toHaveBeenCalledWith(mockScope);
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("removes the prepended element on request", function () {
|
2015-01-14 21:09:41 +00:00
|
|
|
var overlay = overlayService.createOverlay("test", {});
|
2014-11-25 23:59:04 +00:00
|
|
|
|
|
|
|
// Verify precondition
|
|
|
|
expect(mockElement.remove).not.toHaveBeenCalled();
|
|
|
|
expect(mockScope.$destroy).not.toHaveBeenCalled();
|
|
|
|
|
|
|
|
// Dismiss the overlay
|
|
|
|
overlay.dismiss();
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
// Now it should have been removed, and the scope destroyed
|
|
|
|
expect(mockElement.remove).toHaveBeenCalled();
|
|
|
|
expect(mockScope.$destroy).toHaveBeenCalled();
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|
2016-05-19 18:29:13 +00:00
|
|
|
);
|