[Location] Test getOriginal method
This commit is contained in:
@@ -22,6 +22,7 @@ define(
|
|||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
domainObject = domainObjectFactory({
|
domainObject = domainObjectFactory({
|
||||||
|
id: "testObject",
|
||||||
capabilities: {
|
capabilities: {
|
||||||
context: {
|
context: {
|
||||||
getParent: function () {
|
getParent: function () {
|
||||||
@@ -60,7 +61,7 @@ define(
|
|||||||
|
|
||||||
locationCapability = new LocationCapability(
|
locationCapability = new LocationCapability(
|
||||||
mockQ,
|
mockQ,
|
||||||
mockObjectService,
|
mockInjector,
|
||||||
domainObject
|
domainObject
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
@@ -101,6 +102,57 @@ define(
|
|||||||
expect(whenComplete).toHaveBeenCalled();
|
expect(whenComplete).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("when used to load an original instance", function () {
|
||||||
|
var objectPromise,
|
||||||
|
qPromise,
|
||||||
|
originalObjects,
|
||||||
|
mockCallback;
|
||||||
|
|
||||||
|
function resolvePromises() {
|
||||||
|
if (mockQ.when.calls.length > 0) {
|
||||||
|
qPromise.resolve(mockQ.when.mostRecentCall.args[0]);
|
||||||
|
}
|
||||||
|
if (mockObjectService.getObjects.calls.length > 0) {
|
||||||
|
objectPromise.resolve(originalObjects);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
objectPromise = new ControlledPromise();
|
||||||
|
qPromise = new ControlledPromise();
|
||||||
|
originalObjects = {
|
||||||
|
testObject: domainObjectFactory()
|
||||||
|
};
|
||||||
|
|
||||||
|
mockInjector.get.andCallFake(function (key) {
|
||||||
|
return key === 'objectService' && mockObjectService;
|
||||||
|
});
|
||||||
|
mockObjectService.getObjects.andReturn(objectPromise);
|
||||||
|
mockQ.when.andReturn(qPromise);
|
||||||
|
|
||||||
|
mockCallback = jasmine.createSpy('callback');
|
||||||
|
});
|
||||||
|
|
||||||
|
it("provides originals directly", function () {
|
||||||
|
domainObject.model.location = 'root';
|
||||||
|
locationCapability.getOriginal().then(mockCallback);
|
||||||
|
expect(mockCallback).not.toHaveBeenCalled();
|
||||||
|
resolvePromises();
|
||||||
|
expect(mockCallback)
|
||||||
|
.toHaveBeenCalledWith(domainObject);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("loads from the object service for links", function () {
|
||||||
|
domainObject.model.location = 'some-other-root';
|
||||||
|
locationCapability.getOriginal().then(mockCallback);
|
||||||
|
expect(mockCallback).not.toHaveBeenCalled();
|
||||||
|
resolvePromises();
|
||||||
|
expect(mockCallback)
|
||||||
|
.toHaveBeenCalledWith(originalObjects.testObject);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user