mirror of
https://github.com/nasa/openmct.git
synced 2025-06-14 13:18:15 +00:00
[Core] Specs for model service components
Fill in specs for model service components, part of bundle platform/core; WTD-573.
This commit is contained in:
@ -26,7 +26,7 @@
|
|||||||
"provides": "modelService",
|
"provides": "modelService",
|
||||||
"type": "provider",
|
"type": "provider",
|
||||||
"implementation": "models/RootModelProvider.js",
|
"implementation": "models/RootModelProvider.js",
|
||||||
"depends": [ "roots[]", "$log" ]
|
"depends": [ "roots[]", "$q", "$log" ]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"provides": "modelService",
|
"provides": "modelService",
|
||||||
|
@ -20,10 +20,10 @@ define(
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function RootModelProvider(roots, $log) {
|
function RootModelProvider(roots, $q, $log) {
|
||||||
// Pull out identifiers to used as ROOT's
|
// Pull out identifiers to used as ROOT's
|
||||||
var ids = roots.map(function (root) { return root.id; }),
|
var ids = roots.map(function (root) { return root.id; }),
|
||||||
baseProvider = new StaticModelProvider(roots, $log);
|
baseProvider = new StaticModelProvider(roots, $q, $log);
|
||||||
|
|
||||||
function addRoot(models) {
|
function addRoot(models) {
|
||||||
models.ROOT = {
|
models.ROOT = {
|
||||||
|
@ -9,6 +9,47 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The model aggregator", function () {
|
describe("The model aggregator", function () {
|
||||||
|
var mockQ,
|
||||||
|
mockProviders,
|
||||||
|
modelList = [
|
||||||
|
{ "a": { someKey: "some value" } },
|
||||||
|
{ "b": { someOtherKey: "some other value" } }
|
||||||
|
],
|
||||||
|
aggregator;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockQ = jasmine.createSpyObj("$q", [ "all" ]);
|
||||||
|
mockProviders = modelList.map(function (models, i) {
|
||||||
|
var mockProvider = jasmine.createSpyObj(
|
||||||
|
"mockProvider" + i,
|
||||||
|
[ "getModels" ]
|
||||||
|
);
|
||||||
|
mockProvider.getModels.andReturn(models);
|
||||||
|
return mockProvider;
|
||||||
|
});
|
||||||
|
|
||||||
|
mockQ.all.andReturn({
|
||||||
|
then: function (c) { return c(modelList); }
|
||||||
|
});
|
||||||
|
|
||||||
|
aggregator = new ModelAggregator(mockQ, mockProviders);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("aggregates results promised by multiple providers", function () {
|
||||||
|
expect(aggregator.getModels(["a", "b"])).toEqual({
|
||||||
|
"a": { someKey: "some value" },
|
||||||
|
"b": { someOtherKey: "some other value" }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it("passes ids to all aggregated providers", function () {
|
||||||
|
aggregator.getModels(["a", "b"]);
|
||||||
|
|
||||||
|
mockProviders.forEach(function (mockProvider) {
|
||||||
|
expect(mockProvider.getModels)
|
||||||
|
.toHaveBeenCalledWith(["a", "b"]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,57 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The persisted model provider", function () {
|
describe("The persisted model provider", function () {
|
||||||
|
var mockQ,
|
||||||
|
mockPersistenceService,
|
||||||
|
SPACE = "some space",
|
||||||
|
provider;
|
||||||
|
|
||||||
|
function mockPromise(value) {
|
||||||
|
return {
|
||||||
|
then: function (callback) {
|
||||||
|
return mockPromise(callback(value));
|
||||||
|
},
|
||||||
|
testValue: value
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockAll(mockPromises) {
|
||||||
|
return mockPromise(mockPromises.map(function (p) {
|
||||||
|
return p.testValue;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockQ = { when: mockPromise, all: mockAll };
|
||||||
|
mockPersistenceService = {
|
||||||
|
readObject: function (space, id) {
|
||||||
|
return mockPromise({
|
||||||
|
space: space,
|
||||||
|
id: id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
provider = new PersistedModelProvider(
|
||||||
|
mockPersistenceService,
|
||||||
|
mockQ,
|
||||||
|
SPACE
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("reads object models from persistence", function () {
|
||||||
|
var models;
|
||||||
|
|
||||||
|
provider.getModels(["a", "x", "zz"]).then(function (m) {
|
||||||
|
models = m;
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(models).toEqual({
|
||||||
|
a: { space: SPACE, id: "a" },
|
||||||
|
x: { space: SPACE, id: "x" },
|
||||||
|
zz: { space: SPACE, id: "zz" }
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,69 @@ define(
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
describe("The root model provider", function () {
|
describe("The root model provider", function () {
|
||||||
|
var roots = [
|
||||||
|
{
|
||||||
|
"id": "a",
|
||||||
|
"model": {
|
||||||
|
"name": "Thing A",
|
||||||
|
"someProperty": "Some Value A"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "b",
|
||||||
|
"model": {
|
||||||
|
"name": "Thing B",
|
||||||
|
"someProperty": "Some Value B"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
captured,
|
||||||
|
mockLog,
|
||||||
|
mockQ,
|
||||||
|
provider;
|
||||||
|
|
||||||
|
function mockPromise(value) {
|
||||||
|
return {
|
||||||
|
then: function (callback) {
|
||||||
|
return mockPromise(callback(value));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function capture(value) { captured = value; }
|
||||||
|
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
mockQ = { when: mockPromise };
|
||||||
|
mockLog = jasmine.createSpyObj("$log", ["error", "warn", "info", "debug"]);
|
||||||
|
provider = new RootModelProvider(roots, mockQ, mockLog);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides models from extension declarations", function () {
|
||||||
|
// Verify that we got the promise as the return value
|
||||||
|
provider.getModels(["a", "b"]).then(capture);
|
||||||
|
|
||||||
|
// Verify that the promise has the desired models
|
||||||
|
expect(captured.a.name).toEqual("Thing A");
|
||||||
|
expect(captured.a.someProperty).toEqual("Some Value A");
|
||||||
|
expect(captured.b.name).toEqual("Thing B");
|
||||||
|
expect(captured.b.someProperty).toEqual("Some Value B");
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it("does not provide models which are not in extension declarations", function () {
|
||||||
|
provider.getModels(["c"]).then(capture);
|
||||||
|
|
||||||
|
// Verify that the promise has the desired models
|
||||||
|
expect(captured.c).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides a ROOT object with roots in its composition", function () {
|
||||||
|
provider.getModels(["ROOT"]).then(capture);
|
||||||
|
|
||||||
|
expect(captured.ROOT).toBeDefined();
|
||||||
|
expect(captured.ROOT.composition).toEqual(["a", "b"]);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user