Merge remote-tracking branch 'github/master' into open233b
Resolve conflicts on nasa/openmctweb#233 Conflicts: platform/commonUI/general/bundle.json platform/commonUI/general/res/fonts/symbols/icomoon.io-WTD-symbols-project.json platform/commonUI/general/res/fonts/symbols/wtdsymbols.eot platform/commonUI/general/res/fonts/symbols/wtdsymbols.svg platform/commonUI/general/res/fonts/symbols/wtdsymbols.ttf platform/commonUI/general/res/fonts/symbols/wtdsymbols.woff platform/commonUI/general/res/sass/_main.scss platform/commonUI/general/res/sass/user-environ/_layout.scss platform/commonUI/themes/espresso/res/css/theme-espresso.css platform/commonUI/themes/espresso/res/sass/_constants.scss platform/commonUI/themes/snow/res/css/theme-snow.css
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
/*****************************************************************************
|
||||
* 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,Promise,describe,it,expect,beforeEach,waitsFor,jasmine*/
|
||||
|
||||
define(
|
||||
["../../src/controllers/DateTimeFieldController", "moment"],
|
||||
function (DateTimeFieldController, moment) {
|
||||
'use strict';
|
||||
|
||||
var TEST_FORMAT = "YYYY-MM-DD HH:mm:ss";
|
||||
|
||||
describe("The DateTimeFieldController", function () {
|
||||
var mockScope,
|
||||
mockFormatService,
|
||||
mockFormat,
|
||||
controller;
|
||||
|
||||
function fireWatch(expr, value) {
|
||||
mockScope.$watch.calls.forEach(function (call) {
|
||||
if (call.args[0] === expr) {
|
||||
call.args[1](value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
mockScope = jasmine.createSpyObj('$scope', ['$watch']);
|
||||
mockFormatService =
|
||||
jasmine.createSpyObj('formatService', ['getFormat']);
|
||||
mockFormat = jasmine.createSpyObj('format', [
|
||||
'parse',
|
||||
'validate',
|
||||
'format'
|
||||
]);
|
||||
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
|
||||
mockFormat.validate.andCallFake(function (text) {
|
||||
return moment.utc(text, TEST_FORMAT).isValid();
|
||||
});
|
||||
mockFormat.parse.andCallFake(function (text) {
|
||||
return moment.utc(text, TEST_FORMAT).valueOf();
|
||||
});
|
||||
mockFormat.format.andCallFake(function (value) {
|
||||
return moment.utc(value).format(TEST_FORMAT);
|
||||
});
|
||||
|
||||
mockScope.ngModel = { testField: 12321 };
|
||||
mockScope.field = "testField";
|
||||
mockScope.structure = { format: "someFormat" };
|
||||
|
||||
controller = new DateTimeFieldController(
|
||||
mockScope,
|
||||
mockFormatService
|
||||
);
|
||||
});
|
||||
|
||||
it("updates models from user-entered text", function () {
|
||||
var newText = "1977-05-25 17:30:00";
|
||||
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
expect(mockScope.ngModel.testField)
|
||||
.toEqual(mockFormat.parse(newText));
|
||||
expect(mockScope.textInvalid).toBeFalsy();
|
||||
});
|
||||
|
||||
it("updates text from model values", function () {
|
||||
var testTime = mockFormat.parse("1977-05-25 17:30:00");
|
||||
mockScope.ngModel.testField = testTime;
|
||||
fireWatch("ngModel[field]", testTime);
|
||||
expect(mockScope.textValue).toEqual("1977-05-25 17:30:00");
|
||||
});
|
||||
|
||||
describe("when user input is invalid", function () {
|
||||
var newText, oldValue;
|
||||
|
||||
beforeEach(function () {
|
||||
newText = "Not a date";
|
||||
oldValue = mockScope.ngModel.testField;
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
});
|
||||
|
||||
it("displays error state", function () {
|
||||
expect(mockScope.textInvalid).toBeTruthy();
|
||||
});
|
||||
|
||||
it("does not modify model state", function () {
|
||||
expect(mockScope.ngModel.testField).toEqual(oldValue);
|
||||
});
|
||||
|
||||
it("does not modify user input", function () {
|
||||
expect(mockScope.textValue).toEqual(newText);
|
||||
});
|
||||
});
|
||||
|
||||
it("does not modify valid but irregular user input", function () {
|
||||
// Don't want the controller "fixing" bad or
|
||||
// irregularly-formatted input out from under
|
||||
// the user's fingertips.
|
||||
var newText = "2015-3-3 01:02:04",
|
||||
oldValue = mockScope.ngModel.testField;
|
||||
|
||||
mockFormat.validate.andReturn(true);
|
||||
mockFormat.parse.andReturn(42);
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
|
||||
expect(mockScope.textValue).toEqual(newText);
|
||||
expect(mockScope.ngModel.testField).toEqual(42);
|
||||
expect(mockScope.ngModel.testField).not.toEqual(oldValue);
|
||||
});
|
||||
|
||||
it("obtains a format from the format service", function () {
|
||||
fireWatch('structure.format', mockScope.structure.format);
|
||||
expect(mockFormatService.getFormat)
|
||||
.toHaveBeenCalledWith(mockScope.structure.format);
|
||||
});
|
||||
|
||||
it("throws an error for unknown formats", function () {
|
||||
mockFormatService.getFormat.andReturn(undefined);
|
||||
expect(function () {
|
||||
fireWatch("structure.format", "some-format");
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
describe("using the obtained format", function () {
|
||||
var testValue = 1234321,
|
||||
testText = "some text";
|
||||
|
||||
beforeEach(function () {
|
||||
mockFormat.validate.andReturn(true);
|
||||
mockFormat.parse.andReturn(testValue);
|
||||
mockFormat.format.andReturn(testText);
|
||||
});
|
||||
|
||||
it("parses user input", function () {
|
||||
var newText = "some other new text";
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
expect(mockFormat.parse).toHaveBeenCalledWith(newText);
|
||||
expect(mockScope.ngModel.testField).toEqual(testValue);
|
||||
});
|
||||
|
||||
it("validates user input", function () {
|
||||
var newText = "some other new text";
|
||||
mockScope.textValue = newText;
|
||||
fireWatch("textValue", newText);
|
||||
expect(mockFormat.validate).toHaveBeenCalledWith(newText);
|
||||
});
|
||||
|
||||
it("formats model data for display", function () {
|
||||
var newValue = 42;
|
||||
mockScope.ngModel.testField = newValue;
|
||||
fireWatch("ngModel[field]", newValue);
|
||||
expect(mockFormat.format).toHaveBeenCalledWith(newValue);
|
||||
expect(mockScope.textValue).toEqual(testText);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
@@ -33,7 +33,10 @@ define(
|
||||
|
||||
describe("The TimeRangeController", function () {
|
||||
var mockScope,
|
||||
mockFormatService,
|
||||
testDefaultFormat,
|
||||
mockNow,
|
||||
mockFormat,
|
||||
controller;
|
||||
|
||||
function fireWatch(expr, value) {
|
||||
@@ -57,8 +60,30 @@ define(
|
||||
"$scope",
|
||||
[ "$apply", "$watch", "$watchCollection" ]
|
||||
);
|
||||
mockFormatService = jasmine.createSpyObj(
|
||||
"formatService",
|
||||
[ "getFormat" ]
|
||||
);
|
||||
testDefaultFormat = 'utc';
|
||||
mockFormat = jasmine.createSpyObj(
|
||||
"format",
|
||||
[ "validate", "format", "parse" ]
|
||||
);
|
||||
|
||||
mockFormatService.getFormat.andReturn(mockFormat);
|
||||
|
||||
mockFormat.format.andCallFake(function (value) {
|
||||
return moment.utc(value).format("YYYY-MM-DD HH:mm:ss");
|
||||
});
|
||||
|
||||
mockNow = jasmine.createSpy('now');
|
||||
controller = new TimeRangeController(mockScope, mockNow);
|
||||
|
||||
controller = new TimeRangeController(
|
||||
mockScope,
|
||||
mockFormatService,
|
||||
testDefaultFormat,
|
||||
mockNow
|
||||
);
|
||||
});
|
||||
|
||||
it("watches the model that was passed in", function () {
|
||||
@@ -167,70 +192,22 @@ define(
|
||||
.toBeGreaterThan(mockScope.ngModel.inner.start);
|
||||
});
|
||||
|
||||
describe("by typing", function () {
|
||||
it("updates models", function () {
|
||||
var newStart = "1977-05-25 17:30:00",
|
||||
newEnd = "2015-12-18 03:30:00";
|
||||
|
||||
mockScope.boundsModel.start = newStart;
|
||||
fireWatch("boundsModel.start", newStart);
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.toEqual(moment.utc(newStart).valueOf());
|
||||
expect(mockScope.boundsModel.startValid)
|
||||
.toBeTruthy();
|
||||
|
||||
mockScope.boundsModel.end = newEnd;
|
||||
fireWatch("boundsModel.end", newEnd);
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.toEqual(moment.utc(newEnd).valueOf());
|
||||
expect(mockScope.boundsModel.endValid)
|
||||
.toBeTruthy();
|
||||
});
|
||||
|
||||
it("displays error state", function () {
|
||||
var newStart = "Not a date",
|
||||
newEnd = "Definitely not a date",
|
||||
oldStart = mockScope.ngModel.outer.start,
|
||||
oldEnd = mockScope.ngModel.outer.end;
|
||||
|
||||
mockScope.boundsModel.start = newStart;
|
||||
fireWatch("boundsModel.start", newStart);
|
||||
expect(mockScope.ngModel.outer.start)
|
||||
.toEqual(oldStart);
|
||||
expect(mockScope.boundsModel.startValid)
|
||||
.toBeFalsy();
|
||||
|
||||
mockScope.boundsModel.end = newEnd;
|
||||
fireWatch("boundsModel.end", newEnd);
|
||||
expect(mockScope.ngModel.outer.end)
|
||||
.toEqual(oldEnd);
|
||||
expect(mockScope.boundsModel.endValid)
|
||||
.toBeFalsy();
|
||||
});
|
||||
|
||||
it("does not modify user input", function () {
|
||||
// Don't want the controller "fixing" bad or
|
||||
// irregularly-formatted input out from under
|
||||
// the user's fingertips.
|
||||
var newStart = "Not a date",
|
||||
newEnd = "2015-3-3 01:02:04",
|
||||
oldStart = mockScope.ngModel.outer.start,
|
||||
oldEnd = mockScope.ngModel.outer.end;
|
||||
|
||||
mockScope.boundsModel.start = newStart;
|
||||
fireWatch("boundsModel.start", newStart);
|
||||
expect(mockScope.boundsModel.start)
|
||||
.toEqual(newStart);
|
||||
|
||||
mockScope.boundsModel.end = newEnd;
|
||||
fireWatch("boundsModel.end", newEnd);
|
||||
expect(mockScope.boundsModel.end)
|
||||
.toEqual(newEnd);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("watches for changes in format selection", function () {
|
||||
expect(mockFormatService.getFormat)
|
||||
.not.toHaveBeenCalledWith('test-format');
|
||||
fireWatch("parameters.format", 'test-format');
|
||||
expect(mockFormatService.getFormat)
|
||||
.toHaveBeenCalledWith('test-format');
|
||||
});
|
||||
|
||||
it("throws an error for unknown formats", function () {
|
||||
mockFormatService.getFormat.andReturn(undefined);
|
||||
expect(function () {
|
||||
fireWatch("parameters.format", "some-format");
|
||||
}).toThrow();
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user