added test for setMessage function, fixing bug for elements with only one child

This commit is contained in:
El RIDO 2017-02-11 10:40:34 +01:00
parent 61a59911b8
commit b992bcc732
No known key found for this signature in database
GPG key ID: 0F5C940A6BD81F92
4 changed files with 53 additions and 5 deletions

View file

@ -77,7 +77,7 @@ describe('helper', function () {
var html = '',
result = true;
ids.forEach(function(item, i) {
html += '<div id="' + item.join('') + '">' + (contents[i] || contents[0]) + '</div>';
html += '<div id="' + item.join('') + '">' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '</div>';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
@ -102,7 +102,7 @@ describe('helper', function () {
var html = '',
result = true;
ids.forEach(function(item, i) {
html += '<div id="' + item.join('') + '">' + (contents[i] || contents[0]) + '</div>';
html += '<div id="' + item.join('') + '">' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '</div>';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
@ -117,6 +117,54 @@ describe('helper', function () {
);
});
describe('setMessage', function () {
jsc.property(
'replaces the content of an empty element, analog to setElementText',
jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
'nearray string',
'string',
function (ids, contents, replacingContent) {
var html = '',
result = true;
ids.forEach(function(item, i) {
html += '<div id="' + item.join('') + '">' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '</div>';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
var id = item.join(''),
element = $(document.getElementById(id));
$.PrivateBin.helper.setMessage(element, replacingContent);
result *= replacingContent === $(document.getElementById(id)).text();
});
clean();
return Boolean(result);
}
);
jsc.property(
'replaces the last child of a non-empty element',
jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
jsc.nearray(jsc.nearray(jsc.elements(alnumString))),
'nearray string',
'string',
function (ids, classes, contents, replacingContent) {
var html = '',
result = true;
ids.forEach(function(item, i) {
html += '<div id="' + item.join('') + '"><span class="' + (classes[i] || classes[0]) + '"></span> ' + $.PrivateBin.helper.htmlEntities(contents[i] || contents[0]) + '</div>';
});
var clean = jsdom(html);
ids.forEach(function(item, i) {
var id = item.join(''),
element = $(document.getElementById(id));
$.PrivateBin.helper.setMessage(element, replacingContent);
result *= ' ' + replacingContent === $(document.getElementById(id)).contents()[1].nodeValue;
});
clean();
return Boolean(result);
}
);
});
describe('scriptLocation', function () {
jsc.property(
'returns the URL without query & fragment',