mirror of
https://github.com/nasa/openmct.git
synced 2025-05-11 13:03:03 +00:00
[Time Conductor] Throw errors for unknown formats
Per code review, nasa/openmctweb#204
This commit is contained in:
parent
796d6b800a
commit
a1d765f271
@ -7,7 +7,7 @@
|
|||||||
"provides": "formatService",
|
"provides": "formatService",
|
||||||
"type": "provider",
|
"type": "provider",
|
||||||
"implementation": "FormatProvider.js",
|
"implementation": "FormatProvider.js",
|
||||||
"depends": [ "formats[]", "$log" ]
|
"depends": [ "formats[]" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"formats": [
|
"formats": [
|
||||||
|
@ -85,7 +85,7 @@ define([
|
|||||||
* @param {Array.<function(new : Format)>} format constructors,
|
* @param {Array.<function(new : Format)>} format constructors,
|
||||||
* from the `formats` extension category.
|
* from the `formats` extension category.
|
||||||
*/
|
*/
|
||||||
function FormatProvider(formats, $log) {
|
function FormatProvider(formats) {
|
||||||
var formatMap = {};
|
var formatMap = {};
|
||||||
|
|
||||||
function addToMap(Format) {
|
function addToMap(Format) {
|
||||||
@ -97,13 +97,12 @@ define([
|
|||||||
|
|
||||||
formats.forEach(addToMap);
|
formats.forEach(addToMap);
|
||||||
this.formatMap = formatMap;
|
this.formatMap = formatMap;
|
||||||
this.$log = $log;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FormatProvider.prototype.getFormat = function (key) {
|
FormatProvider.prototype.getFormat = function (key) {
|
||||||
var format = this.formatMap[key];
|
var format = this.formatMap[key];
|
||||||
if (!format) {
|
if (!format) {
|
||||||
this.$log.warn("No format found for " + key);
|
throw new Error("FormatProvider: No format found for " + key);
|
||||||
}
|
}
|
||||||
return format;
|
return format;
|
||||||
};
|
};
|
||||||
|
@ -41,14 +41,13 @@ 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, mockLog);
|
provider = new FormatProvider(mockFormats);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("looks up formats by key", function () {
|
it("looks up formats by key", function () {
|
||||||
@ -58,11 +57,10 @@ define(
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("warns about unknown formats", function () {
|
it("throws an error about unknown formats", function () {
|
||||||
provider.getFormat('a'); // known format
|
expect(function () {
|
||||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
provider.getFormat('some-unknown-format');
|
||||||
provider.getFormat('some-unknown-format');
|
}).toThrow();
|
||||||
expect(mockLog.warn).toHaveBeenCalledWith(jasmine.any(String));
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user