mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-10-04 01:59:18 +02:00
added test for setMessage function, fixing bug for elements with only one child
This commit is contained in:
parent
61a59911b8
commit
b992bcc732
4 changed files with 53 additions and 5 deletions
52
js/test.js
52
js/test.js
|
@ -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',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue