[Representation] Test switching between links

Add test case to verify that representation gets refreshed
when switching among two linked instances of the same
domain object.
This commit is contained in:
Victor Woeltjen 2015-12-02 10:49:18 -08:00
parent 5e07951892
commit 386f1f20ff

View File

@ -247,6 +247,54 @@ define(
mockScope.$watch.calls[0].args[1]();
expect(mockScope.testCapability).toBeUndefined();
});
it("detects changes among linked instances", function () {
var mockContext = jasmine.createSpyObj('context', ['getPath']),
mockContext2 = jasmine.createSpyObj('context', ['getPath']),
mockLink = jasmine.createSpyObj(
'linkedObject',
DOMAIN_OBJECT_METHODS
),
mockParent = jasmine.createSpyObj(
'parentObject',
DOMAIN_OBJECT_METHODS
),
callCount;
mockDomainObject.getCapability.andCallFake(function (c) {
return c === 'context' && mockContext;
});
mockLink.getCapability.andCallFake(function (c) {
return c === 'context' && mockContext2;
});
mockDomainObject.hasCapability.andCallFake(function (c) {
return c === 'context';
});
mockLink.hasCapability.andCallFake(function (c) {
return c === 'context';
});
mockLink.getModel.andReturn({});
mockContext.getPath.andReturn([mockDomainObject]);
mockContext2.getPath.andReturn([mockParent, mockLink]);
mockLink.getId.andReturn('test-id');
mockDomainObject.getId.andReturn('test-id');
mockParent.getId.andReturn('parent-id');
mockScope.key = "abc";
mockScope.domainObject = mockDomainObject;
mockScope.$watch.calls[0].args[1]();
callCount = mockChangeTemplate.calls.length;
mockScope.domainObject = mockLink;
mockScope.$watch.calls[0].args[1]();
expect(mockChangeTemplate.calls.length)
.toEqual(callCount + 1);
});
});
}
);