[Representation] Add test cases
...for TemplateLinker
This commit is contained in:
@@ -37,6 +37,8 @@ define(
|
|||||||
mockElement,
|
mockElement,
|
||||||
mockTemplates,
|
mockTemplates,
|
||||||
mockElements,
|
mockElements,
|
||||||
|
mockHttpPromise,
|
||||||
|
mockChainPromise,
|
||||||
linker;
|
linker;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -45,9 +47,13 @@ define(
|
|||||||
mockLog = jasmine.createSpyObj('$log', ['error', 'warn']);
|
mockLog = jasmine.createSpyObj('$log', ['error', 'warn']);
|
||||||
mockScope = jasmine.createSpyObj('$scope', ['$on']);
|
mockScope = jasmine.createSpyObj('$scope', ['$on']);
|
||||||
mockElement = jasmine.createSpyObj('element', JQLITE_METHODS);
|
mockElement = jasmine.createSpyObj('element', JQLITE_METHODS);
|
||||||
|
mockHttpPromise = jasmine.createSpyObj('promise1', ['then']);
|
||||||
|
mockChainPromise = jasmine.createSpyObj('promise2', ['then']);
|
||||||
mockTemplates = {};
|
mockTemplates = {};
|
||||||
mockElements = {};
|
mockElements = {};
|
||||||
|
|
||||||
|
mockHttp.get.andReturn(mockHttpPromise);
|
||||||
|
mockHttpPromise.then.andReturn(mockChainPromise);
|
||||||
mockCompile.andCallFake(function (html) {
|
mockCompile.andCallFake(function (html) {
|
||||||
mockTemplates[html] = jasmine.createSpy('template');
|
mockTemplates[html] = jasmine.createSpy('template');
|
||||||
mockElements[html] =
|
mockElements[html] =
|
||||||
@@ -89,6 +95,49 @@ define(
|
|||||||
expect(mockElement.replaceWith)
|
expect(mockElement.replaceWith)
|
||||||
.toHaveBeenCalledWith(commentElement);
|
.toHaveBeenCalledWith(commentElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("provides a function to change templates", function () {
|
||||||
|
expect(changeTemplate).toEqual(jasmine.any(Function));
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("and then changing templates", function () {
|
||||||
|
var testUrl,
|
||||||
|
testTemplate;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
testUrl = "some/url/template.html";
|
||||||
|
testTemplate = "<div>Some template!</div>";
|
||||||
|
changeTemplate(testUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("loads templates using $http", function () {
|
||||||
|
expect(mockHttp.get).toHaveBeenCalledWith(testUrl);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("compiles loaded templates with linked scope", function () {
|
||||||
|
var chainValue;
|
||||||
|
chainValue = mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
|
data: testTemplate
|
||||||
|
});
|
||||||
|
expect(mockCompile).toHaveBeenCalledWith(testTemplate);
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](chainValue);
|
||||||
|
expect(mockTemplates[testTemplate]).toHaveBeenCalledWith(
|
||||||
|
mockScope,
|
||||||
|
jasmine.any(Function)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("replaces comments with the compiled element", function () {
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
|
mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
|
data: testTemplate
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(commentElement.replaceWith)
|
||||||
|
.toHaveBeenCalledWith(mockElement);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user