mirror of
https://github.com/nasa/openmct.git
synced 2024-12-24 15:26:39 +00:00
[Composition] Update specs
Update specs for changes to the return value of composition.add, nasa/openmctweb#97
This commit is contained in:
parent
b1238b0c96
commit
b2649de649
@ -161,7 +161,7 @@ define(
|
||||
mockDomainObject.getId.andReturn(id);
|
||||
mockCompositionCapability.invoke
|
||||
.andReturn(mockPromise([mockDomainObject]));
|
||||
return mockPromise(true);
|
||||
return mockPromise(mockDomainObject);
|
||||
});
|
||||
|
||||
// Should find it in the composition
|
||||
|
@ -52,10 +52,10 @@ define(
|
||||
// Take the most recently modified model, for cases where
|
||||
// multiple persistence spaces return models.
|
||||
function takeMostRecent(modelA, modelB) {
|
||||
return (!modelA || modelA.modified === undefined) ? modelB :
|
||||
(!modelB || modelB.modified === undefined) ? modelA :
|
||||
modelA.modified > modelB.modified ? modelA :
|
||||
modelB;
|
||||
return (!modelB || modelB.modified === undefined) ? modelA :
|
||||
(!modelA || modelA.modified === undefined) ? modelB :
|
||||
modelB.modified > modelA.modified ? modelB :
|
||||
modelA;
|
||||
}
|
||||
|
||||
PersistedModelProvider.prototype.getModels = function (ids) {
|
||||
|
@ -32,7 +32,9 @@ define(
|
||||
describe("The persisted model provider", function () {
|
||||
var mockQ,
|
||||
mockPersistenceService,
|
||||
SPACE = "some space",
|
||||
SPACE = "space0",
|
||||
spaces = [ "space1" ],
|
||||
modTimes,
|
||||
provider;
|
||||
|
||||
function mockPromise(value) {
|
||||
@ -51,12 +53,14 @@ define(
|
||||
}
|
||||
|
||||
beforeEach(function () {
|
||||
modTimes = {};
|
||||
mockQ = { when: mockPromise, all: mockAll };
|
||||
mockPersistenceService = {
|
||||
readObject: function (space, id) {
|
||||
return mockPromise({
|
||||
space: space,
|
||||
id: id
|
||||
id: id,
|
||||
modified: (modTimes[space] || {})[id]
|
||||
});
|
||||
}
|
||||
};
|
||||
@ -64,7 +68,8 @@ define(
|
||||
provider = new PersistedModelProvider(
|
||||
mockPersistenceService,
|
||||
mockQ,
|
||||
SPACE
|
||||
SPACE,
|
||||
spaces
|
||||
);
|
||||
});
|
||||
|
||||
@ -82,6 +87,24 @@ define(
|
||||
});
|
||||
});
|
||||
|
||||
it("reads object models from multiple spaces", function () {
|
||||
var models;
|
||||
|
||||
modTimes.space1 = {
|
||||
'x': 12321
|
||||
};
|
||||
|
||||
provider.getModels(["a", "x", "zz"]).then(function (m) {
|
||||
models = m;
|
||||
});
|
||||
|
||||
expect(models).toEqual({
|
||||
a: { space: SPACE, id: "a" },
|
||||
x: { space: 'space1', id: "x", modified: 12321 },
|
||||
zz: { space: SPACE, id: "zz" }
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
);
|
@ -59,15 +59,6 @@ define(
|
||||
// Note that this was checked-for explicitly during validate step
|
||||
var composition = parentObject.getCapability('composition');
|
||||
|
||||
function findChild(children) {
|
||||
var i;
|
||||
for (i = 0; i < children.length; i += 1) {
|
||||
if (children[i].getId() === object.getId()) {
|
||||
return children[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return composition.add(object).then(function (result) {
|
||||
return parentObject.getCapability('persistence')
|
||||
.persist()
|
||||
|
@ -207,7 +207,7 @@ define(
|
||||
it("persists parent", function () {
|
||||
linkService.perform(object, parentObject);
|
||||
expect(addPromise.then).toHaveBeenCalled();
|
||||
addPromise.resolve();
|
||||
addPromise.resolve(linkedObject);
|
||||
expect(parentObject.getCapability)
|
||||
.toHaveBeenCalledWith('persistence');
|
||||
expect(persistenceCapability.persist).toHaveBeenCalled();
|
||||
@ -219,7 +219,7 @@ define(
|
||||
whenComplete = jasmine.createSpy('whenComplete');
|
||||
returnPromise.then(whenComplete);
|
||||
|
||||
addPromise.resolve();
|
||||
addPromise.resolve(linkedObject);
|
||||
persistencePromise.resolve();
|
||||
compositionPromise.resolve([linkedObject]);
|
||||
expect(whenComplete).toHaveBeenCalledWith(linkedObject);
|
||||
|
Loading…
Reference in New Issue
Block a user