@@ -119,9 +119,9 @@ define(
|
|||||||
if (!this.domains.some(matchesKey)) {
|
if (!this.domains.some(matchesKey)) {
|
||||||
throw new Error("Unknown domain " + key);
|
throw new Error("Unknown domain " + key);
|
||||||
}
|
}
|
||||||
this.domain = key;
|
this.activeDomain = key;
|
||||||
}
|
}
|
||||||
return this.domain;
|
return this.activeDomain;
|
||||||
};
|
};
|
||||||
|
|
||||||
return TimeConductor;
|
return TimeConductor;
|
||||||
|
|||||||
@@ -21,12 +21,9 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,describe,it,expect,beforeEach,waitsFor,afterEach,jasmine*/
|
/*global define,describe,it,expect,beforeEach,waitsFor,afterEach,jasmine*/
|
||||||
|
|
||||||
/**
|
|
||||||
* EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015.
|
|
||||||
*/
|
|
||||||
define(
|
define(
|
||||||
["../src/ConductorRepresenter"],
|
["../src/ConductorRepresenter", "./TestTimeConductor"],
|
||||||
function (ConductorRepresenter) {
|
function (ConductorRepresenter, TestTimeConductor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var SCOPE_METHODS = [
|
var SCOPE_METHODS = [
|
||||||
@@ -75,10 +72,7 @@ define(
|
|||||||
testViews = [ { someKey: "some value" } ];
|
testViews = [ { someKey: "some value" } ];
|
||||||
mockScope = jasmine.createSpyObj('scope', SCOPE_METHODS);
|
mockScope = jasmine.createSpyObj('scope', SCOPE_METHODS);
|
||||||
mockElement = jasmine.createSpyObj('element', ELEMENT_METHODS);
|
mockElement = jasmine.createSpyObj('element', ELEMENT_METHODS);
|
||||||
mockConductor = jasmine.createSpyObj(
|
mockConductor = new TestTimeConductor();
|
||||||
'conductor',
|
|
||||||
[ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ]
|
|
||||||
);
|
|
||||||
mockCompiledTemplate = jasmine.createSpy('template');
|
mockCompiledTemplate = jasmine.createSpy('template');
|
||||||
mockNewScope = jasmine.createSpyObj('newScope', SCOPE_METHODS);
|
mockNewScope = jasmine.createSpyObj('newScope', SCOPE_METHODS);
|
||||||
mockNewElement = jasmine.createSpyObj('newElement', ELEMENT_METHODS);
|
mockNewElement = jasmine.createSpyObj('newElement', ELEMENT_METHODS);
|
||||||
@@ -133,7 +127,7 @@ define(
|
|||||||
mockConductor.displayEnd.andReturn(1984);
|
mockConductor.displayEnd.andReturn(1984);
|
||||||
representer.represent(testViews[0], {});
|
representer.represent(testViews[0], {});
|
||||||
|
|
||||||
expect(mockNewScope.conductor).toEqual({
|
expect(mockNewScope.ngModel.conductor).toEqual({
|
||||||
inner: { start: 1977, end: 1984 },
|
inner: { start: 1977, end: 1984 },
|
||||||
outer: { start: 42, end: 12321 }
|
outer: { start: 42, end: 12321 }
|
||||||
});
|
});
|
||||||
@@ -147,21 +141,76 @@ define(
|
|||||||
|
|
||||||
representer.represent(testViews[0], {});
|
representer.represent(testViews[0], {});
|
||||||
|
|
||||||
mockNewScope.conductor = testState;
|
mockNewScope.ngModel.conductor = testState;
|
||||||
|
|
||||||
fireWatch(mockNewScope, 'conductor.inner.start', testState.inner.start);
|
fireWatch(
|
||||||
|
mockNewScope,
|
||||||
|
'ngModel.conductor.inner.start',
|
||||||
|
testState.inner.start
|
||||||
|
);
|
||||||
expect(mockConductor.displayStart).toHaveBeenCalledWith(42);
|
expect(mockConductor.displayStart).toHaveBeenCalledWith(42);
|
||||||
|
|
||||||
fireWatch(mockNewScope, 'conductor.inner.end', testState.inner.end);
|
fireWatch(
|
||||||
|
mockNewScope,
|
||||||
|
'ngModel.conductor.inner.end',
|
||||||
|
testState.inner.end
|
||||||
|
);
|
||||||
expect(mockConductor.displayEnd).toHaveBeenCalledWith(1984);
|
expect(mockConductor.displayEnd).toHaveBeenCalledWith(1984);
|
||||||
|
|
||||||
fireWatch(mockNewScope, 'conductor.outer.start', testState.outer.start);
|
fireWatch(
|
||||||
|
mockNewScope,
|
||||||
|
'ngModel.conductor.outer.start',
|
||||||
|
testState.outer.start
|
||||||
|
);
|
||||||
expect(mockConductor.queryStart).toHaveBeenCalledWith(-1977);
|
expect(mockConductor.queryStart).toHaveBeenCalledWith(-1977);
|
||||||
|
|
||||||
fireWatch(mockNewScope, 'conductor.outer.end', testState.outer.end);
|
fireWatch(
|
||||||
|
mockNewScope,
|
||||||
|
'ngModel.conductor.outer.end',
|
||||||
|
testState.outer.end
|
||||||
|
);
|
||||||
expect(mockConductor.queryEnd).toHaveBeenCalledWith(12321);
|
expect(mockConductor.queryEnd).toHaveBeenCalledWith(12321);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("exposes domain selection in scope", function () {
|
||||||
|
representer.represent(testViews[0], null);
|
||||||
|
|
||||||
|
expect(mockNewScope.ngModel.domain)
|
||||||
|
.toEqual(mockConductor.domain());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes domain options in scope", function () {
|
||||||
|
representer.represent(testViews[0], null);
|
||||||
|
|
||||||
|
mockConductor.domainOptions().forEach(function (option, i) {
|
||||||
|
expect(mockNewScope.ngModel.options[i].value)
|
||||||
|
.toEqual(option.key);
|
||||||
|
expect(mockNewScope.ngModel.options[i].name)
|
||||||
|
.toEqual(option.name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("updates domain selection from scope", function () {
|
||||||
|
var choice;
|
||||||
|
representer.represent(testViews[0], null);
|
||||||
|
|
||||||
|
// Choose a domain that isn't currently selected
|
||||||
|
mockNewScope.ngModel.options.forEach(function (option) {
|
||||||
|
if (option.value !== mockNewScope.ngModel.domain) {
|
||||||
|
choice = option.value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(mockConductor.domain)
|
||||||
|
.not.toHaveBeenCalledWith(choice);
|
||||||
|
|
||||||
|
mockNewScope.ngModel.domain = choice;
|
||||||
|
fireWatch(mockNewScope, "ngModel.domain", choice);
|
||||||
|
|
||||||
|
expect(mockConductor.domain)
|
||||||
|
.toHaveBeenCalledWith(choice);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -21,9 +21,6 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
/**
|
|
||||||
* EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015.
|
|
||||||
*/
|
|
||||||
define(
|
define(
|
||||||
["../src/ConductorService"],
|
["../src/ConductorService"],
|
||||||
function (ConductorService) {
|
function (ConductorService) {
|
||||||
@@ -38,7 +35,10 @@ define(
|
|||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
mockNow = jasmine.createSpy('now');
|
mockNow = jasmine.createSpy('now');
|
||||||
mockNow.andReturn(TEST_NOW);
|
mockNow.andReturn(TEST_NOW);
|
||||||
conductorService = new ConductorService(mockNow);
|
conductorService = new ConductorService(mockNow, [
|
||||||
|
{ key: "d1", name: "Domain #1" },
|
||||||
|
{ key: "d2", name: "Domain #2" }
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("initializes a time conductor around the current time", function () {
|
it("initializes a time conductor around the current time", function () {
|
||||||
|
|||||||
@@ -23,8 +23,8 @@
|
|||||||
|
|
||||||
|
|
||||||
define(
|
define(
|
||||||
["../src/ConductorTelemetryDecorator"],
|
["../src/ConductorTelemetryDecorator", "./TestTimeConductor"],
|
||||||
function (ConductorTelemetryDecorator) {
|
function (ConductorTelemetryDecorator, TestTimeConductor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("ConductorTelemetryDecorator", function () {
|
describe("ConductorTelemetryDecorator", function () {
|
||||||
@@ -54,10 +54,7 @@ define(
|
|||||||
'conductorService',
|
'conductorService',
|
||||||
['getConductor']
|
['getConductor']
|
||||||
);
|
);
|
||||||
mockConductor = jasmine.createSpyObj(
|
mockConductor = new TestTimeConductor();
|
||||||
'conductor',
|
|
||||||
[ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ]
|
|
||||||
);
|
|
||||||
mockPromise = jasmine.createSpyObj(
|
mockPromise = jasmine.createSpyObj(
|
||||||
'promise',
|
'promise',
|
||||||
['then']
|
['then']
|
||||||
@@ -82,6 +79,7 @@ define(
|
|||||||
mockConductor.queryEnd.andReturn(-12321);
|
mockConductor.queryEnd.andReturn(-12321);
|
||||||
mockConductor.displayStart.andReturn(42);
|
mockConductor.displayStart.andReturn(42);
|
||||||
mockConductor.displayEnd.andReturn(1977);
|
mockConductor.displayEnd.andReturn(1977);
|
||||||
|
mockConductor.domain.andReturn("testDomain");
|
||||||
|
|
||||||
decorator = new ConductorTelemetryDecorator(
|
decorator = new ConductorTelemetryDecorator(
|
||||||
mockConductorService,
|
mockConductorService,
|
||||||
@@ -89,26 +87,74 @@ define(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds display start/end times to historical requests", function () {
|
|
||||||
decorator.requestTelemetry([{ someKey: "some value" }]);
|
describe("decorates historical requests", function () {
|
||||||
expect(mockTelemetryService.requestTelemetry)
|
var request;
|
||||||
.toHaveBeenCalledWith([{
|
|
||||||
someKey: "some value",
|
beforeEach(function () {
|
||||||
start: mockConductor.displayStart(),
|
decorator.requestTelemetry([{ someKey: "some value" }]);
|
||||||
end: mockConductor.displayEnd()
|
request = mockTelemetryService.requestTelemetry
|
||||||
}]);
|
.mostRecentCall.args[0][0];
|
||||||
|
});
|
||||||
|
|
||||||
|
it("with start times", function () {
|
||||||
|
expect(request.start).toEqual(mockConductor.displayStart());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("with end times", function () {
|
||||||
|
expect(request.end).toEqual(mockConductor.displayEnd());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("with domain selection", function () {
|
||||||
|
expect(request.domain).toEqual(mockConductor.domain());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds display start/end times to subscription requests", function () {
|
describe("decorates subscription requests", function () {
|
||||||
var mockCallback = jasmine.createSpy('callback');
|
var request;
|
||||||
decorator.subscribe(mockCallback, [{ someKey: "some value" }]);
|
|
||||||
expect(mockTelemetryService.subscribe)
|
beforeEach(function () {
|
||||||
.toHaveBeenCalledWith(jasmine.any(Function), [{
|
var mockCallback = jasmine.createSpy('callback');
|
||||||
someKey: "some value",
|
decorator.subscribe(mockCallback, [{ someKey: "some value" }]);
|
||||||
start: mockConductor.displayStart(),
|
request = mockTelemetryService.subscribe
|
||||||
end: mockConductor.displayEnd()
|
.mostRecentCall.args[1][0];
|
||||||
}]);
|
});
|
||||||
|
|
||||||
|
it("with start times", function () {
|
||||||
|
expect(request.start).toEqual(mockConductor.displayStart());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("with end times", function () {
|
||||||
|
expect(request.end).toEqual(mockConductor.displayEnd());
|
||||||
|
});
|
||||||
|
|
||||||
|
it("with domain selection", function () {
|
||||||
|
expect(request.domain).toEqual(mockConductor.domain());
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
//
|
||||||
|
// it("adds display start/end times & domain selection to historical requests", function () {
|
||||||
|
// decorator.requestTelemetry([{ someKey: "some value" }]);
|
||||||
|
// expect(mockTelemetryService.requestTelemetry)
|
||||||
|
// .toHaveBeenCalledWith([{
|
||||||
|
// someKey: "some value",
|
||||||
|
// start: mockConductor.displayStart(),
|
||||||
|
// end: mockConductor.displayEnd(),
|
||||||
|
// domain: jasmine.any(String)
|
||||||
|
// }]);
|
||||||
|
// });
|
||||||
|
//
|
||||||
|
// it("adds display start/end times & domain selection to subscription requests", function () {
|
||||||
|
// var mockCallback = jasmine.createSpy('callback');
|
||||||
|
// decorator.subscribe(mockCallback, [{ someKey: "some value" }]);
|
||||||
|
// expect(mockTelemetryService.subscribe)
|
||||||
|
// .toHaveBeenCalledWith(jasmine.any(Function), [{
|
||||||
|
// someKey: "some value",
|
||||||
|
// start: mockConductor.displayStart(),
|
||||||
|
// end: mockConductor.displayEnd(),
|
||||||
|
// domain: jasmine.any(String)
|
||||||
|
// }]);
|
||||||
|
// });
|
||||||
|
|
||||||
it("prunes historical values to the displayable range", function () {
|
it("prunes historical values to the displayable range", function () {
|
||||||
var packagedTelemetry;
|
var packagedTelemetry;
|
||||||
|
|||||||
@@ -22,8 +22,8 @@
|
|||||||
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
define(
|
define(
|
||||||
["../src/ConductorTelemetrySeries"],
|
["../src/ConductorTelemetrySeries", "./TestTimeConductor"],
|
||||||
function (ConductorTelemetrySeries) {
|
function (ConductorTelemetrySeries, TestTimeConductor) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("ConductorTelemetrySeries", function () {
|
describe("ConductorTelemetrySeries", function () {
|
||||||
@@ -39,10 +39,7 @@ define(
|
|||||||
'series',
|
'series',
|
||||||
[ 'getPointCount', 'getDomainValue', 'getRangeValue' ]
|
[ 'getPointCount', 'getDomainValue', 'getRangeValue' ]
|
||||||
);
|
);
|
||||||
mockConductor = jasmine.createSpyObj(
|
mockConductor = new TestTimeConductor();
|
||||||
'conductor',
|
|
||||||
[ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ]
|
|
||||||
);
|
|
||||||
|
|
||||||
mockSeries.getPointCount.andCallFake(function () {
|
mockSeries.getPointCount.andCallFake(function () {
|
||||||
return testArray.length;
|
return testArray.length;
|
||||||
|
|||||||
48
platform/features/conductor/test/TestTimeConductor.js
Normal file
48
platform/features/conductor/test/TestTimeConductor.js
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* 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.
|
||||||
|
*****************************************************************************/
|
||||||
|
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine,spyOn*/
|
||||||
|
|
||||||
|
define(
|
||||||
|
["../src/TimeConductor"],
|
||||||
|
function (TimeConductor) {
|
||||||
|
function TestTimeConductor() {
|
||||||
|
var self = this;
|
||||||
|
|
||||||
|
TimeConductor.apply(this, [
|
||||||
|
402514200000,
|
||||||
|
444546000000,
|
||||||
|
[
|
||||||
|
{ key: "domain0", name: "Domain #1" },
|
||||||
|
{ key: "domain1", name: "Domain #2" }
|
||||||
|
]
|
||||||
|
]);
|
||||||
|
|
||||||
|
Object.keys(TimeConductor.prototype).forEach(function (method) {
|
||||||
|
spyOn(self, method).andCallThrough();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
TestTimeConductor.prototype = TimeConductor.prototype;
|
||||||
|
|
||||||
|
return TestTimeConductor;
|
||||||
|
}
|
||||||
|
);
|
||||||
@@ -21,9 +21,6 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
/*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||||
|
|
||||||
/**
|
|
||||||
* EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015.
|
|
||||||
*/
|
|
||||||
define(
|
define(
|
||||||
["../src/TimeConductor"],
|
["../src/TimeConductor"],
|
||||||
function (TimeConductor) {
|
function (TimeConductor) {
|
||||||
@@ -32,12 +29,17 @@ define(
|
|||||||
describe("TimeConductor", function () {
|
describe("TimeConductor", function () {
|
||||||
var testStart,
|
var testStart,
|
||||||
testEnd,
|
testEnd,
|
||||||
|
testDomains,
|
||||||
conductor;
|
conductor;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
testStart = 42;
|
testStart = 42;
|
||||||
testEnd = 12321;
|
testEnd = 12321;
|
||||||
conductor = new TimeConductor(testStart, testEnd);
|
testDomains = [
|
||||||
|
{ key: "d1", name: "Domain #1" },
|
||||||
|
{ key: "d2", name: "Domain #2" }
|
||||||
|
]
|
||||||
|
conductor = new TimeConductor(testStart, testEnd, testDomains);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("provides accessors for query/display start/end times", function () {
|
it("provides accessors for query/display start/end times", function () {
|
||||||
@@ -58,6 +60,25 @@ define(
|
|||||||
expect(conductor.displayEnd()).toEqual(4);
|
expect(conductor.displayEnd()).toEqual(4);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("exposes domain options", function () {
|
||||||
|
expect(conductor.domainOptions()).toEqual(testDomains);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("exposes the current domain choice", function () {
|
||||||
|
expect(conductor.domain()).toEqual(testDomains[0].key);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("allows the domain choice to be changed", function () {
|
||||||
|
conductor.domain(testDomains[1].key);
|
||||||
|
expect(conductor.domain()).toEqual(testDomains[1].key);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("throws an error on attempts to set an invalid domain", function () {
|
||||||
|
expect(function () {
|
||||||
|
conductor.domain("invalid-domain");
|
||||||
|
}).toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user