mirror of
https://github.com/nasa/openmct.git
synced 2025-05-10 04:22:53 +00:00
[Representation] Add more test cases
...for TemplateLinker, to achieve full code coverage.
This commit is contained in:
parent
b177c38656
commit
5fba6f5ead
@ -27,7 +27,7 @@ define(
|
|||||||
function (TemplateLinker) {
|
function (TemplateLinker) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var JQLITE_METHODS = [ 'replaceWith', 'empty' ];
|
var JQLITE_METHODS = [ 'replaceWith', 'empty', 'append' ];
|
||||||
|
|
||||||
describe("TemplateLinker", function () {
|
describe("TemplateLinker", function () {
|
||||||
var mockHttp,
|
var mockHttp,
|
||||||
@ -127,7 +127,7 @@ define(
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("replaces comments with the compiled element", function () {
|
it("replaces comments with specified element", function () {
|
||||||
mockChainPromise.then.mostRecentCall.args[0](
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
mockHttpPromise.then.mostRecentCall.args[0]({
|
mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
data: testTemplate
|
data: testTemplate
|
||||||
@ -136,6 +136,69 @@ define(
|
|||||||
expect(commentElement.replaceWith)
|
expect(commentElement.replaceWith)
|
||||||
.toHaveBeenCalledWith(mockElement);
|
.toHaveBeenCalledWith(mockElement);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("appends rendered content to the specified element", function () {
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
|
mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
|
data: testTemplate
|
||||||
|
})
|
||||||
|
);
|
||||||
|
mockTemplates[testTemplate].mostRecentCall.args[1](
|
||||||
|
mockElements[testTemplate]
|
||||||
|
);
|
||||||
|
expect(mockElement.append)
|
||||||
|
.toHaveBeenCalledWith(mockElements[testTemplate]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("clears templates when called with undefined", function () {
|
||||||
|
expect(mockElement.replaceWith.callCount)
|
||||||
|
.toEqual(1);
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
|
mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
|
data: testTemplate
|
||||||
|
})
|
||||||
|
);
|
||||||
|
changeTemplate(undefined);
|
||||||
|
expect(mockElement.replaceWith.callCount)
|
||||||
|
.toEqual(2);
|
||||||
|
expect(mockElement.replaceWith.mostRecentCall.args[0])
|
||||||
|
.toEqual(commentElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("logs no warnings", function () {
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
|
mockHttpPromise.then.mostRecentCall.args[0]({
|
||||||
|
data: testTemplate
|
||||||
|
})
|
||||||
|
);
|
||||||
|
mockTemplates[testTemplate].mostRecentCall.args[1](
|
||||||
|
mockElements[testTemplate]
|
||||||
|
);
|
||||||
|
expect(mockLog.warn).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("which cannot be found", function () {
|
||||||
|
beforeEach(function () {
|
||||||
|
mockChainPromise.then.mostRecentCall.args[0](
|
||||||
|
// Reject the http promise
|
||||||
|
mockHttpPromise.then.mostRecentCall.args[1]()
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("removes the element from the DOM", function () {
|
||||||
|
expect(mockElement.replaceWith.callCount)
|
||||||
|
.toEqual(2);
|
||||||
|
expect(
|
||||||
|
mockElement.replaceWith.mostRecentCall.args[0]
|
||||||
|
).toEqual(commentElement);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("logs a warning", function () {
|
||||||
|
expect(mockLog.warn)
|
||||||
|
.toHaveBeenCalledWith(jasmine.any(String));
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user