2015-05-13 23:42:35 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* Open MCT Web, Copyright (c) 2014-2015, United States Government
|
|
|
|
* as represented by the Administrator of the National Aeronautics and Space
|
|
|
|
* Administration. All rights reserved.
|
|
|
|
*
|
|
|
|
* Open MCT Web is licensed under the Apache License, Version 2.0 (the
|
|
|
|
* "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.
|
|
|
|
*
|
|
|
|
* Open MCT Web includes source code licensed under additional open source
|
|
|
|
* 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
|
|
|
/*global define,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MCTIncudeSpec. Created by vwoeltje on 11/6/14.
|
|
|
|
*/
|
|
|
|
define(
|
|
|
|
["../src/DialogService"],
|
|
|
|
function (DialogService) {
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
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",
|
|
|
|
[ "createOverlay" ]
|
|
|
|
);
|
|
|
|
mockQ = jasmine.createSpyObj(
|
|
|
|
"$q",
|
|
|
|
[ "defer" ]
|
|
|
|
);
|
|
|
|
mockLog = jasmine.createSpyObj(
|
|
|
|
"$log",
|
|
|
|
[ "warn", "info", "debug" ]
|
|
|
|
);
|
|
|
|
mockOverlay = jasmine.createSpyObj(
|
|
|
|
"overlay",
|
|
|
|
[ "dismiss" ]
|
|
|
|
);
|
|
|
|
mockDeferred = jasmine.createSpyObj(
|
|
|
|
"deferred",
|
|
|
|
[ "resolve", "reject"]
|
|
|
|
);
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2014-11-25 22:44:16 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|