mirror of
https://github.com/nasa/openmct.git
synced 2024-12-27 16:38:51 +00:00
c932e953bc
WTD-1239
67 lines
2.3 KiB
JavaScript
67 lines
2.3 KiB
JavaScript
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine,window,afterEach*/
|
|
|
|
define(
|
|
["../../src/actions/AbstractStartTimerAction"],
|
|
function (AbstractStartTimerAction) {
|
|
"use strict";
|
|
|
|
describe("A timer's start/restart action", function () {
|
|
var mockNow,
|
|
mockDomainObject,
|
|
mockPersistence,
|
|
testModel,
|
|
action;
|
|
|
|
function asPromise(value) {
|
|
return (value || {}).then ? value : {
|
|
then: function (callback) {
|
|
return asPromise(callback(value));
|
|
}
|
|
};
|
|
}
|
|
|
|
beforeEach(function () {
|
|
mockNow = jasmine.createSpy('now');
|
|
mockDomainObject = jasmine.createSpyObj(
|
|
'domainObject',
|
|
[ 'getCapability', 'useCapability' ]
|
|
);
|
|
mockPersistence = jasmine.createSpyObj(
|
|
'persistence',
|
|
['persist']
|
|
);
|
|
|
|
mockDomainObject.getCapability.andCallFake(function (c) {
|
|
return (c === 'persistence') && mockPersistence;
|
|
});
|
|
mockDomainObject.useCapability.andCallFake(function (c, v) {
|
|
if (c === 'mutation') {
|
|
testModel = v(testModel) || testModel;
|
|
return asPromise(true);
|
|
}
|
|
});
|
|
|
|
testModel = {};
|
|
|
|
action = new AbstractStartTimerAction(mockNow, {
|
|
domainObject: mockDomainObject
|
|
});
|
|
});
|
|
|
|
it("updates the model with a timestamp and persists", function () {
|
|
mockNow.andReturn(12000);
|
|
action.perform();
|
|
expect(testModel.timestamp).toEqual(12000);
|
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
|
});
|
|
|
|
it("does not truncate milliseconds", function () {
|
|
mockNow.andReturn(42321);
|
|
action.perform();
|
|
expect(testModel.timestamp).toEqual(42321);
|
|
expect(mockPersistence.persist).toHaveBeenCalled();
|
|
});
|
|
});
|
|
}
|
|
);
|