From cbaf45afe9e2a7ebfce00e11e5c9f81edc082346 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 25 Sep 2015 10:40:19 -0700 Subject: [PATCH] [Time Conductor] Update specs nasa/openmctweb#115 --- .../features/conductor/src/TimeConductor.js | 4 +- .../test/ConductorRepresenterSpec.js | 79 +++++++++++++--- .../conductor/test/ConductorServiceSpec.js | 8 +- .../test/ConductorTelemetryDecoratorSpec.js | 92 ++++++++++++++----- .../test/ConductorTelemetrySeriesSpec.js | 9 +- .../conductor/test/TestTimeConductor.js | 48 ++++++++++ .../conductor/test/TimeConductorSpec.js | 29 +++++- 7 files changed, 215 insertions(+), 54 deletions(-) create mode 100644 platform/features/conductor/test/TestTimeConductor.js diff --git a/platform/features/conductor/src/TimeConductor.js b/platform/features/conductor/src/TimeConductor.js index 6caa1e6d65..df30040b7f 100644 --- a/platform/features/conductor/src/TimeConductor.js +++ b/platform/features/conductor/src/TimeConductor.js @@ -119,9 +119,9 @@ define( if (!this.domains.some(matchesKey)) { throw new Error("Unknown domain " + key); } - this.domain = key; + this.activeDomain = key; } - return this.domain; + return this.activeDomain; }; return TimeConductor; diff --git a/platform/features/conductor/test/ConductorRepresenterSpec.js b/platform/features/conductor/test/ConductorRepresenterSpec.js index 2b1003f3c7..b0cf23745f 100644 --- a/platform/features/conductor/test/ConductorRepresenterSpec.js +++ b/platform/features/conductor/test/ConductorRepresenterSpec.js @@ -21,12 +21,9 @@ *****************************************************************************/ /*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( - ["../src/ConductorRepresenter"], - function (ConductorRepresenter) { + ["../src/ConductorRepresenter", "./TestTimeConductor"], + function (ConductorRepresenter, TestTimeConductor) { "use strict"; var SCOPE_METHODS = [ @@ -75,10 +72,7 @@ define( testViews = [ { someKey: "some value" } ]; mockScope = jasmine.createSpyObj('scope', SCOPE_METHODS); mockElement = jasmine.createSpyObj('element', ELEMENT_METHODS); - mockConductor = jasmine.createSpyObj( - 'conductor', - [ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ] - ); + mockConductor = new TestTimeConductor(); mockCompiledTemplate = jasmine.createSpy('template'); mockNewScope = jasmine.createSpyObj('newScope', SCOPE_METHODS); mockNewElement = jasmine.createSpyObj('newElement', ELEMENT_METHODS); @@ -133,7 +127,7 @@ define( mockConductor.displayEnd.andReturn(1984); representer.represent(testViews[0], {}); - expect(mockNewScope.conductor).toEqual({ + expect(mockNewScope.ngModel.conductor).toEqual({ inner: { start: 1977, end: 1984 }, outer: { start: 42, end: 12321 } }); @@ -147,21 +141,76 @@ define( 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); - fireWatch(mockNewScope, 'conductor.inner.end', testState.inner.end); + fireWatch( + mockNewScope, + 'ngModel.conductor.inner.end', + testState.inner.end + ); 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); - fireWatch(mockNewScope, 'conductor.outer.end', testState.outer.end); + fireWatch( + mockNewScope, + 'ngModel.conductor.outer.end', + testState.outer.end + ); 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); + }); + }); } ); diff --git a/platform/features/conductor/test/ConductorServiceSpec.js b/platform/features/conductor/test/ConductorServiceSpec.js index 5146ca5f42..4d6fb12f12 100644 --- a/platform/features/conductor/test/ConductorServiceSpec.js +++ b/platform/features/conductor/test/ConductorServiceSpec.js @@ -21,9 +21,6 @@ *****************************************************************************/ /*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ -/** - * EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015. - */ define( ["../src/ConductorService"], function (ConductorService) { @@ -38,7 +35,10 @@ define( beforeEach(function () { mockNow = jasmine.createSpy('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 () { diff --git a/platform/features/conductor/test/ConductorTelemetryDecoratorSpec.js b/platform/features/conductor/test/ConductorTelemetryDecoratorSpec.js index 84812b541a..7145682bf3 100644 --- a/platform/features/conductor/test/ConductorTelemetryDecoratorSpec.js +++ b/platform/features/conductor/test/ConductorTelemetryDecoratorSpec.js @@ -23,8 +23,8 @@ define( - ["../src/ConductorTelemetryDecorator"], - function (ConductorTelemetryDecorator) { + ["../src/ConductorTelemetryDecorator", "./TestTimeConductor"], + function (ConductorTelemetryDecorator, TestTimeConductor) { "use strict"; describe("ConductorTelemetryDecorator", function () { @@ -54,10 +54,7 @@ define( 'conductorService', ['getConductor'] ); - mockConductor = jasmine.createSpyObj( - 'conductor', - [ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ] - ); + mockConductor = new TestTimeConductor(); mockPromise = jasmine.createSpyObj( 'promise', ['then'] @@ -82,6 +79,7 @@ define( mockConductor.queryEnd.andReturn(-12321); mockConductor.displayStart.andReturn(42); mockConductor.displayEnd.andReturn(1977); + mockConductor.domain.andReturn("testDomain"); decorator = new ConductorTelemetryDecorator( mockConductorService, @@ -89,26 +87,74 @@ define( ); }); - it("adds display start/end times to historical requests", function () { - decorator.requestTelemetry([{ someKey: "some value" }]); - expect(mockTelemetryService.requestTelemetry) - .toHaveBeenCalledWith([{ - someKey: "some value", - start: mockConductor.displayStart(), - end: mockConductor.displayEnd() - }]); + + describe("decorates historical requests", function () { + var request; + + beforeEach(function () { + decorator.requestTelemetry([{ someKey: "some value" }]); + 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 () { - 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() - }]); + describe("decorates subscription requests", function () { + var request; + + beforeEach(function () { + var mockCallback = jasmine.createSpy('callback'); + decorator.subscribe(mockCallback, [{ someKey: "some value" }]); + request = mockTelemetryService.subscribe + .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 () { var packagedTelemetry; diff --git a/platform/features/conductor/test/ConductorTelemetrySeriesSpec.js b/platform/features/conductor/test/ConductorTelemetrySeriesSpec.js index ea884f74f3..9ce485d7d2 100644 --- a/platform/features/conductor/test/ConductorTelemetrySeriesSpec.js +++ b/platform/features/conductor/test/ConductorTelemetrySeriesSpec.js @@ -22,8 +22,8 @@ /*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ define( - ["../src/ConductorTelemetrySeries"], - function (ConductorTelemetrySeries) { + ["../src/ConductorTelemetrySeries", "./TestTimeConductor"], + function (ConductorTelemetrySeries, TestTimeConductor) { "use strict"; describe("ConductorTelemetrySeries", function () { @@ -39,10 +39,7 @@ define( 'series', [ 'getPointCount', 'getDomainValue', 'getRangeValue' ] ); - mockConductor = jasmine.createSpyObj( - 'conductor', - [ 'queryStart', 'queryEnd', 'displayStart', 'displayEnd' ] - ); + mockConductor = new TestTimeConductor(); mockSeries.getPointCount.andCallFake(function () { return testArray.length; diff --git a/platform/features/conductor/test/TestTimeConductor.js b/platform/features/conductor/test/TestTimeConductor.js new file mode 100644 index 0000000000..5c8b95896f --- /dev/null +++ b/platform/features/conductor/test/TestTimeConductor.js @@ -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; + } +); diff --git a/platform/features/conductor/test/TimeConductorSpec.js b/platform/features/conductor/test/TimeConductorSpec.js index 558322329e..27e9aad93f 100644 --- a/platform/features/conductor/test/TimeConductorSpec.js +++ b/platform/features/conductor/test/TimeConductorSpec.js @@ -21,9 +21,6 @@ *****************************************************************************/ /*global define,describe,it,expect,beforeEach,waitsFor,jasmine*/ -/** - * EventSpec. Created by vwoeltje on 11/6/14. Modified by shale on 06/23/2015. - */ define( ["../src/TimeConductor"], function (TimeConductor) { @@ -32,12 +29,17 @@ define( describe("TimeConductor", function () { var testStart, testEnd, + testDomains, conductor; beforeEach(function () { testStart = 42; 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 () { @@ -58,6 +60,25 @@ define( 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(); + }); + }); } );