[Representation] Build URLs from templateLinker
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user