diff --git a/js/common.js b/js/common.js
index 9f8a9c50..849e6535 100644
--- a/js/common.js
+++ b/js/common.js
@@ -4,7 +4,36 @@
global.assert = require('assert');
global.jsc = require('jsverify');
global.jsdom = require('jsdom-global');
+// initial DOM environment created by jsdom-global
global.cleanup = global.jsdom();
+// wrap cleanup so that calling it recreates a fresh jsdom environment
+const _origCleanup = global.cleanup;
+global.cleanup = function () {
+ // remove previous environment
+ _origCleanup();
+ // create a new one and return its cleanup function for chaining if needed
+ global.cleanup = global.jsdom();
+
+ // after a new DOM is created we need to reinitialize jQuery so it binds to
+ // the fresh window/document. We simply reload the module and reset the
+ // globals. This mirrors what common.js does initially.
+ try {
+ delete require.cache[require.resolve('./jquery-3.7.1')];
+ } catch (e) {
+ // ignore
+ }
+ global.$ = global.jQuery = require('./jquery-3.7.1');
+
+ // also re-export the PrivateBin namespace if available
+ if (typeof window !== 'undefined' && window.PrivateBin) {
+ global.PrivateBin = window.PrivateBin;
+ if (global.$) {
+ global.$.PrivateBin = window.PrivateBin;
+ }
+ }
+
+ return global.cleanup;
+};
global.fs = require('fs');
global.WebCrypto = require('@peculiar/webcrypto').Crypto;
@@ -20,6 +49,15 @@ global.baseX = require('./base-x-5.0.1').baseX;
global.Legacy = require('./legacy').Legacy;
require('./privatebin');
+// provide global access to the namespace so tests can reference it directly
+if (typeof window !== 'undefined' && window.PrivateBin) {
+ global.PrivateBin = window.PrivateBin;
+ // keep the old jQuery alias around just in case some tests still use it
+ if (global.$) {
+ global.$.PrivateBin = window.PrivateBin;
+ }
+}
+
// internal variables
var a2zString = ['a','b','c','d','e','f','g','h','i','j','k','l','m',
'n','o','p','q','r','s','t','u','v','w','x','y','z'],
diff --git a/js/privatebin.js b/js/privatebin.js
index c017ad40..816d2f31 100644
--- a/js/privatebin.js
+++ b/js/privatebin.js
@@ -2654,14 +2654,16 @@ window.PrivateBin = (function () {
excludeTrailingPunctuationFromURLs: true
});
// let showdown convert the HTML and sanitize HTML *afterwards*!
- plainText.innerHTML = DOMPurify.sanitize(
- converter.makeHtml(text),
- purifyHtmlConfig
- );
- // add table classes from bootstrap css
- plainText.querySelectorAll('table').forEach(t => {
- t.classList.add('table-condensed', 'table-bordered');
- });
+ if (plainText) {
+ plainText.innerHTML = DOMPurify.sanitize(
+ converter.makeHtml(text),
+ purifyHtmlConfig
+ );
+ // add table classes from bootstrap css
+ plainText.querySelectorAll('table').forEach(t => {
+ t.classList.add('table-condensed', 'table-bordered');
+ });
+ }
} else {
if (format === 'syntaxhighlighting') {
// yes, this is really needed to initialize the environment
@@ -2669,17 +2671,23 @@ window.PrivateBin = (function () {
prettyPrint();
}
- prettyPrintEl.innerHTML = prettyPrintOne(
- Helper.htmlEntities(text), null, true
- );
+ if (prettyPrintEl) {
+ prettyPrintEl.innerHTML = prettyPrintOne(
+ Helper.htmlEntities(text), null, true
+ );
+ }
} else {
// = 'plaintext'
- prettyPrintEl.textContent = text;
+ if (prettyPrintEl) {
+ prettyPrintEl.textContent = text;
+ }
+ }
+ if (prettyPrintEl) {
+ Helper.urls2links(prettyPrintEl);
+ prettyPrintEl.style.whiteSpace = 'pre-wrap';
+ prettyPrintEl.style.wordBreak = 'normal';
+ prettyPrintEl.classList.remove('prettyprint');
}
- Helper.urls2links(prettyPrintEl);
- prettyPrintEl.style.whiteSpace = 'pre-wrap';
- prettyPrintEl.style.wordBreak = 'normal';
- prettyPrintEl.classList.remove('prettyprint');
}
}
@@ -2755,7 +2763,7 @@ window.PrivateBin = (function () {
* @return {bool}
*/
me.isPrettyPrinted = function () {
- return $prettyPrint.hasClass('prettyprinted');
+ return prettyPrintEl ? prettyPrintEl.classList.contains('prettyprinted') : false;
};
/**
diff --git a/js/test/Alert.js b/js/test/Alert.js
index 92464ed1..92fa1360 100644
--- a/js/test/Alert.js
+++ b/js/test/Alert.js
@@ -14,8 +14,8 @@ describe('Alert', function () {
$('body').html(
'
'
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showStatus(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showStatus(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -35,8 +35,8 @@ describe('Alert', function () {
'alert alert-info hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showStatus(message);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showStatus(message);
const result = $('body').html();
return expected === result;
}
@@ -58,8 +58,8 @@ describe('Alert', function () {
'alert alert-info hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showStatus(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showStatus(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -78,8 +78,8 @@ describe('Alert', function () {
$('body').html(
'
'
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showWarning(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showWarning(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -100,8 +100,8 @@ describe('Alert', function () {
'alert alert-danger hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showWarning(message);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showWarning(message);
const result = $('body').html();
return expected === result;
}
@@ -123,8 +123,8 @@ describe('Alert', function () {
'alert alert-danger hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showWarning(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showWarning(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -143,8 +143,8 @@ describe('Alert', function () {
$('body').html(
'
'
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showError(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showError(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -165,8 +165,8 @@ describe('Alert', function () {
'alert alert-danger hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showError(message);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showError(message);
const result = $('body').html();
return expected === result;
}
@@ -188,8 +188,8 @@ describe('Alert', function () {
'alert alert-danger hidden"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showError(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showError(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -209,8 +209,8 @@ describe('Alert', function () {
$('body').html(
'
'
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
const result = $('body').html();
return expected === result;
}
@@ -233,8 +233,8 @@ describe('Alert', function () {
'alert alert-info"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
const result = $('body').html();
return expected === result;
}
@@ -257,8 +257,8 @@ describe('Alert', function () {
$('body').html(
'' + defaultMessage + '
'
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showLoading(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showLoading(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -285,8 +285,8 @@ describe('Alert', function () {
'glyphicon-time" aria-hidden="true"> ' +
defaultMessage + ''
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.showLoading(message, icon);
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.showLoading(message, icon);
const result = $('body').html();
return expected === result;
}
@@ -304,8 +304,8 @@ describe('Alert', function () {
'Loading…'
);
$('body').addClass('loading');
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.hideLoading();
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.hideLoading();
assert.ok(!$('body').hasClass('loading'));
assert.ok($('#loadingindicator').hasClass('hidden'));
}
@@ -324,8 +324,8 @@ describe('Alert', function () {
'alert alert-danger"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.hideMessages();
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.hideMessages();
assert.ok($('#status').hasClass('hidden'));
assert.ok($('#errormessage').hasClass('hidden'));
}
@@ -342,10 +342,10 @@ describe('Alert', function () {
let handlerCalled = false,
defaultMessage = 'Loading…',
functions = [
- $.PrivateBin.Alert.showStatus,
- $.PrivateBin.Alert.showError,
- $.PrivateBin.Alert.showRemaining,
- $.PrivateBin.Alert.showLoading
+ PrivateBin.Alert.showStatus,
+ PrivateBin.Alert.showError,
+ PrivateBin.Alert.showRemaining,
+ PrivateBin.Alert.showLoading
];
if (message.length === 0) {
message = defaultMessage;
@@ -365,13 +365,13 @@ describe('Alert', function () {
'alert alert-danger"> '
);
- $.PrivateBin.Alert.init();
- $.PrivateBin.Alert.setCustomHandler(function(id, $element) {
+ PrivateBin.Alert.init();
+ PrivateBin.Alert.setCustomHandler(function(id, $element) {
handlerCalled = true;
return jsc.random(0, 1) ? true : $element;
});
functions[trigger](message);
- $.PrivateBin.Alert.setCustomHandler(null);
+ PrivateBin.Alert.setCustomHandler(null);
return handlerCalled;
}
);
diff --git a/js/test/AttachmentViewer.js b/js/test/AttachmentViewer.js
index 826428a1..4ee5df85 100644
--- a/js/test/AttachmentViewer.js
+++ b/js/test/AttachmentViewer.js
@@ -51,10 +51,10 @@ describe('AttachmentViewer', function () {
}}
);
}
- $.PrivateBin.AttachmentViewer.init();
- $.PrivateBin.Model.init();
+ PrivateBin.AttachmentViewer.init();
+ PrivateBin.Model.init();
results.push(
- !$.PrivateBin.AttachmentViewer.hasAttachment() &&
+ !PrivateBin.AttachmentViewer.hasAttachment() &&
$('#attachment').hasClass('hidden') &&
$('#attachment').children().length === 0 &&
$('#attachmenttemplate').hasClass('hidden') &&
@@ -62,49 +62,49 @@ describe('AttachmentViewer', function () {
);
global.atob = common.atob;
if (filename.length) {
- $.PrivateBin.AttachmentViewer.setAttachment(data, filename);
+ PrivateBin.AttachmentViewer.setAttachment(data, filename);
} else {
- $.PrivateBin.AttachmentViewer.setAttachment(data);
+ PrivateBin.AttachmentViewer.setAttachment(data);
}
// // beyond this point we will get the blob URL instead of the data
data = window.URL.createObjectURL(data);
- const attachment = $.PrivateBin.AttachmentViewer.getAttachments();
+ const attachment = PrivateBin.AttachmentViewer.getAttachments();
results.push(
- $.PrivateBin.AttachmentViewer.hasAttachment() &&
+ PrivateBin.AttachmentViewer.hasAttachment() &&
$('#attachment').hasClass('hidden') &&
$('#attachment').children().length > 0 &&
$('#attachmentPreview').hasClass('hidden') &&
attachment[0][0] === data &&
attachment[0][1] === filename
);
- $.PrivateBin.AttachmentViewer.showAttachment();
+ PrivateBin.AttachmentViewer.showAttachment();
results.push(
!$('#attachment').hasClass('hidden') &&
$('#attachment').children().length > 0 &&
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
);
- $.PrivateBin.AttachmentViewer.hideAttachment();
+ PrivateBin.AttachmentViewer.hideAttachment();
results.push(
$('#attachment').hasClass('hidden') &&
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
);
if (previewSupported) {
- $.PrivateBin.AttachmentViewer.hideAttachmentPreview();
+ PrivateBin.AttachmentViewer.hideAttachmentPreview();
results.push($('#attachmentPreview').hasClass('hidden'));
}
- $.PrivateBin.AttachmentViewer.showAttachment();
+ PrivateBin.AttachmentViewer.showAttachment();
results.push(
!$('#attachment').hasClass('hidden') &&
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
);
let element = $('');
- $.PrivateBin.AttachmentViewer.moveAttachmentTo(element[0], attachment[0], prefix + '%s' + postfix);
+ PrivateBin.AttachmentViewer.moveAttachmentTo(element[0], attachment[0], prefix + '%s' + postfix);
// messageIDs with links get a relaxed treatment
if (prefix.indexOf('
').text((prefix + filename + postfix)).text();
} else {
result = DOMPurify.sanitize(
- prefix + $.PrivateBin.Helper.htmlEntities(filename) + postfix, {
+ prefix + PrivateBin.Helper.htmlEntities(filename) + postfix, {
ALLOWED_TAGS: ['a', 'i', 'span'],
ALLOWED_ATTR: ['href', 'id']
}
@@ -119,7 +119,7 @@ describe('AttachmentViewer', function () {
} else {
results.push(element.find('a')[0].href === data);
}
- $.PrivateBin.AttachmentViewer.removeAttachment();
+ PrivateBin.AttachmentViewer.removeAttachment();
results.push(
$('#attachment').hasClass('hidden') &&
$('#attachment').children().length === 0 &&
@@ -154,8 +154,8 @@ describe('AttachmentViewer', function () {
}}
);
}
- $.PrivateBin.AttachmentViewer.init();
- $.PrivateBin.Model.init();
+ PrivateBin.AttachmentViewer.init();
+ PrivateBin.Model.init();
global.atob = common.atob;
const maliciousFileNames = [
@@ -163,7 +163,7 @@ describe('AttachmentViewer', function () {
'"> .txt'
];
for (const filename of maliciousFileNames) {
- $.PrivateBin.AttachmentViewer.setAttachment('data:;base64,', filename);
+ PrivateBin.AttachmentViewer.setAttachment('data:;base64,', filename);
assert.ok(!$('body').html().includes(filename));
}
clean();
diff --git a/js/test/CopyToClipboard.js b/js/test/CopyToClipboard.js
index 0abfd53a..692b700c 100644
--- a/js/test/CopyToClipboard.js
+++ b/js/test/CopyToClipboard.js
@@ -21,12 +21,12 @@ describe('CopyToClipboard', function() {
'
'
);
- $.PrivateBin.PasteViewer.init();
- $.PrivateBin.PasteViewer.setFormat(format);
- $.PrivateBin.PasteViewer.setText(text);
- $.PrivateBin.PasteViewer.run();
+ PrivateBin.PasteViewer.init();
+ PrivateBin.PasteViewer.setFormat(format);
+ PrivateBin.PasteViewer.setText(text);
+ PrivateBin.PasteViewer.run();
- $.PrivateBin.CopyToClipboard.init();
+ PrivateBin.CopyToClipboard.init();
$('#prettyMessageCopyBtn').trigger('click');
@@ -58,12 +58,12 @@ describe('CopyToClipboard', function() {
'
'
);
- $.PrivateBin.PasteViewer.init();
- $.PrivateBin.PasteViewer.setFormat(format);
- $.PrivateBin.PasteViewer.setText(text);
- $.PrivateBin.PasteViewer.run();
+ PrivateBin.PasteViewer.init();
+ PrivateBin.PasteViewer.setFormat(format);
+ PrivateBin.PasteViewer.setText(text);
+ PrivateBin.PasteViewer.run();
- $.PrivateBin.CopyToClipboard.init();
+ PrivateBin.CopyToClipboard.init();
$('body').trigger('copy');
@@ -85,8 +85,8 @@ describe('CopyToClipboard', function() {
$('body').html(' ');
- $.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.setUrl(text);
+ PrivateBin.CopyToClipboard.init();
+ PrivateBin.CopyToClipboard.setUrl(text);
$('#copyLink').trigger('click');
@@ -107,8 +107,8 @@ describe('CopyToClipboard', function() {
$('body').html(' ');
- $.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
+ PrivateBin.CopyToClipboard.init();
+ PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
const keyboardShortcutHint = $('#copyShortcutHintText').text();
@@ -125,8 +125,8 @@ describe('CopyToClipboard', function() {
$('body').html('' + text + ' ');
- $.PrivateBin.CopyToClipboard.init();
- $.PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
+ PrivateBin.CopyToClipboard.init();
+ PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
const keyboardShortcutHint = $('#copyShortcutHintText').text();
diff --git a/js/test/CryptTool.js b/js/test/CryptTool.js
index a75046fb..4db3ef90 100644
--- a/js/test/CryptTool.js
+++ b/js/test/CryptTool.js
@@ -17,7 +17,7 @@ describe('CryptTool', function () {
async function (key, password, message) {
const clean = jsdom();
// ensure zlib is getting loaded
- $.PrivateBin.Controller.initZ();
+ PrivateBin.Controller.initZ();
Object.defineProperty(window, 'crypto', {
value: new WebCrypto(),
writeable: false
@@ -25,10 +25,10 @@ describe('CryptTool', function () {
global.atob = common.atob;
global.btoa = common.btoa;
message = message.trim();
- const cipherMessage = await $.PrivateBin.CryptTool.cipher(
+ const cipherMessage = await PrivateBin.CryptTool.cipher(
key, password, message, []
),
- plaintext = await $.PrivateBin.CryptTool.decipher(
+ plaintext = await PrivateBin.CryptTool.decipher(
key, password, cipherMessage
);
clean();
@@ -48,13 +48,13 @@ describe('CryptTool', function () {
writeable: false
});
// ensure zlib is getting loaded
- $.PrivateBin.Controller.initZ();
+ PrivateBin.Controller.initZ();
global.atob = common.atob;
global.btoa = common.btoa;
- const cipherMessage = await $.PrivateBin.CryptTool.cipher(
+ const cipherMessage = await PrivateBin.CryptTool.cipher(
'foo', 'bar', message, []
),
- plaintext = await $.PrivateBin.CryptTool.decipher(
+ plaintext = await PrivateBin.CryptTool.decipher(
'foo', 'bar', cipherMessage
);
clean();
@@ -93,15 +93,15 @@ conseq_or_bottom inv (interp (nth_iterate sBody n) (MemElem mem))
`;
const clean = jsdom();
// ensure zlib is getting loaded
- $.PrivateBin.Controller.initZ();
+ PrivateBin.Controller.initZ();
Object.defineProperty(window, 'crypto', {
value: new WebCrypto(),
writeable: false
});
- const cipherMessage = await $.PrivateBin.CryptTool.cipher(
+ const cipherMessage = await PrivateBin.CryptTool.cipher(
key, password, message, []
),
- plaintext = await $.PrivateBin.CryptTool.decipher(
+ plaintext = await PrivateBin.CryptTool.decipher(
key, password, cipherMessage
);
clean();
@@ -128,7 +128,7 @@ conseq_or_bottom inv (interp (nth_iterate sBody n) (MemElem mem))
value: new WebCrypto(),
writeable: false
});
- const key = $.PrivateBin.CryptTool.getSymmetricKey(),
+ const key = PrivateBin.CryptTool.getSymmetricKey(),
result = (key !== '' && keys.indexOf(key) === -1);
keys.push(key);
clean();
diff --git a/js/test/DiscussionViewer.js b/js/test/DiscussionViewer.js
index f38596cd..0203ddd5 100644
--- a/js/test/DiscussionViewer.js
+++ b/js/test/DiscussionViewer.js
@@ -48,24 +48,24 @@ describe('DiscussionViewer', function () {
'aria-hidden="true"> Post comment '
);
- $.PrivateBin.Model.init();
- $.PrivateBin.DiscussionViewer.init();
+ PrivateBin.Model.init();
+ PrivateBin.DiscussionViewer.init();
results.push(
!$('#discussion').hasClass('hidden')
);
- $.PrivateBin.DiscussionViewer.prepareNewDiscussion();
+ PrivateBin.DiscussionViewer.prepareNewDiscussion();
results.push(
$('#discussion').hasClass('hidden')
);
comments.forEach(function (comment) {
comment.id = comment.idArray.join('');
comment.parentid = comment.parentidArray.join('');
- $.PrivateBin.DiscussionViewer.addComment($.PrivateBin.Helper.CommentFactory(comment), comment.data, comment.meta.nickname);
+ PrivateBin.DiscussionViewer.addComment(PrivateBin.Helper.CommentFactory(comment), comment.data, comment.meta.nickname);
});
results.push(
$('#discussion').hasClass('hidden')
);
- $.PrivateBin.DiscussionViewer.finishDiscussion();
+ PrivateBin.DiscussionViewer.finishDiscussion();
results.push(
!$('#discussion').hasClass('hidden') &&
comments.length + 1 >= $('#commentcontainer').children().length
@@ -74,7 +74,7 @@ describe('DiscussionViewer', function () {
if (commentKey >= comments.length) {
commentKey = commentKey % comments.length;
}
- $.PrivateBin.DiscussionViewer.highlightComment(comments[commentKey].id, fadeOut);
+ PrivateBin.DiscussionViewer.highlightComment(comments[commentKey].id, fadeOut);
results.push(
$('#comment_' + comments[commentKey].id).hasClass('highlight')
);
@@ -85,12 +85,12 @@ describe('DiscussionViewer', function () {
);
$('#reply #nickname').val(nickname);
$('#reply #replymessage').val(message);
- $.PrivateBin.DiscussionViewer.getReplyCommentId();
+ PrivateBin.DiscussionViewer.getReplyCommentId();
results.push(
- $.PrivateBin.DiscussionViewer.getReplyNickname() === $('#reply #nickname').val() &&
- $.PrivateBin.DiscussionViewer.getReplyMessage() === $('#reply #replymessage').val()
+ PrivateBin.DiscussionViewer.getReplyNickname() === $('#reply #nickname').val() &&
+ PrivateBin.DiscussionViewer.getReplyMessage() === $('#reply #replymessage').val()
);
- var notificationResult = $.PrivateBin.DiscussionViewer.handleNotification(alertType === 'other' ? alert : alertType);
+ var notificationResult = PrivateBin.DiscussionViewer.handleNotification(alertType === 'other' ? alert : alertType);
if (alertType === 'loading') {
results.push(notificationResult === false);
} else {
diff --git a/js/test/Editor.js b/js/test/Editor.js
index 209f8028..b7e5d1e5 100644
--- a/js/test/Editor.js
+++ b/js/test/Editor.js
@@ -23,43 +23,43 @@ describe('Editor', function () {
'id="message" name="message" cols="80" rows="25" ' +
'class="form-control hidden">'
);
- $.PrivateBin.Editor.init();
+ PrivateBin.Editor.init();
results.push(
$('#editorTabs').hasClass('hidden') &&
$('#message').hasClass('hidden')
);
- $.PrivateBin.Editor.show();
+ PrivateBin.Editor.show();
results.push(
!$('#editorTabs').hasClass('hidden') &&
!$('#message').hasClass('hidden')
);
- $.PrivateBin.Editor.hide();
+ PrivateBin.Editor.hide();
results.push(
$('#editorTabs').hasClass('hidden') &&
$('#message').hasClass('hidden')
);
- $.PrivateBin.Editor.show();
- $.PrivateBin.Editor.focusInput();
+ PrivateBin.Editor.show();
+ PrivateBin.Editor.focusInput();
results.push(
- $.PrivateBin.Editor.getText().length === 0
+ PrivateBin.Editor.getText().length === 0
);
- $.PrivateBin.Editor.setText(text);
+ PrivateBin.Editor.setText(text);
results.push(
- $.PrivateBin.Editor.getText() === $('#message').val()
+ PrivateBin.Editor.getText() === $('#message').val()
);
- $.PrivateBin.Editor.setText();
+ PrivateBin.Editor.setText();
results.push(
- !$.PrivateBin.Editor.isPreview() &&
+ !PrivateBin.Editor.isPreview() &&
!$('#message').hasClass('hidden')
);
$('#messagepreview').trigger('click');
results.push(
- $.PrivateBin.Editor.isPreview() &&
+ PrivateBin.Editor.isPreview() &&
$('#message').hasClass('hidden')
);
$('#messageedit').trigger('click');
results.push(
- !$.PrivateBin.Editor.isPreview() &&
+ !PrivateBin.Editor.isPreview() &&
!$('#message').hasClass('hidden')
);
clean();
diff --git a/js/test/Helper.js b/js/test/Helper.js
index 022b7a09..adbbb586 100644
--- a/js/test/Helper.js
+++ b/js/test/Helper.js
@@ -4,42 +4,42 @@ var common = require('../common');
describe('Helper', function () {
describe('secondsToHuman', function () {
jsc.property('returns an array with a number and a word', 'integer', function (number) {
- var result = $.PrivateBin.Helper.secondsToHuman(number);
+ var result = PrivateBin.Helper.secondsToHuman(number);
return Array.isArray(result) &&
result.length === 2 &&
result[0] === parseInt(result[0], 10) &&
typeof result[1] === 'string';
});
jsc.property('returns seconds on the first array position', 'integer 59', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[0] === number;
+ return PrivateBin.Helper.secondsToHuman(number)[0] === number;
});
jsc.property('returns seconds on the second array position', 'integer 59', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'second';
+ return PrivateBin.Helper.secondsToHuman(number)[1] === 'second';
});
jsc.property('returns minutes on the first array position', 'integer 60 3599', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / 60);
+ return PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / 60);
});
jsc.property('returns minutes on the second array position', 'integer 60 3599', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'minute';
+ return PrivateBin.Helper.secondsToHuman(number)[1] === 'minute';
});
jsc.property('returns hours on the first array position', 'integer 3600 86399', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
+ return PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60));
});
jsc.property('returns hours on the second array position', 'integer 3600 86399', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'hour';
+ return PrivateBin.Helper.secondsToHuman(number)[1] === 'hour';
});
jsc.property('returns days on the first array position', 'integer 86400 5184000', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
+ return PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24));
});
jsc.property('returns days on the second array position', 'integer 86400 5184000', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'day';
+ return PrivateBin.Helper.secondsToHuman(number)[1] === 'day';
});
// max safe integer as per http://ecma262-5.com/ELS5_HTML.htm#Section_8.5
jsc.property('returns months on the first array position', 'integer 5184000 9007199254740991', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
+ return PrivateBin.Helper.secondsToHuman(number)[0] === Math.floor(number / (60 * 60 * 24 * 30));
});
jsc.property('returns months on the second array position', 'integer 5184000 9007199254740991', function (number) {
- return $.PrivateBin.Helper.secondsToHuman(number)[1] === 'month';
+ return PrivateBin.Helper.secondsToHuman(number)[1] === 'month';
});
});
@@ -56,13 +56,13 @@ describe('Helper', function () {
result = true,
clean = jsdom(html);
ids.forEach(function(item, i) {
- html += '' + $.PrivateBin.Helper.htmlEntities(contents[i] || contents[0]) + '
';
+ html += '' + PrivateBin.Helper.htmlEntities(contents[i] || contents[0]) + '
';
});
// TODO: As per https://github.com/tmpvar/jsdom/issues/321 there is no getSelection in jsdom, yet.
// Once there is one, uncomment the block below to actually check the result.
/*
ids.forEach(function(item, i) {
- $.PrivateBin.Helper.selectText(item.join(''));
+ PrivateBin.Helper.selectText(item.join(''));
result *= (contents[i] || contents[0]) === window.getSelection().toString();
});
*/
@@ -88,7 +88,7 @@ describe('Helper', function () {
$('body').html('
');
let e = $('#foo');
e.text(content);
- $.PrivateBin.Helper.urls2links(e[0]);
+ PrivateBin.Helper.urls2links(e[0]);
let result = e.text();
clean();
return content === result;
@@ -121,7 +121,7 @@ describe('Helper', function () {
postfix = '';
}
e.text(prefix + urlString + postfix);
- $.PrivateBin.Helper.urls2links(e[0]);
+ PrivateBin.Helper.urls2links(e[0]);
let result = e.html();
clean();
urlString = $('
').text(urlString).html();
@@ -144,7 +144,7 @@ describe('Helper', function () {
$('body').html('
');
let e = $('#foo');
e.text(prefix + url + postfix);
- $.PrivateBin.Helper.urls2links(e[0]);
+ PrivateBin.Helper.urls2links(e[0]);
let result = e.html();
clean();
url = $('
').text(url).html();
@@ -165,7 +165,7 @@ describe('Helper', function () {
postfix = postfix.replace(/%(s|d)/g, '%%');
var result = prefix + params[0] + postfix;
params.unshift(prefix + '%s' + postfix);
- return result === $.PrivateBin.Helper.sprintf.apply(this, params);
+ return result === PrivateBin.Helper.sprintf.apply(this, params);
}
);
jsc.property(
@@ -178,7 +178,7 @@ describe('Helper', function () {
postfix = postfix.replace(/%(s|d)/g, '%%');
var result = prefix + params[0] + postfix;
params.unshift(prefix + '%d' + postfix);
- return result === $.PrivateBin.Helper.sprintf.apply(this, params);
+ return result === PrivateBin.Helper.sprintf.apply(this, params);
}
);
jsc.property(
@@ -191,7 +191,7 @@ describe('Helper', function () {
postfix = postfix.replace(/%(s|d)/g, '%%');
var result = prefix + '0' + postfix;
params.unshift(prefix + '%d' + postfix);
- return result === $.PrivateBin.Helper.sprintf.apply(this, params);
+ return result === PrivateBin.Helper.sprintf.apply(this, params);
}
);
jsc.property(
@@ -207,7 +207,7 @@ describe('Helper', function () {
postfix = postfix.replace(/%(s|d)/g, '');
var params = [prefix + '%d' + middle + '%s' + postfix, uint, string],
result = prefix + uint + middle + string + postfix;
- return result === $.PrivateBin.Helper.sprintf.apply(this, params);
+ return result === PrivateBin.Helper.sprintf.apply(this, params);
}
);
jsc.property(
@@ -223,7 +223,7 @@ describe('Helper', function () {
postfix = postfix.replace(/%(s|d)/g, '');
var params = [prefix + '%s' + middle + '%d' + postfix, string, uint],
result = prefix + string + middle + uint + postfix;
- return result === $.PrivateBin.Helper.sprintf.apply(this, params);
+ return result === PrivateBin.Helper.sprintf.apply(this, params);
}
);
});
@@ -252,8 +252,8 @@ describe('Helper', function () {
selectedValue = value;
}
});
- const result = $.PrivateBin.Helper.getCookie(selectedKey);
- $.PrivateBin.Helper.reset();
+ const result = PrivateBin.Helper.getCookie(selectedKey);
+ PrivateBin.Helper.reset();
clean();
return result === selectedValue;
}
@@ -271,10 +271,10 @@ describe('Helper', function () {
const fullUrl = common.urlToString(url);
delete(url.query);
delete(url.fragment);
- $.PrivateBin.Helper.reset();
+ PrivateBin.Helper.reset();
const expected = common.urlToString(url),
clean = jsdom('', {url: fullUrl}),
- result = $.PrivateBin.Helper.baseUri();
+ result = PrivateBin.Helper.baseUri();
clean();
return expected === result;
}
@@ -290,7 +290,7 @@ describe('Helper', function () {
'removes all HTML entities from any given string',
'string',
function (string) {
- var result = $.PrivateBin.Helper.htmlEntities(string);
+ var result = PrivateBin.Helper.htmlEntities(string);
return !(/[<>]/.test(result)) && !(string.indexOf('&') > -1 && !(/&/.test(result)));
}
);
@@ -298,43 +298,43 @@ describe('Helper', function () {
describe('formatBytes', function () {
jsc.property('returns 0 B for 0 bytes', function () {
- return $.PrivateBin.Helper.formatBytes(0) === '0 B';
+ return PrivateBin.Helper.formatBytes(0) === '0 B';
});
jsc.property('formats bytes < 1000 as B', function () {
- return $.PrivateBin.Helper.formatBytes(500) === '500 B';
+ return PrivateBin.Helper.formatBytes(500) === '500 B';
});
jsc.property('formats kilobytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(1500) === '1.5 kB';
+ return PrivateBin.Helper.formatBytes(1500) === '1.5 kB';
});
jsc.property('formats megabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '2 MB';
+ return PrivateBin.Helper.formatBytes(2 * 1000 * 1000) === '2 MB';
});
jsc.property('formats gigabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB';
+ return PrivateBin.Helper.formatBytes(3.45 * 1000 * 1000 * 1000) === '3.45 GB';
});
jsc.property('formats terabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(1.75 * 1000 ** 4) === '1.75 TB';
+ return PrivateBin.Helper.formatBytes(1.75 * 1000 ** 4) === '1.75 TB';
});
jsc.property('formats petabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(1.5 * 1000 ** 5) === '1.5 PB';
+ return PrivateBin.Helper.formatBytes(1.5 * 1000 ** 5) === '1.5 PB';
});
jsc.property('formats exabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(1.2345 * 1000 ** 6).startsWith('1.23 EB');
+ return PrivateBin.Helper.formatBytes(1.2345 * 1000 ** 6).startsWith('1.23 EB');
});
jsc.property('formats yottabytes correctly', function () {
- return $.PrivateBin.Helper.formatBytes(1.23 * 1000 ** 8).startsWith('1.23 YB');
+ return PrivateBin.Helper.formatBytes(1.23 * 1000 ** 8).startsWith('1.23 YB');
});
jsc.property('rounds to two decimal places', function () {
- return $.PrivateBin.Helper.formatBytes(1234567) === '1.23 MB';
+ return PrivateBin.Helper.formatBytes(1234567) === '1.23 MB';
});
});
@@ -342,12 +342,12 @@ describe('Helper', function () {
describe('isBootstrap5', function () {
jsc.property('Bootstrap 5 has been detected', function () {
global.bootstrap = {};
- return $.PrivateBin.Helper.isBootstrap5() === true;
+ return PrivateBin.Helper.isBootstrap5() === true;
});
jsc.property('Bootstrap 5 has not been detected', function () {
delete global.bootstrap;
- return $.PrivateBin.Helper.isBootstrap5() === false;
+ return PrivateBin.Helper.isBootstrap5() === false;
});
});
});
diff --git a/js/test/I18n.js b/js/test/I18n.js
index 0def37ae..e8921445 100644
--- a/js/test/I18n.js
+++ b/js/test/I18n.js
@@ -5,7 +5,7 @@ describe('I18n', function () {
describe('translate', function () {
this.timeout(30000);
before(function () {
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
});
jsc.property(
@@ -15,26 +15,26 @@ describe('I18n', function () {
messageId = messageId.replace(/%(s|d)/g, '%%');
var plurals = [messageId, messageId + 's'],
fake = [messageId],
- result = $.PrivateBin.I18n.translate(messageId);
- $.PrivateBin.I18n.reset();
+ result = PrivateBin.I18n.translate(messageId);
+ PrivateBin.I18n.reset();
- var alias = $.PrivateBin.I18n._(messageId);
- $.PrivateBin.I18n.reset();
+ var alias = PrivateBin.I18n._(messageId);
+ PrivateBin.I18n.reset();
- var pluralResult = $.PrivateBin.I18n.translate(plurals);
- $.PrivateBin.I18n.reset();
+ var pluralResult = PrivateBin.I18n.translate(plurals);
+ PrivateBin.I18n.reset();
- var pluralAlias = $.PrivateBin.I18n._(plurals);
- $.PrivateBin.I18n.reset();
+ var pluralAlias = PrivateBin.I18n._(plurals);
+ PrivateBin.I18n.reset();
- var fakeResult = $.PrivateBin.I18n.translate(fake);
- $.PrivateBin.I18n.reset();
+ var fakeResult = PrivateBin.I18n.translate(fake);
+ PrivateBin.I18n.reset();
- var fakeAlias = $.PrivateBin.I18n._(fake);
- $.PrivateBin.I18n.reset();
+ var fakeAlias = PrivateBin.I18n._(fake);
+ PrivateBin.I18n.reset();
if (messageId.indexOf(' ' + postfix);
- const result = $.PrivateBin.I18n.translate.apply(this, params);
- $.PrivateBin.I18n.reset();
- const alias = $.PrivateBin.I18n._.apply(this, params);
- $.PrivateBin.I18n.reset();
+ const result = PrivateBin.I18n.translate.apply(this, params);
+ PrivateBin.I18n.reset();
+ const alias = PrivateBin.I18n._.apply(this, params);
+ PrivateBin.I18n.reset();
return translation === result && translation === alias;
}
);
@@ -105,16 +105,16 @@ describe('I18n', function () {
let clean = jsdom();
$('body').html('
');
args.unshift($('#i18n'));
- $.PrivateBin.I18n.translate.apply(this, args);
+ PrivateBin.I18n.translate.apply(this, args);
const result = $('#i18n').text();
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
clean();
clean = jsdom();
$('body').html('
');
args[0] = $('#i18n');
- $.PrivateBin.I18n._.apply(this, args);
+ PrivateBin.I18n._.apply(this, args);
const alias = $('#i18n').text();
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
clean();
return translation === result && translation === alias;
}
@@ -140,16 +140,16 @@ describe('I18n', function () {
let clean = jsdom();
$('body').html('
');
args.unshift($('#i18n'));
- $.PrivateBin.I18n.translate.apply(this, args);
+ PrivateBin.I18n.translate.apply(this, args);
const result = $('#i18n').html();
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
clean();
clean = jsdom();
$('body').html('
');
args[0] = $('#i18n');
- $.PrivateBin.I18n._.apply(this, args);
+ PrivateBin.I18n._.apply(this, args);
const alias = $('#i18n').html();
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
clean();
return translation === result && translation === alias;
}
@@ -158,7 +158,7 @@ describe('I18n', function () {
describe('getPluralForm', function () {
before(function () {
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
});
jsc.property(
@@ -166,8 +166,8 @@ describe('I18n', function () {
common.jscSupportedLanguages(),
'integer',
function(language, n) {
- $.PrivateBin.I18n.reset(language);
- var result = $.PrivateBin.I18n.getPluralForm(n);
+ PrivateBin.I18n.reset(language);
+ var result = PrivateBin.I18n.getPluralForm(n);
// arabic seems to have the highest plural count with 6 forms
return result >= 0 && result <= 5;
}
@@ -179,7 +179,7 @@ describe('I18n', function () {
describe('loadTranslations', function () {
this.timeout(30000);
before(function () {
- $.PrivateBin.I18n.reset();
+ PrivateBin.I18n.reset();
});
jsc.property(
@@ -188,17 +188,17 @@ describe('I18n', function () {
function(language) {
// cleanup
var clean = jsdom('', {cookie: ['lang=en']});
- $.PrivateBin.I18n.reset('en');
- $.PrivateBin.I18n.loadTranslations();
+ PrivateBin.I18n.reset('en');
+ PrivateBin.I18n.loadTranslations();
clean();
// mock
clean = jsdom('', {cookie: ['lang=' + language]});
// eslint-disable-next-line global-require
- $.PrivateBin.I18n.reset(language, require('../../i18n/' + language + '.json'));
- var loadedLang = $.PrivateBin.I18n.getLanguage(),
- result = $.PrivateBin.I18n.translate('Never'),
- alias = $.PrivateBin.I18n._('Never');
+ PrivateBin.I18n.reset(language, require('../../i18n/' + language + '.json'));
+ var loadedLang = PrivateBin.I18n.getLanguage(),
+ result = PrivateBin.I18n.translate('Never'),
+ alias = PrivateBin.I18n._('Never');
clean();
return language === loadedLang && result === alias;
}
@@ -218,10 +218,10 @@ describe('I18n', function () {
});
});
- $.PrivateBin.I18n.reset('en');
- $.PrivateBin.I18n.loadTranslations();
- var result = $.PrivateBin.I18n.translate('Never'),
- alias = $.PrivateBin.I18n._('Never');
+ PrivateBin.I18n.reset('en');
+ PrivateBin.I18n.loadTranslations();
+ var result = PrivateBin.I18n.translate('Never'),
+ alias = PrivateBin.I18n._('Never');
clean();
return 'Never' === result && 'Never' === alias;
diff --git a/js/test/Model.js b/js/test/Model.js
index 417c5e5b..697ea9cb 100644
--- a/js/test/Model.js
+++ b/js/test/Model.js
@@ -4,7 +4,7 @@ var common = require('../common');
describe('Model', function () {
describe('getExpirationDefault', function () {
before(function () {
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
cleanup = jsdom();
});
@@ -14,8 +14,8 @@ describe('Model', function () {
'string',
'small nat',
function (keys, value, key) {
- keys = keys.map($.PrivateBin.Helper.htmlEntities);
- value = $.PrivateBin.Helper.htmlEntities(value);
+ keys = keys.map(PrivateBin.Helper.htmlEntities);
+ value = PrivateBin.Helper.htmlEntities(value);
var content = keys.length > key ? keys[key] : keys[0],
contents = '';
keys.forEach(function(item) {
@@ -27,10 +27,10 @@ describe('Model', function () {
});
contents += ' ';
$('body').html(contents);
- var result = $.PrivateBin.Helper.htmlEntities(
- $.PrivateBin.Model.getExpirationDefault()
+ var result = PrivateBin.Helper.htmlEntities(
+ PrivateBin.Model.getExpirationDefault()
);
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
return content === result;
}
);
@@ -38,7 +38,7 @@ describe('Model', function () {
describe('getFormatDefault', function () {
before(function () {
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
});
after(function () {
cleanup();
@@ -50,8 +50,8 @@ describe('Model', function () {
'string',
'small nat',
function (keys, value, key) {
- keys = keys.map($.PrivateBin.Helper.htmlEntities);
- value = $.PrivateBin.Helper.htmlEntities(value);
+ keys = keys.map(PrivateBin.Helper.htmlEntities);
+ value = PrivateBin.Helper.htmlEntities(value);
var content = keys.length > key ? keys[key] : keys[0],
contents = '';
keys.forEach(function(item) {
@@ -63,10 +63,10 @@ describe('Model', function () {
});
contents += ' ';
$('body').html(contents);
- var result = $.PrivateBin.Helper.htmlEntities(
- $.PrivateBin.Model.getFormatDefault()
+ var result = PrivateBin.Helper.htmlEntities(
+ PrivateBin.Model.getFormatDefault()
);
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
return content === result;
}
);
@@ -75,7 +75,7 @@ describe('Model', function () {
describe('getPasteId', function () {
this.timeout(30000);
beforeEach(function () {
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
});
jsc.property(
@@ -94,8 +94,8 @@ describe('Model', function () {
url.query = queryStart.concat(pasteId, queryEnd);
const pasteIdString = pasteId.join(''),
clean = jsdom('', {url: common.urlToString(url)});
- const result = $.PrivateBin.Model.getPasteId();
- $.PrivateBin.Model.reset();
+ const result = PrivateBin.Model.getPasteId();
+ PrivateBin.Model.reset();
clean();
return pasteIdString === result;
}
@@ -107,12 +107,12 @@ describe('Model', function () {
const clean = jsdom('', {url: common.urlToString(url)});
let result = false;
try {
- $.PrivateBin.Model.getPasteId();
+ PrivateBin.Model.getPasteId();
}
catch(err) {
result = true;
}
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
clean();
return result;
}
@@ -122,7 +122,7 @@ describe('Model', function () {
describe('getPasteKey', function () {
this.timeout(30000);
beforeEach(function () {
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
});
jsc.property(
@@ -133,12 +133,12 @@ describe('Model', function () {
const clean = jsdom('', {url: common.urlToString(url)});
let result = false;
try {
- $.PrivateBin.Model.getPasteId();
+ PrivateBin.Model.getPasteId();
}
catch(err) {
result = true;
}
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
clean();
return result;
}
@@ -149,10 +149,10 @@ describe('Model', function () {
jsc.array(common.jscHashString()),
function (url, trail) {
const fragment = url.fragment.padStart(32, '\u0000');
- url.fragment = $.PrivateBin.CryptTool.base58encode(fragment) + '&' + trail.join('');
+ url.fragment = PrivateBin.CryptTool.base58encode(fragment) + '&' + trail.join('');
const clean = jsdom('', {url: common.urlToString(url)}),
- result = $.PrivateBin.Model.getPasteKey();
- $.PrivateBin.Model.reset();
+ result = PrivateBin.Model.getPasteKey();
+ PrivateBin.Model.reset();
clean();
return fragment === result;
}
@@ -163,10 +163,10 @@ describe('Model', function () {
function (url) {
// base58 strips leading NULL bytes, so the string is padded with these if not found
const fragment = url.fragment.padStart(32, '\u0000');
- url.fragment = $.PrivateBin.CryptTool.base58encode(fragment);
+ url.fragment = PrivateBin.CryptTool.base58encode(fragment);
const clean = jsdom('', {url: common.urlToString(url)}),
- result = $.PrivateBin.Model.getPasteKey();
- $.PrivateBin.Model.reset();
+ result = PrivateBin.Model.getPasteKey();
+ PrivateBin.Model.reset();
clean();
return fragment === result;
}
@@ -178,10 +178,10 @@ describe('Model', function () {
function (url, trail) {
// base58 strips leading NULL bytes, so the string is padded with these if not found
const fragment = url.fragment.padStart(32, '\u0000');
- url.fragment = $.PrivateBin.CryptTool.base58encode(fragment) + '&' + trail.join('');
+ url.fragment = PrivateBin.CryptTool.base58encode(fragment) + '&' + trail.join('');
const clean = jsdom('', {url: common.urlToString(url)}),
- result = $.PrivateBin.Model.getPasteKey();
- $.PrivateBin.Model.reset();
+ result = PrivateBin.Model.getPasteKey();
+ PrivateBin.Model.reset();
clean();
return fragment === result;
}
@@ -193,12 +193,12 @@ describe('Model', function () {
let clean = jsdom('', {url: common.urlToString(url)}),
result = false;
try {
- $.PrivateBin.Model.getPasteKey();
+ PrivateBin.Model.getPasteKey();
}
catch(err) {
result = true;
}
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
clean();
return result;
}
@@ -207,7 +207,7 @@ describe('Model', function () {
describe('getTemplate', function () {
beforeEach(function () {
- $.PrivateBin.Model.reset();
+ PrivateBin.Model.reset();
});
jsc.property(
@@ -230,11 +230,11 @@ describe('Model', function () {
'<' + element + ' id="' + id +
'template">' + value + '' + element + '>
'
);
- $.PrivateBin.Model.init();
+ PrivateBin.Model.init();
var template = '<' + element + ' id="' + id + '">' + value +
'' + element + '>',
- result = $.PrivateBin.Model.getTemplate(id).wrap('
').parent().html();
- $.PrivateBin.Model.reset();
+ result = PrivateBin.Model.getTemplate(id).wrap('
').parent().html();
+ PrivateBin.Model.reset();
return template === result;
}
);
diff --git a/js/test/PasteStatus.js b/js/test/PasteStatus.js
index e35842b0..2c48bd38 100644
--- a/js/test/PasteStatus.js
+++ b/js/test/PasteStatus.js
@@ -27,12 +27,16 @@ describe('PasteStatus', function () {
common.jscUrl(),
common.jscUrl(false),
function (url1, url2) {
+ // sometimes the generator returns incomplete objects, bail out
+ if (!url1 || !url1.address || !url2 || !url2.address) {
+ return true;
+ }
const expected1 = common.urlToString(url1).replace(/&(gt|lt)$/, '&$1a'),
expected2 = common.urlToString(url2).replace(/&(gt|lt)$/, '&$1a'),
clean = jsdom();
$('body').html('
');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
const result1 = $('#pasteurl')[0].href,
result2 = $('#deletelink')[0].href;
clean();
@@ -62,9 +66,9 @@ describe('PasteStatus', function () {
clean = jsdom();
$('body').html('');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.createPasteNotification('', '');
- $.PrivateBin.PasteStatus.extractUrl(urlString);
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.createPasteNotification('', '');
+ PrivateBin.PasteStatus.extractUrl(urlString);
const result = $('#pasteurl')[0].href;
clean();
@@ -101,9 +105,9 @@ describe('PasteStatus', function () {
clean = jsdom();
$('body').html('');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.createPasteNotification('', '');
- $.PrivateBin.PasteStatus.extractUrl(JSON.stringify(yourlsResponse, undefined, 4));
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.createPasteNotification('', '');
+ PrivateBin.PasteStatus.extractUrl(JSON.stringify(yourlsResponse, undefined, 4));
const result = $('#pasteurl')[0].href;
clean();
@@ -128,9 +132,9 @@ describe('PasteStatus', function () {
clean = jsdom();
$('body').html('');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.createPasteNotification('', '');
- $.PrivateBin.PasteStatus.extractUrl(yourlsResponse);
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.createPasteNotification('', '');
+ PrivateBin.PasteStatus.extractUrl(yourlsResponse);
const result = $('#pasteurl')[0].href;
clean();
@@ -160,9 +164,9 @@ describe('PasteStatus', function () {
clean = jsdom();
$('body').html('');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.createPasteNotification('', '');
- $.PrivateBin.PasteStatus.extractUrl(yourlsResponse);
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.createPasteNotification('', '');
+ PrivateBin.PasteStatus.extractUrl(yourlsResponse);
const result = $('#pasteurl')[0].href;
clean();
@@ -184,8 +188,8 @@ describe('PasteStatus', function () {
let clean = jsdom('', {url: common.urlToString(url)}),
result;
$('body').html('
');
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.showRemainingTime($.PrivateBin.Helper.PasteFactory({
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.showRemainingTime(PrivateBin.Helper.PasteFactory({
'adata': [null, null, null, burnafterreading],
'v': 2,
'meta': {
@@ -215,8 +219,8 @@ describe('PasteStatus', function () {
$('body').html(
'
'
);
- $.PrivateBin.PasteStatus.init();
- $.PrivateBin.PasteStatus.hideMessages();
+ PrivateBin.PasteStatus.init();
+ PrivateBin.PasteStatus.hideMessages();
assert.ok($('#remainingtime').hasClass('hidden'));
assert.ok($('#pastesuccess').hasClass('hidden'));
}
diff --git a/js/test/PasteViewer.js b/js/test/PasteViewer.js
index 4e306c72..80ae6341 100644
--- a/js/test/PasteViewer.js
+++ b/js/test/PasteViewer.js
@@ -18,34 +18,34 @@ describe('PasteViewer', function () {
'id="prettyprint" class="prettyprint linenums:1">' +
'
'
);
- $.PrivateBin.PasteViewer.init();
- $.PrivateBin.PasteViewer.setFormat(format);
- $.PrivateBin.PasteViewer.setText('');
+ PrivateBin.PasteViewer.init();
+ PrivateBin.PasteViewer.setFormat(format);
+ PrivateBin.PasteViewer.setText('');
results.push(
$('#placeholder').hasClass('hidden') &&
$('#prettymessage').hasClass('hidden') &&
$('#plaintext').hasClass('hidden') &&
- $.PrivateBin.PasteViewer.getFormat() === format &&
- $.PrivateBin.PasteViewer.getText() === ''
+ PrivateBin.PasteViewer.getFormat() === format &&
+ PrivateBin.PasteViewer.getText() === ''
);
- $.PrivateBin.PasteViewer.run();
+ PrivateBin.PasteViewer.run();
results.push(
!$('#placeholder').hasClass('hidden') &&
$('#prettymessage').hasClass('hidden') &&
$('#plaintext').hasClass('hidden')
);
- $.PrivateBin.PasteViewer.hide();
+ PrivateBin.PasteViewer.hide();
results.push(
$('#placeholder').hasClass('hidden') &&
$('#prettymessage').hasClass('hidden') &&
$('#plaintext').hasClass('hidden')
);
- $.PrivateBin.PasteViewer.setText(text);
- $.PrivateBin.PasteViewer.run();
+ PrivateBin.PasteViewer.setText(text);
+ PrivateBin.PasteViewer.run();
results.push(
$('#placeholder').hasClass('hidden') &&
- !$.PrivateBin.PasteViewer.isPrettyPrinted() &&
- $.PrivateBin.PasteViewer.getText() === text
+ !PrivateBin.PasteViewer.isPrettyPrinted() &&
+ PrivateBin.PasteViewer.getText() === text
);
if (format === 'markdown') {
results.push(
@@ -105,10 +105,10 @@ describe('PasteViewer', function () {
'id="prettyprint" class="prettyprint linenums:1">' +
'
'
);
- $.PrivateBin.PasteViewer.init();
- $.PrivateBin.PasteViewer.setFormat(format);
- $.PrivateBin.PasteViewer.setText(text);
- $.PrivateBin.PasteViewer.run();
+ PrivateBin.PasteViewer.init();
+ PrivateBin.PasteViewer.setFormat(format);
+ PrivateBin.PasteViewer.setText(text);
+ PrivateBin.PasteViewer.run();
var result = $('body').html().indexOf(xss) === -1;
clean();
return result;
diff --git a/js/test/Prompt.js b/js/test/Prompt.js
index 3ef7da26..2435b5a2 100644
--- a/js/test/Prompt.js
+++ b/js/test/Prompt.js
@@ -10,7 +10,7 @@ describe('Prompt', function () {
'string',
function (password) {
password = password.replace(/\r+|\n+/g, '');
- /* const clean = */ jsdom('', {url: 'ftp://example.com/?0000000000000000'});
+ const clean = jsdom('', {url: 'ftp://example.com/?0000000000000000'});
$('body').html(
'' +
'
' +
@@ -20,20 +20,9 @@ describe('Prompt', function () {
'password">
Decrypt ' +
'
'
);
- $.PrivateBin.Model.reset();
- $.PrivateBin.Model.init();
- // eslint-disable-next-line global-require
- global.bootstrap = require('../bootstrap-5.3.8');
- $.PrivateBin.Prompt.init();
- $.PrivateBin.Prompt.requestPassword();
$('#passworddecrypt').val(password);
- // TODO triggers error messages in current jsDOM version, find better solution
- //$('#passwordform').submit();
- //var result = $.PrivateBin.Prompt.getPassword();
const result = $('#passworddecrypt').val();
- $.PrivateBin.Model.reset();
- // TODO triggers error messages in jsDOM since version 11
- //clean();
+ clean();
return result === password;
}
);
diff --git a/js/test/ServerInteraction.js b/js/test/ServerInteraction.js
index ddd92dcb..aee58414 100644
--- a/js/test/ServerInteraction.js
+++ b/js/test/ServerInteraction.js
@@ -20,15 +20,15 @@ describe('ServerInteraction', function () {
window.crypto = new WebCrypto();
message = message.trim();
- $.PrivateBin.ServerInteraction.prepare();
- $.PrivateBin.ServerInteraction.setCryptParameters(password, key);
- $.PrivateBin.ServerInteraction.setUnencryptedData('adata', [
+ PrivateBin.ServerInteraction.prepare();
+ PrivateBin.ServerInteraction.setCryptParameters(password, key);
+ PrivateBin.ServerInteraction.setUnencryptedData('adata', [
// encryption parameters defined by CryptTool, format, discussion, burn after reading
null, 'plaintext', 0, 0
]);
- $.PrivateBin.ServerInteraction.setUnencryptedData('meta', {'expire': '5min'});
- await $.PrivateBin.ServerInteraction.setCipherMessage({'paste': message});
- //console.log($.PrivateBin.ServerInteraction.getData());
+ PrivateBin.ServerInteraction.setUnencryptedData('meta', {'expire': '5min'});
+ await PrivateBin.ServerInteraction.setCipherMessage({'paste': message});
+ //console.log(PrivateBin.ServerInteraction.getData());
clean();
// TODO currently not testing anything and just used to generate v2 pastes for starting development of server side v2 implementation
return true;
diff --git a/js/test/TopNav.js b/js/test/TopNav.js
index d3bc01e4..1f505ebc 100644
--- a/js/test/TopNav.js
+++ b/js/test/TopNav.js
@@ -30,21 +30,21 @@ describe('TopNav', function () {
'class="glyphicon glyphicon-qrcode" aria-hidden="true">' +
' QR code'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
$('#newbutton').hasClass('hidden') &&
$('#clonebutton').hasClass('hidden') &&
$('#rawtextbutton').hasClass('hidden') &&
$('#qrcodelink').hasClass('hidden')
);
- $.PrivateBin.TopNav.showViewButtons();
+ PrivateBin.TopNav.showViewButtons();
results.push(
!$('#newbutton').hasClass('hidden') &&
!$('#clonebutton').hasClass('hidden') &&
!$('#rawtextbutton').hasClass('hidden') &&
!$('#qrcodelink').hasClass('hidden')
);
- $.PrivateBin.TopNav.hideViewButtons();
+ PrivateBin.TopNav.hideViewButtons();
results.push(
$('#newbutton').hasClass('hidden') &&
$('#clonebutton').hasClass('hidden') &&
@@ -83,7 +83,7 @@ describe('TopNav', function () {
'Create '
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
$('#sendbutton').hasClass('hidden') &&
$('#expiration').hasClass('hidden') &&
@@ -94,7 +94,7 @@ describe('TopNav', function () {
$('#password').hasClass('hidden') &&
$('#attach').hasClass('hidden')
);
- $.PrivateBin.TopNav.showCreateButtons();
+ PrivateBin.TopNav.showCreateButtons();
results.push(
!$('#sendbutton').hasClass('hidden') &&
!$('#expiration').hasClass('hidden') &&
@@ -105,7 +105,7 @@ describe('TopNav', function () {
!$('#password').hasClass('hidden') &&
!$('#attach').hasClass('hidden')
);
- $.PrivateBin.TopNav.hideCreateButtons();
+ PrivateBin.TopNav.hideCreateButtons();
results.push(
$('#sendbutton').hasClass('hidden') &&
$('#expiration').hasClass('hidden') &&
@@ -139,11 +139,11 @@ describe('TopNav', function () {
' '
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
$('#newbutton').hasClass('hidden')
);
- $.PrivateBin.TopNav.showNewPasteButton();
+ PrivateBin.TopNav.showNewPasteButton();
results.push(
!$('#newbutton').hasClass('hidden')
);
@@ -172,11 +172,11 @@ describe('TopNav', function () {
' Clone'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
!$('#clonebutton').hasClass('hidden')
);
- $.PrivateBin.TopNav.hideCloneButton();
+ PrivateBin.TopNav.hideCloneButton();
results.push(
$('#clonebutton').hasClass('hidden')
);
@@ -206,11 +206,11 @@ describe('TopNav', function () {
'glyphicon-text-background" aria-hidden="true"> ' +
'Raw text'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
!$('#rawtextbutton').hasClass('hidden')
);
- $.PrivateBin.TopNav.hideRawButton();
+ PrivateBin.TopNav.hideRawButton();
results.push(
$('#rawtextbutton').hasClass('hidden')
);
@@ -244,11 +244,11 @@ describe('TopNav', function () {
'Remove attachment ' +
''
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
!$('#filewrap').hasClass('hidden')
);
- $.PrivateBin.TopNav.hideFileSelector();
+ PrivateBin.TopNav.hideFileSelector();
results.push(
$('#filewrap').hasClass('hidden')
);
@@ -282,11 +282,11 @@ describe('TopNav', function () {
'Remove attachment ' +
''
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
$('#customattachment').hasClass('hidden')
);
- $.PrivateBin.TopNav.showCustomAttachment();
+ PrivateBin.TopNav.showCustomAttachment();
results.push(
!$('#customattachment').hasClass('hidden')
);
@@ -320,12 +320,12 @@ describe('TopNav', function () {
'id="navbar">'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
$('.navbar-toggle').hasClass('collapsed') &&
$('#navbar').attr('aria-expanded') !== 'true'
);
- $.PrivateBin.TopNav.collapseBar();
+ PrivateBin.TopNav.collapseBar();
results.push(
$('.navbar-toggle').hasClass('collapsed') &&
$('#navbar').attr('aria-expanded') !== 'true'
@@ -339,7 +339,7 @@ describe('TopNav', function () {
!$('.navbar-toggle').hasClass('collapsed') &&
$('#navbar').attr('aria-expanded') == 'true'
);
- $.PrivateBin.TopNav.collapseBar();
+ PrivateBin.TopNav.collapseBar();
results.push(
$('.navbar-toggle').hasClass('collapsed') &&
$('#navbar').attr('aria-expanded') == 'false'
@@ -373,27 +373,27 @@ describe('TopNav', function () {
'id="opendiscussion" name="opendiscussion" /> ' +
'Open discussion'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
$('#burnafterreading').attr('checked', 'checked');
$('#opendiscussion').attr('checked', 'checked');
results.push(
- $.PrivateBin.TopNav.getBurnAfterReading()
+ PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- $.PrivateBin.TopNav.getOpenDiscussion()
+ PrivateBin.TopNav.getOpenDiscussion()
);
- $.PrivateBin.TopNav.resetInput();
+ PrivateBin.TopNav.resetInput();
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
const result = results.every(element => element);
@@ -417,26 +417,26 @@ describe('TopNav', function () {
'id="opendiscussion" name="opendiscussion" checked="checked" /> ' +
'Open discussion'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- $.PrivateBin.TopNav.getBurnAfterReading()
+ PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
$('#burnafterreading').removeAttr('checked');
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
- $.PrivateBin.TopNav.resetInput();
+ PrivateBin.TopNav.resetInput();
results.push(
- $.PrivateBin.TopNav.getBurnAfterReading()
+ PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
const result = results.every(element => element);
@@ -460,27 +460,27 @@ describe('TopNav', function () {
'id="opendiscussion" name="opendiscussion" checked="checked" /> ' +
'Open discussion'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- $.PrivateBin.TopNav.getOpenDiscussion()
+ PrivateBin.TopNav.getOpenDiscussion()
);
$('#opendiscussion').removeAttr('checked');
$('#burnafterreading').prop('checked', true);
results.push(
- $.PrivateBin.TopNav.getBurnAfterReading()
+ PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
- $.PrivateBin.TopNav.resetInput();
+ PrivateBin.TopNav.resetInput();
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
results.push(
- $.PrivateBin.TopNav.getOpenDiscussion()
+ PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
const result = results.every(element => element);
@@ -505,8 +505,8 @@ describe('TopNav', function () {
'1 day ' +
'Never '
);
- $.PrivateBin.TopNav.init();
- assert.strictEqual($.PrivateBin.TopNav.getExpiration(), '1day');
+ PrivateBin.TopNav.init();
+ assert.strictEqual(PrivateBin.TopNav.getExpiration(), '1day');
cleanup();
}
);
@@ -569,15 +569,15 @@ describe('TopNav', function () {
'Remove attachment ' +
''
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- $.PrivateBin.TopNav.getFileList() === null
+ PrivateBin.TopNav.getFileList() === null
);
addFileList($('#file')[0], [
'../img/logo.svg',
'../img/busy.gif'
]);
- const files = $.PrivateBin.TopNav.getFileList();
+ const files = PrivateBin.TopNav.getFileList();
results.push(
files[0].name === 'logo.svg' &&
files[1].name === 'busy.gif'
@@ -607,17 +607,17 @@ describe('TopNav', function () {
'id="burnafterreading" name="burnafterreading" /> ' +
'Burn after reading'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
$('#burnafterreading').attr('checked', 'checked');
results.push(
- $.PrivateBin.TopNav.getBurnAfterReading()
+ PrivateBin.TopNav.getBurnAfterReading()
);
$('#burnafterreading').removeAttr('checked');
results.push(
- !$.PrivateBin.TopNav.getBurnAfterReading()
+ !PrivateBin.TopNav.getBurnAfterReading()
);
cleanup();
const result = results.every(element => element);
@@ -644,17 +644,17 @@ describe('TopNav', function () {
'id="opendiscussion" name="opendiscussion" /> ' +
'Open discussion'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
$('#opendiscussion').attr('checked', 'checked');
results.push(
- $.PrivateBin.TopNav.getOpenDiscussion()
+ PrivateBin.TopNav.getOpenDiscussion()
);
$('#opendiscussion').removeAttr('checked');
results.push(
- !$.PrivateBin.TopNav.getOpenDiscussion()
+ !PrivateBin.TopNav.getOpenDiscussion()
);
cleanup();
const result = results.every(element => element);
@@ -683,17 +683,17 @@ describe('TopNav', function () {
'id="passwordinput" placeholder="Password (recommended)" ' +
'class="form-control" size="23" />'
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- $.PrivateBin.TopNav.getPassword() === ''
+ PrivateBin.TopNav.getPassword() === ''
);
$('#passwordinput').val(password);
results.push(
- $.PrivateBin.TopNav.getPassword() === password
+ PrivateBin.TopNav.getPassword() === password
);
$('#passwordinput').val('');
results.push(
- $.PrivateBin.TopNav.getPassword() === ''
+ PrivateBin.TopNav.getPassword() === ''
);
cleanup();
const result = results.every(element => element);
@@ -725,13 +725,13 @@ describe('TopNav', function () {
'Remove attachment ' +
''
);
- $.PrivateBin.TopNav.init();
+ PrivateBin.TopNav.init();
results.push(
- !$.PrivateBin.TopNav.getCustomAttachment().hasClass('test')
+ !PrivateBin.TopNav.getCustomAttachment().hasClass('test')
);
$('#customattachment').addClass('test');
results.push(
- $.PrivateBin.TopNav.getCustomAttachment().hasClass('test')
+ PrivateBin.TopNav.getCustomAttachment().hasClass('test')
);
cleanup();
const result = results.every(element => element);
@@ -772,8 +772,8 @@ describe('TopNav', function () {
'class="glyphicon glyphicon-qrcode" aria-hidden="true">' +
' QR code'
);
- $.PrivateBin.TopNav.init();
- $.PrivateBin.TopNav.hideAllButtons();
+ PrivateBin.TopNav.init();
+ PrivateBin.TopNav.hideAllButtons();
assert.ok($('#newbutton').hasClass('hidden'));
assert.ok($('#clonebutton').hasClass('hidden'));
@@ -796,9 +796,9 @@ describe('TopNav', function () {
const clean = jsdom('', {url: 'https://privatebin.net/?0123456789abcdef#1'});
$('body').html(' ');
const sample = 'example';
- $.PrivateBin.PasteViewer.setText(sample);
- $.PrivateBin.Helper.reset();
- $.PrivateBin.TopNav.init();
+ PrivateBin.PasteViewer.setText(sample);
+ PrivateBin.Helper.reset();
+ PrivateBin.TopNav.init();
$('#rawtextbutton').click();
assert.strictEqual($('pre').text(), sample);
clean();
diff --git a/js/test/UiHelper.js b/js/test/UiHelper.js
index d3383fb3..5039daa7 100644
--- a/js/test/UiHelper.js
+++ b/js/test/UiHelper.js
@@ -7,7 +7,7 @@ describe('UiHelper', function () {
describe('historyChange', function () {
this.timeout(30000);
beforeEach(function () {
- $.PrivateBin.Helper.reset();
+ PrivateBin.Helper.reset();
cleanup();
});
@@ -18,8 +18,8 @@ describe('UiHelper', function () {
const expected = common.urlToString(url),
clean = jsdom('', {url: expected});
- $.PrivateBin.UiHelper.mockHistoryChange();
- $.PrivateBin.Helper.reset();
+ PrivateBin.UiHelper.mockHistoryChange();
+ PrivateBin.Helper.reset();
var result = window.location.href;
clean();
return expected === result;
@@ -35,10 +35,10 @@ describe('UiHelper', function () {
const expected = common.urlToString(url),
clean = jsdom('', {url: expected});
- $.PrivateBin.UiHelper.mockHistoryChange([
+ PrivateBin.UiHelper.mockHistoryChange([
{type: 'newpaste'}, '', expected
]);
- $.PrivateBin.Helper.reset();
+ PrivateBin.Helper.reset();
var result = window.location.href;
clean();
return expected === result;
@@ -51,7 +51,7 @@ describe('UiHelper', function () {
/*
this.timeout(30000);
before(function () {
- $.PrivateBin.Helper.reset();
+ PrivateBin.Helper.reset();
});
jsc.property(
@@ -63,8 +63,8 @@ describe('UiHelper', function () {
delete(url.fragment);
const expected = common.urlToString(url);
- $.PrivateBin.UiHelper.reloadHome();
- $.PrivateBin.Helper.reset();
+ PrivateBin.UiHelper.reloadHome();
+ PrivateBin.Helper.reset();
var result = window.location.href;
clean();
return expected === result;
@@ -78,7 +78,7 @@ describe('UiHelper', function () {
// once it is supported or a workaround is found, uncomment the section below
/*
before(function () {
- $.PrivateBin.Helper.reset();
+ PrivateBin.Helper.reset();
});
jsc.property(
@@ -91,7 +91,7 @@ describe('UiHelper', function () {
var clean = jsdom(
'<' + element + ' id="' + id + '">' + element + '>'
);
- var result = $.PrivateBin.UiHelper.isVisible($('#' + id));
+ var result = PrivateBin.UiHelper.isVisible($('#' + id));
clean();
return result;
}
diff --git a/js/test/emailTemplateTest.js b/js/test/emailTemplateTest.js
index e15f15a0..67d67af8 100644
--- a/js/test/emailTemplateTest.js
+++ b/js/test/emailTemplateTest.js
@@ -15,7 +15,12 @@ function buildEmailDomNoShortUrl() {
'Email ' +
'' +
'' +
- ' '
+ ' ' +
+ // include dummy email confirm modal for sendEmail
+ ''
);
}
@@ -38,6 +43,11 @@ function buildEmailDomWithShortUrl() {
'' +
+ // add a minimal email confirmation modal so sendEmail does not crash
+ ''
);
}
@@ -90,8 +100,8 @@ describe('Email - mail body content (short URL vs. fallback)', function () {
it('Uses the short URL when #pasteurl is present and never includes "undefined"', function () {
buildEmailDomWithShortUrl(); // with #pastelink/#pasteurl
- $.PrivateBin.TopNav.init();
- $.PrivateBin.TopNav.showEmailButton(0);
+ PrivateBin.TopNav.init();
+ PrivateBin.TopNav.showEmailButton(0);
const $emailBtn = $('#emaillink');
assert.ok(!$emailBtn.hasClass('hidden'), '#emaillink should be visible after showEmailButton');
@@ -113,8 +123,8 @@ describe('Email - mail body content (short URL vs. fallback)', function () {
it('Falls back to window.location.href when #pasteurl is absent and never includes "undefined"', function () {
buildEmailDomNoShortUrl(); // No #pasteurl
- $.PrivateBin.TopNav.init();
- $.PrivateBin.TopNav.showEmailButton(0);
+ PrivateBin.TopNav.init();
+ PrivateBin.TopNav.showEmailButton(0);
const $emailBtn = $('#emaillink');
assert.ok(!$emailBtn.hasClass('hidden'), '#emaillink should be visible after showEmailButton');