From 61a59911b8bf3f0e5aa647d6b870e8c9ebfbc2db Mon Sep 17 00:00:00 2001 From: El RIDO Date: Sat, 11 Feb 2017 09:56:56 +0100 Subject: [PATCH] added test for setElementText function --- js/test.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/js/test.js b/js/test.js index d9eb8703..93e7a8c1 100644 --- a/js/test.js +++ b/js/test.js @@ -71,24 +71,48 @@ describe('helper', function () { describe('selectText', function () { jsc.property( 'selection contains content of given ID', + jsc.nearray(jsc.nearray(jsc.elements(alnumString))), 'nearray string', - 'nearray nestring', function (ids, contents) { - //console.log(ids, contents); var html = '', result = true; ids.forEach(function(item, i) { - html += '
' + (contents[i] || contents[0]) + '
'; + html += '
' + (contents[i] || contents[0]) + '
'; }); var clean = jsdom(html); ids.forEach(function(item, i) { - $.PrivateBin.helper.selectText(item); + $.PrivateBin.helper.selectText(item.join('')); // TODO: As per https://github.com/tmpvar/jsdom/issues/321 there is no getSelection in jsdom, yet. // Once there is one, uncomment the line below to actually check the result. //result *= (contents[i] || contents[0]) === window.getSelection().toString(); }); clean(); - return result; + return Boolean(result); + } + ); + }); + + describe('setElementText', function () { + jsc.property( + 'replaces the content of an element', + jsc.nearray(jsc.nearray(jsc.elements(alnumString))), + 'nearray string', + 'string', + function (ids, contents, replacingContent) { + var html = '', + result = true; + ids.forEach(function(item, i) { + html += '
' + (contents[i] || contents[0]) + '
'; + }); + var clean = jsdom(html); + ids.forEach(function(item, i) { + var id = item.join(''), + element = $(document.getElementById(id)); + $.PrivateBin.helper.setElementText(element, replacingContent); + result *= replacingContent === $(document.getElementById(id)).text(); + }); + clean(); + return Boolean(result); } ); });