2015-11-05 20:45:51 +00:00
|
|
|
/*****************************************************************************
|
2016-07-12 23:21:58 +00:00
|
|
|
* Open MCT, Copyright (c) 2009-2016, United States Government
|
2015-11-05 20:45:51 +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-11-05 20:45:51 +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-11-05 20:45:51 +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.
|
|
|
|
*****************************************************************************/
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
define(
|
|
|
|
["../../src/actions/StartTimerAction"],
|
|
|
|
function (StartTimerAction) {
|
|
|
|
|
|
|
|
describe("A timer's start action", function () {
|
|
|
|
var mockNow,
|
|
|
|
mockDomainObject,
|
|
|
|
testModel,
|
|
|
|
testContext,
|
|
|
|
action;
|
|
|
|
|
|
|
|
function asPromise(value) {
|
|
|
|
return (value || {}).then ? value : {
|
2017-01-18 13:08:54 +00:00
|
|
|
then: function (callback) {
|
|
|
|
return asPromise(callback(value));
|
|
|
|
}
|
|
|
|
};
|
2015-09-14 23:45:38 +00:00
|
|
|
}
|
|
|
|
|
2017-01-26 23:09:01 +00:00
|
|
|
function testState(type, timerState, timestamp, expected) {
|
|
|
|
testModel.type = type;
|
|
|
|
testModel.timerState = timerState;
|
|
|
|
testModel.timestamp = timestamp;
|
|
|
|
|
|
|
|
if (expected) {
|
|
|
|
expect(StartTimerAction.appliesTo(testContext)).toBeTruthy();
|
|
|
|
} else {
|
|
|
|
expect(StartTimerAction.appliesTo(testContext)).toBeFalsy();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-14 23:45:38 +00:00
|
|
|
beforeEach(function () {
|
|
|
|
mockNow = jasmine.createSpy('now');
|
|
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
|
|
'domainObject',
|
2016-05-19 18:29:13 +00:00
|
|
|
['getCapability', 'useCapability', 'getModel']
|
2015-09-14 23:45:38 +00:00
|
|
|
);
|
|
|
|
|
2018-06-30 00:32:59 +00:00
|
|
|
mockDomainObject.useCapability.and.callFake(function (c, v) {
|
2015-09-14 23:45:38 +00:00
|
|
|
if (c === 'mutation') {
|
|
|
|
testModel = v(testModel) || testModel;
|
|
|
|
return asPromise(true);
|
|
|
|
}
|
|
|
|
});
|
2018-06-30 00:32:59 +00:00
|
|
|
mockDomainObject.getModel.and.callFake(function () {
|
2015-09-14 23:45:38 +00:00
|
|
|
return testModel;
|
|
|
|
});
|
|
|
|
|
|
|
|
testModel = {};
|
2017-01-18 13:08:54 +00:00
|
|
|
testContext = {domainObject: mockDomainObject};
|
2015-09-14 23:45:38 +00:00
|
|
|
|
|
|
|
action = new StartTimerAction(mockNow, testContext);
|
|
|
|
});
|
|
|
|
|
2016-05-19 18:50:12 +00:00
|
|
|
it("updates the model with a timestamp", function () {
|
2018-06-30 00:32:59 +00:00
|
|
|
mockNow.and.returnValue(12000);
|
2015-09-14 23:45:38 +00:00
|
|
|
action.perform();
|
|
|
|
expect(testModel.timestamp).toEqual(12000);
|
|
|
|
});
|
|
|
|
|
2017-01-26 00:21:52 +00:00
|
|
|
it("updates the model with a pausedTime", function () {
|
|
|
|
testModel.pausedTime = 12000;
|
|
|
|
action.perform();
|
|
|
|
expect(testModel.pausedTime).toEqual(undefined);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("updates the model with a timerState", function () {
|
|
|
|
testModel.timerState = undefined;
|
|
|
|
action.perform();
|
|
|
|
expect(testModel.timerState).toEqual('started');
|
|
|
|
});
|
|
|
|
|
2017-01-18 13:08:54 +00:00
|
|
|
it("applies only to timers not in a playing state", function () {
|
|
|
|
//in a stopped state
|
2017-01-26 00:21:52 +00:00
|
|
|
testState('timer', 'stopped', undefined, true);
|
2017-01-18 13:08:54 +00:00
|
|
|
|
|
|
|
//in a paused state
|
2017-01-26 00:21:52 +00:00
|
|
|
testState('timer', 'paused', 12000, true);
|
2015-09-14 23:45:38 +00:00
|
|
|
|
2017-01-18 13:08:54 +00:00
|
|
|
//in a playing state
|
2017-01-26 00:21:52 +00:00
|
|
|
testState('timer', 'started', 12000, false);
|
2015-09-14 23:45:38 +00:00
|
|
|
|
2017-01-18 13:08:54 +00:00
|
|
|
//not a timer
|
2017-01-26 00:21:52 +00:00
|
|
|
testState('clock', 'paused', 12000, false);
|
2015-09-14 23:45:38 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2015-10-23 20:44:39 +00:00
|
|
|
);
|