diff --git a/platform/representation/src/MCTInclude.js b/platform/representation/src/MCTInclude.js index c7b3c9a3ed..761a798dfa 100644 --- a/platform/representation/src/MCTInclude.js +++ b/platform/representation/src/MCTInclude.js @@ -71,14 +71,10 @@ define( // Prepopulate templateMap for easy look up by key templates.forEach(function (template) { - var key = template.key, - path = [ - template.bundle.path, - template.bundle.resources, - template.templateUrl - ].join("/"); + var key = template.key; // First found should win (priority ordering) - templateMap[key] = templateMap[key] || path; + templateMap[key] = + templateMap[key] || templateLinker.getPath(template); }); return { diff --git a/platform/representation/src/MCTRepresentation.js b/platform/representation/src/MCTRepresentation.js index 4704c0265e..10b6d3ccec 100644 --- a/platform/representation/src/MCTRepresentation.js +++ b/platform/representation/src/MCTRepresentation.js @@ -72,11 +72,7 @@ define( // Get a path to a representation function getPath(representation) { - return [ - representation.bundle.path, - representation.bundle.resources, - representation.templateUrl - ].join("/"); + return templateLinker.getPath(representation); } // Look up a matching representation for this domain object diff --git a/platform/representation/src/TemplateLinker.js b/platform/representation/src/TemplateLinker.js index e2b9f42155..da357fc1e3 100644 --- a/platform/representation/src/TemplateLinker.js +++ b/platform/representation/src/TemplateLinker.js @@ -61,6 +61,20 @@ define( })); }; + /** + * Get a path to a template from an extension definition fo + * a template, representation, or view. + * @param {TemplateDefinition} extensionDefinition the definition + * of the template/representation/view to resolve + */ + TemplateLinker.prototype.getPath = function (extensionDefinition) { + return [ + extensionDefinition.bundle.path, + extensionDefinition.bundle.resources, + extensionDefinition.templateUrl + ].join('/'); + }; + /** * Populate the given element with templates, within the given scope; * intended to support the `link` function of the supported directives. diff --git a/platform/representation/test/MCTIncludeSpec.js b/platform/representation/test/MCTIncludeSpec.js index 68fa7f5f77..94dc62fd0a 100644 --- a/platform/representation/test/MCTIncludeSpec.js +++ b/platform/representation/test/MCTIncludeSpec.js @@ -31,6 +31,7 @@ define( describe("The mct-include directive", function () { var testTemplates, + testUrls, mockLinker, mockScope, mockElement, @@ -58,11 +59,21 @@ define( templateUrl: "z/template.html" } ]; - mockLinker = jasmine.createSpyObj('templateLinker', ['link']); + testUrls = {}; + testTemplates.forEach(function (t, i) { + testUrls[t.key] = "some URL " + String(i); + }); + mockLinker = jasmine.createSpyObj( + 'templateLinker', + ['link', 'getPath'] + ); mockScope = jasmine.createSpyObj('$scope', ['$watch', '$on']); mockElement = jasmine.createSpyObj('element', ['empty']); mockChangeTemplate = jasmine.createSpy('changeTemplate'); mockLinker.link.andReturn(mockChangeTemplate); + mockLinker.getPath.andCallFake(function (template) { + return testUrls[template.key]; + }); mctInclude = new MCTInclude(testTemplates, mockLinker); mctInclude.link(mockScope, mockElement, {}); }); @@ -80,15 +91,14 @@ define( mockScope.key = 'abc'; fireWatch('key', mockScope.key); expect(mockChangeTemplate) - .toHaveBeenCalledWith("a/b/c/template.html"); + .toHaveBeenCalledWith(testUrls.abc); mockScope.key = 'xyz'; fireWatch('key', mockScope.key); expect(mockChangeTemplate) - .toHaveBeenCalledWith("x/y/z/template.html"); + .toHaveBeenCalledWith(testUrls.xyz); }); - }); } ); diff --git a/platform/representation/test/MCTRepresentationSpec.js b/platform/representation/test/MCTRepresentationSpec.js index 1f2d55b4ab..30fed7c0ca 100644 --- a/platform/representation/test/MCTRepresentationSpec.js +++ b/platform/representation/test/MCTRepresentationSpec.js @@ -36,6 +36,7 @@ define( describe("The mct-representation directive", function () { var testRepresentations, testViews, + testUrls, mockRepresenters, mockQ, mockLinker, @@ -64,6 +65,8 @@ define( } beforeEach(function () { + testUrls = {}; + testRepresentations = [ { key: "abc", @@ -94,6 +97,11 @@ define( testModel = { someKey: "some value" }; + testUrls = {}; + testViews.concat(testRepresentations).forEach(function (t, i) { + testUrls[t.key] = "some URL " + String(i); + }); + mockRepresenters = ["A", "B"].map(function (name) { var constructor = jasmine.createSpy("Representer" + name), representer = jasmine.createSpyObj( @@ -105,7 +113,10 @@ define( }); mockQ = { when: mockPromise }; - mockLinker = jasmine.createSpyObj('templateLinker', ['link']); + mockLinker = jasmine.createSpyObj( + 'templateLinker', + ['link', 'getPath'] + ); mockChangeTemplate = jasmine.createSpy('changeTemplate'); mockLog = jasmine.createSpyObj("$log", LOG_FUNCTIONS); @@ -115,6 +126,9 @@ define( mockDomainObject.getModel.andReturn(testModel); mockLinker.link.andReturn(mockChangeTemplate); + mockLinker.getPath.andCallFake(function (ext) { + return testUrls[ext.key]; + }); mctRepresentation = new MCTRepresentation( testRepresentations, @@ -160,7 +174,7 @@ define( fireWatch('domainObject', mockDomainObject); expect(mockChangeTemplate) - .toHaveBeenCalledWith("a/b/c/template.html"); + .toHaveBeenCalledWith(testUrls.abc); }); it("recognizes keys for views", function () { @@ -172,7 +186,7 @@ define( fireWatch('domainObject', mockDomainObject); expect(mockChangeTemplate) - .toHaveBeenCalledWith("x/y/z/template.html"); + .toHaveBeenCalledWith(testUrls.xyz); }); it("does not load templates until there is an object", function () { diff --git a/platform/representation/test/TemplateLinkerSpec.js b/platform/representation/test/TemplateLinkerSpec.js index fd8de94931..38a3f867e2 100644 --- a/platform/representation/test/TemplateLinkerSpec.js +++ b/platform/representation/test/TemplateLinkerSpec.js @@ -69,6 +69,16 @@ define( ); }); + it("resolves extension paths", function () { + expect(linker.getPath({ + bundle: { + path: 'a', + resources: 'b' + }, + templateUrl: 'c/d.html' + })).toEqual('a/b/c/d.html'); + }); + describe("when linking elements", function () { var changeTemplate, commentElement;