[Time Conductor] Update specs

...to reflect changes to how unspecified versus unknown formats
are handled.
This commit is contained in:
Victor Woeltjen 2015-10-30 13:53:33 -07:00
parent 7f571415dc
commit f42498ab60
3 changed files with 26 additions and 1 deletions

View File

@ -30,6 +30,7 @@ define(
describe("The FormatProvider", function () { describe("The FormatProvider", function () {
var mockFormats, var mockFormats,
mockLog,
mockFormatInstances, mockFormatInstances,
provider; provider;
@ -40,13 +41,14 @@ define(
[ 'parse', 'validate', 'format' ] [ 'parse', 'validate', 'format' ]
); );
}); });
mockLog = jasmine.createSpyObj('$log', ['error', 'warn']);
// Return constructors // Return constructors
mockFormats = KEYS.map(function (k, i) { mockFormats = KEYS.map(function (k, i) {
function MockFormat() { return mockFormatInstances[i]; } function MockFormat() { return mockFormatInstances[i]; }
MockFormat.key = k; MockFormat.key = k;
return MockFormat; return MockFormat;
}); });
provider = new FormatProvider(mockFormats); provider = new FormatProvider(mockFormats, mockLog);
}); });
it("looks up formats by key", function () { it("looks up formats by key", function () {
@ -56,6 +58,13 @@ define(
}); });
}); });
it("warns about unknown formats", function () {
provider.getFormat('a'); // known format
expect(mockLog.warn).not.toHaveBeenCalled();
provider.getFormat('some-unknown-format');
expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String));
});
}); });
} }
); );

View File

@ -137,6 +137,13 @@ define(
.toHaveBeenCalledWith(mockScope.structure.format); .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 () { describe("using the obtained format", function () {
var testValue = 1234321, var testValue = 1234321,
testText = "some text"; testText = "some text";

View File

@ -34,6 +34,7 @@ define(
describe("The TimeRangeController", function () { describe("The TimeRangeController", function () {
var mockScope, var mockScope,
mockFormatService, mockFormatService,
testDefaultFormat,
mockNow, mockNow,
mockFormat, mockFormat,
controller; controller;
@ -63,6 +64,7 @@ define(
"formatService", "formatService",
[ "getFormat" ] [ "getFormat" ]
); );
testDefaultFormat = 'utc';
mockFormat = jasmine.createSpyObj( mockFormat = jasmine.createSpyObj(
"format", "format",
[ "validate", "format", "parse" ] [ "validate", "format", "parse" ]
@ -79,6 +81,7 @@ define(
controller = new TimeRangeController( controller = new TimeRangeController(
mockScope, mockScope,
mockFormatService, mockFormatService,
testDefaultFormat,
mockNow mockNow
); );
}); });
@ -199,6 +202,12 @@ define(
.toHaveBeenCalledWith('test-format'); .toHaveBeenCalledWith('test-format');
}); });
it("throws an error for unknown formats", function () {
mockFormatService.getFormat.andReturn(undefined);
expect(function () {
fireWatch("parameters.format", "some-format");
}).toThrow();
});
}); });
} }