mirror of
https://github.com/nasa/openmct.git
synced 2025-01-18 02:39:56 +00:00
[Time] conditional timeSystem change without bounds
Allow timeSystem to be changed without specifying bounds when a clock is present and can provide bounds. This simplifies bootstrap code. https://github.com/nasa/openmct/issues/1581
This commit is contained in:
parent
b8ae741969
commit
b70501a7ed
@ -239,7 +239,13 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* @method timeSystem
|
||||
*/
|
||||
TimeAPI.prototype.timeSystem = function (timeSystemOrKey, bounds) {
|
||||
if (arguments.length >= 2) {
|
||||
if (arguments.length >= 1) {
|
||||
if (arguments.length === 1 && !this.activeClock) {
|
||||
throw new Error(
|
||||
"Must specify bounds when changing time system without " +
|
||||
"an active clock."
|
||||
);
|
||||
}
|
||||
var timeSystem;
|
||||
|
||||
if (timeSystemOrKey === undefined) {
|
||||
@ -274,10 +280,10 @@ define(['EventEmitter'], function (EventEmitter) {
|
||||
* Time System
|
||||
* */
|
||||
this.emit('timeSystem', this.system);
|
||||
this.bounds(bounds);
|
||||
if (bounds) {
|
||||
this.bounds(bounds);
|
||||
}
|
||||
|
||||
} else if (arguments.length === 1) {
|
||||
throw new Error('Must set bounds when changing time system');
|
||||
}
|
||||
|
||||
return this.system;
|
||||
|
@ -25,6 +25,8 @@ define(['./TimeAPI'], function (TimeAPI) {
|
||||
var api,
|
||||
timeSystemKey,
|
||||
timeSystem,
|
||||
clockKey,
|
||||
clock,
|
||||
bounds,
|
||||
eventListener,
|
||||
toi;
|
||||
@ -33,7 +35,15 @@ define(['./TimeAPI'], function (TimeAPI) {
|
||||
api = new TimeAPI();
|
||||
timeSystemKey = "timeSystemKey";
|
||||
timeSystem = {key: timeSystemKey};
|
||||
bounds = {start: 0, end: 0};
|
||||
clockKey = "someClockKey";
|
||||
clock = jasmine.createSpyObj("clock", [
|
||||
"on",
|
||||
"off",
|
||||
"currentValue"
|
||||
]);
|
||||
clock.currentValue.andReturn(100);
|
||||
clock.key = clockKey;
|
||||
bounds = {start: 0, end: 1};
|
||||
eventListener = jasmine.createSpy("eventListener");
|
||||
toi = 111;
|
||||
});
|
||||
@ -74,11 +84,23 @@ define(['./TimeAPI'], function (TimeAPI) {
|
||||
|
||||
it("Disallows setting of time system without bounds", function () {
|
||||
api.addTimeSystem(timeSystem);
|
||||
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
||||
expect(api.timeSystem()).not.toBe(timeSystem);
|
||||
expect(function () {
|
||||
api.timeSystem(timeSystemKey);
|
||||
}).toThrow();
|
||||
expect(api.timeSystem()).not.toBe(timeSystemKey);
|
||||
expect(api.timeSystem()).not.toBe(timeSystem);
|
||||
});
|
||||
|
||||
it("allows setting of timesystem without bounds with clock", function () {
|
||||
api.addTimeSystem(timeSystem);
|
||||
api.addClock(clock);
|
||||
api.clock(clockKey, {start: 0, end: 1})
|
||||
expect(api.timeSystem()).not.toBe(timeSystem);
|
||||
expect(function () {
|
||||
api.timeSystem(timeSystemKey);
|
||||
}).not.toThrow();
|
||||
expect(api.timeSystem()).toBe(timeSystem);
|
||||
|
||||
});
|
||||
|
||||
it("Emits an event when time system changes", function () {
|
||||
|
Loading…
Reference in New Issue
Block a user