From 386f1f20ff380a5046edd33ef4578c11d989bf4b Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 2 Dec 2015 10:49:18 -0800 Subject: [PATCH] [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. --- .../test/MCTRepresentationSpec.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 30fed7c0ca..141f2227f3 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -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); + }); }); } );