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-25 22:44:16 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/DialogService"],
|
|
|
|
function (DialogService) {
|
|
|
|
|
|
|
|
describe("The dialog service", function () {
|
2014-11-25 23:59:04 +00:00
|
|
|
var mockOverlayService,
|
|
|
|
mockQ,
|
|
|
|
mockLog,
|
|
|
|
mockOverlay,
|
|
|
|
mockDeferred,
|
|
|
|
dialogService;
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockOverlayService = jasmine.createSpyObj(
|
|
|
|
"overlayService",
|
2016-05-19 18:29:13 +00:00
|
|
|
["createOverlay"]
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
mockQ = jasmine.createSpyObj(
|
|
|
|
"$q",
|
2016-05-19 18:29:13 +00:00
|
|
|
["defer"]
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
mockLog = jasmine.createSpyObj(
|
|
|
|
"$log",
|
2016-05-19 18:29:13 +00:00
|
|
|
["warn", "info", "debug"]
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
mockOverlay = jasmine.createSpyObj(
|
|
|
|
"overlay",
|
2016-05-19 18:29:13 +00:00
|
|
|
["dismiss"]
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
mockDeferred = jasmine.createSpyObj(
|
|
|
|
"deferred",
|
2016-05-19 18:29:13 +00:00
|
|
|
["resolve", "reject"]
|
2014-11-25 23:59:04 +00:00
|
|
|
);
|
|
|
|
mockDeferred.promise = "mock promise";
|
|
|
|
|
|
|
|
mockQ.defer.andReturn(mockDeferred);
|
|
|
|
mockOverlayService.createOverlay.andReturn(mockOverlay);
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
dialogService = new DialogService(
|
|
|
|
mockOverlayService,
|
|
|
|
mockQ,
|
|
|
|
mockLog
|
|
|
|
);
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
it("adds an overlay when user input is requested", function () {
|
|
|
|
dialogService.getUserInput({}, {});
|
|
|
|
expect(mockOverlayService.createOverlay).toHaveBeenCalled();
|
|
|
|
});
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
it("allows user input to be canceled", function () {
|
|
|
|
dialogService.getUserInput({}, { someKey: "some value" });
|
2015-01-14 21:09:41 +00:00
|
|
|
mockOverlayService.createOverlay.mostRecentCall.args[1].cancel();
|
2014-11-25 23:59:04 +00:00
|
|
|
expect(mockDeferred.reject).toHaveBeenCalled();
|
|
|
|
expect(mockDeferred.resolve).not.toHaveBeenCalled();
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("passes back the result of user input when confirmed", function () {
|
2014-11-25 23:59:04 +00:00
|
|
|
var value = { someKey: 42 };
|
|
|
|
dialogService.getUserInput({}, value);
|
2015-01-14 21:09:41 +00:00
|
|
|
mockOverlayService.createOverlay.mostRecentCall.args[1].confirm();
|
2014-11-25 23:59:04 +00:00
|
|
|
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
|
|
|
expect(mockDeferred.resolve).toHaveBeenCalledWith(value);
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("logs a warning when a dialog is already showing", function () {
|
2014-11-25 23:59:04 +00:00
|
|
|
dialogService.getUserInput({}, {});
|
|
|
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
|
|
|
dialogService.getUserInput({}, {});
|
|
|
|
expect(mockLog.warn).toHaveBeenCalled();
|
|
|
|
expect(mockDeferred.reject).toHaveBeenCalled();
|
|
|
|
});
|
2014-11-25 22:44:16 +00:00
|
|
|
|
2014-11-25 23:59:04 +00:00
|
|
|
it("can show multiple dialogs if prior ones are dismissed", function () {
|
|
|
|
dialogService.getUserInput({}, {});
|
|
|
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
2015-01-14 21:09:41 +00:00
|
|
|
mockOverlayService.createOverlay.mostRecentCall.args[1].confirm();
|
2014-11-25 23:59:04 +00:00
|
|
|
dialogService.getUserInput({}, {});
|
|
|
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
|
|
|
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
|
2015-03-25 00:26:50 +00:00
|
|
|
it("provides an options dialogs", function () {
|
|
|
|
var dialogModel = {};
|
|
|
|
dialogService.getUserChoice(dialogModel);
|
|
|
|
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
|
|
|
'overlay-options',
|
|
|
|
{
|
|
|
|
dialog: dialogModel,
|
|
|
|
confirm: jasmine.any(Function),
|
|
|
|
cancel: jasmine.any(Function)
|
2015-10-30 23:20:57 +00:00
|
|
|
},
|
|
|
|
't-dialog'
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("invokes the overlay service with the correct parameters when" +
|
2016-05-19 18:29:13 +00:00
|
|
|
" a blocking dialog is requested", function () {
|
2015-10-30 23:20:57 +00:00
|
|
|
var dialogModel = {};
|
2016-06-30 03:09:58 +00:00
|
|
|
expect(dialogService.showBlockingMessage(dialogModel)).not.toBe(false);
|
2015-10-30 23:20:57 +00:00
|
|
|
expect(mockOverlayService.createOverlay).toHaveBeenCalledWith(
|
|
|
|
"overlay-blocking-message",
|
|
|
|
dialogModel,
|
|
|
|
"t-dialog-sm"
|
2015-03-25 00:26:50 +00:00
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2016-06-30 03:09:58 +00:00
|
|
|
describe("the blocking message dialog", function () {
|
|
|
|
var dialogModel = {};
|
|
|
|
var dialogHandle;
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
dialogHandle = dialogService.showBlockingMessage(dialogModel);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("returns a handle to the dialog", function () {
|
|
|
|
expect(dialogHandle).not.toBe(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("dismissing the dialog dismisses the overlay", function () {
|
|
|
|
dialogHandle.dismiss();
|
|
|
|
expect(mockOverlay.dismiss).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it("individual dialogs can be dismissed", function () {
|
|
|
|
var secondDialogHandle,
|
|
|
|
secondMockOverlay;
|
|
|
|
|
|
|
|
dialogHandle.dismiss();
|
|
|
|
|
|
|
|
secondMockOverlay = jasmine.createSpyObj(
|
|
|
|
"overlay",
|
|
|
|
["dismiss"]
|
|
|
|
);
|
|
|
|
mockOverlayService.createOverlay.andReturn(secondMockOverlay);
|
|
|
|
secondDialogHandle = dialogService.showBlockingMessage(dialogModel);
|
|
|
|
|
|
|
|
//Dismiss the first dialog. It should only dismiss if it
|
|
|
|
// is active
|
|
|
|
dialogHandle.dismiss();
|
|
|
|
expect(secondMockOverlay.dismiss).not.toHaveBeenCalled();
|
|
|
|
secondDialogHandle.dismiss();
|
|
|
|
expect(secondMockOverlay.dismiss).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
}
|
2015-10-30 23:20:57 +00:00
|
|
|
);
|