mirror of
https://github.com/nasa/openmct.git
synced 2025-06-13 20:58:15 +00:00
[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:
@ -121,8 +121,8 @@ define(
|
|||||||
function populateElement(template) {
|
function populateElement(template) {
|
||||||
destroyScope();
|
destroyScope();
|
||||||
activeScope = scope.$new(false);
|
activeScope = scope.$new(false);
|
||||||
element.empty();
|
element.html(template);
|
||||||
element.append(self.$compile(template)(activeScope));
|
self.$compile(element.contents())(activeScope);
|
||||||
}
|
}
|
||||||
|
|
||||||
function badTemplate(templateUrl) {
|
function badTemplate(templateUrl) {
|
||||||
|
@ -27,7 +27,7 @@ define(
|
|||||||
function (TemplateLinker) {
|
function (TemplateLinker) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var JQLITE_METHODS = [ 'replaceWith', 'empty', 'append' ],
|
var JQLITE_METHODS = [ 'replaceWith', 'empty', 'html', 'contents' ],
|
||||||
SCOPE_METHODS = [ '$on', '$new', '$destroy' ];
|
SCOPE_METHODS = [ '$on', '$new', '$destroy' ];
|
||||||
|
|
||||||
describe("TemplateLinker", function () {
|
describe("TemplateLinker", function () {
|
||||||
@ -39,6 +39,7 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
mockTemplates,
|
mockTemplates,
|
||||||
mockElements,
|
mockElements,
|
||||||
|
mockContents,
|
||||||
mockNewScope,
|
mockNewScope,
|
||||||
mockPromise,
|
mockPromise,
|
||||||
linker;
|
linker;
|
||||||
@ -54,9 +55,12 @@ define(
|
|||||||
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
mockPromise = jasmine.createSpyObj('promise', ['then']);
|
||||||
mockTemplates = {};
|
mockTemplates = {};
|
||||||
mockElements = {};
|
mockElements = {};
|
||||||
|
mockContents = {};
|
||||||
|
|
||||||
mockTemplateRequest.andReturn(mockPromise);
|
mockTemplateRequest.andReturn(mockPromise);
|
||||||
mockCompile.andCallFake(function (html) {
|
mockCompile.andCallFake(function (toCompile) {
|
||||||
|
var html = typeof toCompile === 'string' ?
|
||||||
|
toCompile : toCompile.testHtml;
|
||||||
mockTemplates[html] = jasmine.createSpy('template');
|
mockTemplates[html] = jasmine.createSpy('template');
|
||||||
mockElements[html] =
|
mockElements[html] =
|
||||||
jasmine.createSpyObj('templateEl', JQLITE_METHODS);
|
jasmine.createSpyObj('templateEl', JQLITE_METHODS);
|
||||||
@ -67,6 +71,16 @@ define(
|
|||||||
return { trusted: url };
|
return { trusted: url };
|
||||||
});
|
});
|
||||||
mockScope.$new.andReturn(mockNewScope);
|
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(
|
linker = new TemplateLinker(
|
||||||
mockTemplateRequest,
|
mockTemplateRequest,
|
||||||
@ -135,8 +149,9 @@ define(
|
|||||||
}, false);
|
}, false);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("compiles loaded templates with a new scope", function () {
|
it("compiles element contents with a new scope", function () {
|
||||||
expect(mockCompile).toHaveBeenCalledWith(testTemplate);
|
expect(mockCompile)
|
||||||
|
.toHaveBeenCalledWith(mockContents[testTemplate]);
|
||||||
expect(mockTemplates[testTemplate])
|
expect(mockTemplates[testTemplate])
|
||||||
.toHaveBeenCalledWith(mockNewScope);
|
.toHaveBeenCalledWith(mockNewScope);
|
||||||
});
|
});
|
||||||
@ -146,9 +161,9 @@ define(
|
|||||||
.toHaveBeenCalledWith(mockElement);
|
.toHaveBeenCalledWith(mockElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("appends rendered content to the specified element", function () {
|
it("inserts HTML content into the specified element", function () {
|
||||||
expect(mockElement.append)
|
expect(mockElement.html)
|
||||||
.toHaveBeenCalledWith(mockElements[testTemplate]);
|
.toHaveBeenCalledWith(testTemplate);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("clears templates when called with undefined", function () {
|
it("clears templates when called with undefined", function () {
|
||||||
|
Reference in New Issue
Block a user