[Representation] Update compilation approach

Update compilation approach for templateLinker to more
closely resemble ng-include; minimizes likelihood of
subtle behavioral differences (e.g. incorrect size
selection for split pane)
This commit is contained in:
Victor Woeltjen 2015-10-30 16:37:47 -07:00
parent 454a63e1f1
commit ae928a138c
2 changed files with 24 additions and 9 deletions

View File

@ -121,8 +121,8 @@ define(
function populateElement(template) {
destroyScope();
activeScope = scope.$new(false);
element.empty();
element.append(self.$compile(template)(activeScope));
element.html(template);
self.$compile(element.contents())(activeScope);
}
function badTemplate(templateUrl) {

View File

@ -27,7 +27,7 @@ define(
function (TemplateLinker) {
'use strict';
var JQLITE_METHODS = [ 'replaceWith', 'empty', 'append' ],
var JQLITE_METHODS = [ 'replaceWith', 'empty', 'html', 'contents' ],
SCOPE_METHODS = [ '$on', '$new', '$destroy' ];
describe("TemplateLinker", function () {
@ -39,6 +39,7 @@ define(
mockElement,
mockTemplates,
mockElements,
mockContents,
mockNewScope,
mockPromise,
linker;
@ -54,9 +55,12 @@ define(
mockPromise = jasmine.createSpyObj('promise', ['then']);
mockTemplates = {};
mockElements = {};
mockContents = {};
mockTemplateRequest.andReturn(mockPromise);
mockCompile.andCallFake(function (html) {
mockCompile.andCallFake(function (toCompile) {
var html = typeof toCompile === 'string' ?
toCompile : toCompile.testHtml;
mockTemplates[html] = jasmine.createSpy('template');
mockElements[html] =
jasmine.createSpyObj('templateEl', JQLITE_METHODS);
@ -67,6 +71,16 @@ define(
return { trusted: url };
});
mockScope.$new.andReturn(mockNewScope);
mockElement.html.andCallFake(function (html) {
mockContents[html] =
jasmine.createSpyObj('contentsEl', JQLITE_METHODS);
mockContents[html].testHtml = html;
});
mockElement.contents.andCallFake(function () {
return mockContents[
mockElement.html.mostRecentCall.args[0]
];
});
linker = new TemplateLinker(
mockTemplateRequest,
@ -135,8 +149,9 @@ define(
}, false);
});
it("compiles loaded templates with a new scope", function () {
expect(mockCompile).toHaveBeenCalledWith(testTemplate);
it("compiles element contents with a new scope", function () {
expect(mockCompile)
.toHaveBeenCalledWith(mockContents[testTemplate]);
expect(mockTemplates[testTemplate])
.toHaveBeenCalledWith(mockNewScope);
});
@ -146,9 +161,9 @@ define(
.toHaveBeenCalledWith(mockElement);
});
it("appends rendered content to the specified element", function () {
expect(mockElement.append)
.toHaveBeenCalledWith(mockElements[testTemplate]);
it("inserts HTML content into the specified element", function () {
expect(mockElement.html)
.toHaveBeenCalledWith(testTemplate);
});
it("clears templates when called with undefined", function () {