mirror of
https://github.com/nasa/openmct.git
synced 2025-01-19 11:17:04 +00:00
[Core] Add spec for StaticModelProvider
Add spec for StaticModelProvider to increase coverage in platform/core, for WTD-573.
This commit is contained in:
parent
9b52843e3f
commit
41ecb1f8c2
@ -20,7 +20,7 @@
|
||||
"provides": "modelService",
|
||||
"type": "provider",
|
||||
"implementation": "models/StaticModelProvider.js",
|
||||
"depends": [ "models[]", "$log" ]
|
||||
"depends": [ "models[]", "$q", "$log" ]
|
||||
},
|
||||
{
|
||||
"provides": "modelService",
|
||||
|
@ -4,7 +4,7 @@
|
||||
* Module defining RootModelProvider. Created by vwoeltje on 11/7/14.
|
||||
*/
|
||||
define(
|
||||
['./StaticModelProvider.js'],
|
||||
['./StaticModelProvider'],
|
||||
function (StaticModelProvider) {
|
||||
"use strict";
|
||||
|
||||
|
@ -12,7 +12,7 @@ define(
|
||||
* Loads static models, provided as declared extensions of bundles.
|
||||
* @constructor
|
||||
*/
|
||||
function StaticModelProvider(models, $log) {
|
||||
function StaticModelProvider(models, $q, $log) {
|
||||
var modelMap = {};
|
||||
|
||||
function addModelToMap(model) {
|
||||
@ -54,7 +54,7 @@ define(
|
||||
ids.forEach(function (id) {
|
||||
result[id] = modelMap[id];
|
||||
});
|
||||
return Promise.resolve(result);
|
||||
return $q.when(result);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -9,6 +9,72 @@ define(
|
||||
"use strict";
|
||||
|
||||
describe("The static model provider", function () {
|
||||
var models = [
|
||||
{
|
||||
"id": "a",
|
||||
"model": {
|
||||
"name": "Thing A",
|
||||
"someProperty": "Some Value A"
|
||||
}
|
||||
},
|
||||
{
|
||||
"id": "b",
|
||||
"model": {
|
||||
"name": "Thing B",
|
||||
"someProperty": "Some Value B"
|
||||
}
|
||||
}
|
||||
],
|
||||
mockLog,
|
||||
mockQ,
|
||||
provider;
|
||||
|
||||
beforeEach(function () {
|
||||
mockQ = jasmine.createSpyObj("$q", ["when"]);
|
||||
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]);
|
||||
provider = new StaticModelProvider(models, mockQ, mockLog);
|
||||
});
|
||||
|
||||
it("provides models from extension declarations", function () {
|
||||
var mockPromise = { then: function () { return; } };
|
||||
mockQ.when.andReturn(mockPromise);
|
||||
|
||||
// Verify that we got the promise as the return value
|
||||
expect(provider.getModels(["a", "b"])).toEqual(mockPromise);
|
||||
|
||||
// Verify that the promise has the desired models
|
||||
expect(mockQ.when.callCount).toEqual(1);
|
||||
expect(mockQ.when.mostRecentCall.args[0].a.name).toEqual("Thing A");
|
||||
expect(mockQ.when.mostRecentCall.args[0].a.someProperty).toEqual("Some Value A");
|
||||
expect(mockQ.when.mostRecentCall.args[0].b.name).toEqual("Thing B");
|
||||
expect(mockQ.when.mostRecentCall.args[0].b.someProperty).toEqual("Some Value B");
|
||||
});
|
||||
|
||||
|
||||
it("does not provide models which are not in extension declarations", function () {
|
||||
provider.getModels(["c"]);
|
||||
|
||||
// Verify that the promise has the desired models
|
||||
expect(mockQ.when.callCount).toEqual(1);
|
||||
expect(mockQ.when.mostRecentCall.args[0].c).toBeUndefined();
|
||||
});
|
||||
|
||||
it("logs a warning when model definitions are malformed", function () {
|
||||
// Verify precondition
|
||||
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||
|
||||
// Shouldn't fail with an exception
|
||||
expect(new StaticModelProvider([
|
||||
{ "bad": "no id" },
|
||||
{ "id": "...but no model..." },
|
||||
{ "model": "...and no id..." },
|
||||
{ "id": -40, "model": {} },
|
||||
{ "model": "should be an object", "id": "x" }
|
||||
], mockQ, mockLog)).toBeDefined();
|
||||
|
||||
// Should show warnings
|
||||
expect(mockLog.warn.callCount).toEqual(5);
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user