mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-04-16 21:27:25 -04:00
test: change all other tests to not use jQuery
This commit is contained in:
120
js/test/Alert.js
120
js/test/Alert.js
@@ -11,12 +11,11 @@ describe('Alert', function () {
|
||||
icon = icon.join('');
|
||||
message = message.join('');
|
||||
const expected = '<div id="status">' + message + '</div>';
|
||||
$('body').html(
|
||||
'<div id="status"></div>'
|
||||
);
|
||||
document.body.innerHTML =
|
||||
'<div id="status"></div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showStatus(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -30,14 +29,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-info"><span ' +
|
||||
'class="glyphicon glyphicon-info-sign" ' +
|
||||
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="status" role="alert" class="statusmessage ' +
|
||||
'alert alert-info hidden"><span class="glyphicon ' +
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showStatus(message);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -53,14 +51,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-info"><span ' +
|
||||
'class="glyphicon glyphicon-' + icon +
|
||||
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="status" role="alert" class="statusmessage ' +
|
||||
'alert alert-info hidden"><span class="glyphicon ' +
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showStatus(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -75,12 +72,11 @@ describe('Alert', function () {
|
||||
icon = icon.join('');
|
||||
message = message.join('');
|
||||
const expected = '<div id="errormessage">' + message + '</div>';
|
||||
$('body').html(
|
||||
'<div id="errormessage"></div>'
|
||||
);
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage"></div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showWarning(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -95,14 +91,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-danger"><span ' +
|
||||
'class="glyphicon glyphicon-warning-sign" ' +
|
||||
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger hidden"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showWarning(message);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -118,14 +113,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-danger"><span ' +
|
||||
'class="glyphicon glyphicon-' + icon +
|
||||
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger hidden"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showWarning(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -140,12 +134,11 @@ describe('Alert', function () {
|
||||
icon = icon.join('');
|
||||
message = message.join('');
|
||||
const expected = '<div id="errormessage">' + message + '</div>';
|
||||
$('body').html(
|
||||
'<div id="errormessage"></div>'
|
||||
);
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage"></div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showError(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -160,14 +153,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-danger"><span ' +
|
||||
'class="glyphicon glyphicon-alert" ' +
|
||||
'aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger hidden"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showError(message);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -183,14 +175,13 @@ describe('Alert', function () {
|
||||
'class="statusmessage alert alert-danger"><span ' +
|
||||
'class="glyphicon glyphicon-' + icon +
|
||||
'" aria-hidden="true"></span> <span>' + message + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger hidden"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showError(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -206,12 +197,11 @@ describe('Alert', function () {
|
||||
message = message.join('');
|
||||
string = string.join('');
|
||||
const expected = '<div id="remainingtime" class="">' + string + message + number + '</div>';
|
||||
$('body').html(
|
||||
'<div id="remainingtime" class="hidden"></div>'
|
||||
);
|
||||
document.body.innerHTML =
|
||||
'<div id="remainingtime" class="hidden"></div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -228,14 +218,13 @@ describe('Alert', function () {
|
||||
'class="alert alert-info"><span ' +
|
||||
'class="glyphicon glyphicon-fire" aria-hidden="true">' +
|
||||
'</span> <span>' + string + message + number + '</span></div>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="remainingtime" role="alert" class="hidden ' +
|
||||
'alert alert-info"><span class="glyphicon ' +
|
||||
'glyphicon-fire" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-fire" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showRemaining(['%s' + message + '%d', string, number]);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -254,12 +243,11 @@ describe('Alert', function () {
|
||||
message = defaultMessage;
|
||||
}
|
||||
const expected = '<div id="loadingindicator" class="">' + message + '</div>';
|
||||
$('body').html(
|
||||
'<div id="loadingindicator" class="hidden">' + defaultMessage + '</div>'
|
||||
);
|
||||
document.body.innerHTML =
|
||||
'<div id="loadingindicator" class="hidden">' + defaultMessage + '</div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showLoading(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -279,15 +267,14 @@ describe('Alert', function () {
|
||||
'id="loadingindicator" class="navbar-text"><span ' +
|
||||
'class="glyphicon glyphicon-' + icon +
|
||||
'" aria-hidden="true"></span> <span>' + message + '</span></li></ul>';
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
||||
'class="navbar-text hidden"><span class="glyphicon ' +
|
||||
'glyphicon-time" aria-hidden="true"></span> ' +
|
||||
defaultMessage + '</li></ul>'
|
||||
);
|
||||
defaultMessage + '</li></ul>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.showLoading(message, icon);
|
||||
const result = $('body').html();
|
||||
const result = document.body.innerHTML;
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -297,17 +284,16 @@ describe('Alert', function () {
|
||||
it(
|
||||
'hides the loading message',
|
||||
function() {
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
||||
'class="navbar-text"><span class="glyphicon ' +
|
||||
'glyphicon-time" aria-hidden="true"></span> ' +
|
||||
'Loading…</li></ul>'
|
||||
);
|
||||
$('body').addClass('loading');
|
||||
'Loading…</li></ul>';
|
||||
document.body.classList.add('loading');
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.hideLoading();
|
||||
assert.ok(!$('body').hasClass('loading'));
|
||||
assert.ok($('#loadingindicator').hasClass('hidden'));
|
||||
assert.ok(!document.body.classList.contains('loading'));
|
||||
assert.ok(document.getElementById('loadingindicator').classList.contains('hidden'));
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -316,18 +302,17 @@ describe('Alert', function () {
|
||||
it(
|
||||
'hides all messages',
|
||||
function() {
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<div id="status" role="alert" class="statusmessage ' +
|
||||
'alert alert-info"><span class="glyphicon ' +
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>' +
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.hideMessages();
|
||||
assert.ok($('#status').hasClass('hidden'));
|
||||
assert.ok($('#errormessage').hasClass('hidden'));
|
||||
assert.ok(document.getElementById('status').classList.contains('hidden'));
|
||||
assert.ok(document.getElementById('errormessage').classList.contains('hidden'));
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -350,7 +335,7 @@ describe('Alert', function () {
|
||||
if (message.length === 0) {
|
||||
message = defaultMessage;
|
||||
}
|
||||
$('body').html(
|
||||
document.body.innerHTML =
|
||||
'<ul class="nav navbar-nav"><li id="loadingindicator" ' +
|
||||
'class="navbar-text hidden"><span class="glyphicon ' +
|
||||
'glyphicon-time" aria-hidden="true"></span> ' +
|
||||
@@ -363,12 +348,11 @@ describe('Alert', function () {
|
||||
'glyphicon-info-sign" aria-hidden="true"></span> </div>' +
|
||||
'<div id="errormessage" role="alert" class="statusmessage ' +
|
||||
'alert alert-danger"><span class="glyphicon ' +
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>'
|
||||
);
|
||||
'glyphicon-alert" aria-hidden="true"></span> </div>';
|
||||
PrivateBin.Alert.init();
|
||||
PrivateBin.Alert.setCustomHandler(function(id, $element) {
|
||||
PrivateBin.Alert.setCustomHandler(function(id, element) {
|
||||
handlerCalled = true;
|
||||
return jsc.random(0, 1) ? true : $element;
|
||||
return jsc.random(0, 1) ? true : element;
|
||||
});
|
||||
functions[trigger](message);
|
||||
PrivateBin.Alert.setCustomHandler(null);
|
||||
|
||||
@@ -31,7 +31,7 @@ describe('AttachmentViewer', function () {
|
||||
}
|
||||
prefix = prefix.replace(/%(s|d)/g, '%%');
|
||||
postfix = postfix.replace(/%(s|d)/g, '%%').replace(/<|>/g, '');
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="attachmentPreview" class="col-md-12 text-center hidden"></div>' +
|
||||
'<div id="attachment" class="hidden"></div>' +
|
||||
'<div id="templates">' +
|
||||
@@ -55,10 +55,10 @@ describe('AttachmentViewer', function () {
|
||||
PrivateBin.Model.init();
|
||||
results.push(
|
||||
!PrivateBin.AttachmentViewer.hasAttachment() &&
|
||||
$('#attachment').hasClass('hidden') &&
|
||||
$('#attachment').children().length === 0 &&
|
||||
$('#attachmenttemplate').hasClass('hidden') &&
|
||||
$('#attachmentPreview').hasClass('hidden')
|
||||
document.getElementById('attachment').classList.contains('hidden') &&
|
||||
document.getElementById('attachment').children.length === 0 &&
|
||||
document.getElementById('attachmenttemplate').classList.contains('hidden') &&
|
||||
document.getElementById('attachmentPreview').classList.contains('hidden')
|
||||
);
|
||||
global.atob = common.atob;
|
||||
if (filename.length) {
|
||||
@@ -71,37 +71,39 @@ describe('AttachmentViewer', function () {
|
||||
const attachment = PrivateBin.AttachmentViewer.getAttachments();
|
||||
results.push(
|
||||
PrivateBin.AttachmentViewer.hasAttachment() &&
|
||||
$('#attachment').hasClass('hidden') &&
|
||||
$('#attachment').children().length > 0 &&
|
||||
$('#attachmentPreview').hasClass('hidden') &&
|
||||
document.getElementById('attachment').classList.contains('hidden') &&
|
||||
document.getElementById('attachment').children.length > 0 &&
|
||||
document.getElementById('attachmentPreview').classList.contains('hidden') &&
|
||||
attachment[0][0] === data &&
|
||||
attachment[0][1] === filename
|
||||
);
|
||||
PrivateBin.AttachmentViewer.showAttachment();
|
||||
results.push(
|
||||
!$('#attachment').hasClass('hidden') &&
|
||||
$('#attachment').children().length > 0 &&
|
||||
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
|
||||
!document.getElementById('attachment').classList.contains('hidden') &&
|
||||
document.getElementById('attachment').children.length > 0 &&
|
||||
(previewSupported ? !document.getElementById('attachmentPreview').classList.contains('hidden') : document.getElementById('attachmentPreview').classList.contains('hidden'))
|
||||
);
|
||||
PrivateBin.AttachmentViewer.hideAttachment();
|
||||
results.push(
|
||||
$('#attachment').hasClass('hidden') &&
|
||||
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
|
||||
document.getElementById('attachment').classList.contains('hidden') &&
|
||||
(previewSupported ? !document.getElementById('attachmentPreview').classList.contains('hidden') : document.getElementById('attachmentPreview').classList.contains('hidden'))
|
||||
);
|
||||
if (previewSupported) {
|
||||
PrivateBin.AttachmentViewer.hideAttachmentPreview();
|
||||
results.push($('#attachmentPreview').hasClass('hidden'));
|
||||
results.push(document.getElementById('attachmentPreview').classList.contains('hidden'));
|
||||
}
|
||||
PrivateBin.AttachmentViewer.showAttachment();
|
||||
results.push(
|
||||
!$('#attachment').hasClass('hidden') &&
|
||||
(previewSupported ? !$('#attachmentPreview').hasClass('hidden') : $('#attachmentPreview').hasClass('hidden'))
|
||||
!document.getElementById('attachment').classList.contains('hidden') &&
|
||||
(previewSupported ? !document.getElementById('attachmentPreview').classList.contains('hidden') : document.getElementById('attachmentPreview').classList.contains('hidden'))
|
||||
);
|
||||
let element = $('<div>');
|
||||
PrivateBin.AttachmentViewer.moveAttachmentTo(element[0], attachment[0], prefix + '%s' + postfix);
|
||||
let element = document.createElement('div');
|
||||
PrivateBin.AttachmentViewer.moveAttachmentTo(element, attachment[0], prefix + '%s' + postfix);
|
||||
// messageIDs with links get a relaxed treatment
|
||||
if (prefix.indexOf('<a') === -1 && postfix.indexOf('<a') === -1) {
|
||||
result = $('<textarea>').text((prefix + filename + postfix)).text();
|
||||
const tempTA = document.createElement('textarea');
|
||||
tempTA.textContent = (prefix + filename + postfix);
|
||||
result = tempTA.textContent;
|
||||
} else {
|
||||
result = DOMPurify.sanitize(
|
||||
prefix + PrivateBin.Helper.htmlEntities(filename) + postfix, {
|
||||
@@ -112,18 +114,18 @@ describe('AttachmentViewer', function () {
|
||||
}
|
||||
if (filename.length) {
|
||||
results.push(
|
||||
element.find('a')[0].href === data &&
|
||||
element.find('a')[0].getAttribute('download') === filename &&
|
||||
element.find('a')[0].text === result
|
||||
element.querySelector('a').href === data &&
|
||||
element.querySelector('a').getAttribute('download') === filename &&
|
||||
element.querySelector('a').textContent === result
|
||||
);
|
||||
} else {
|
||||
results.push(element.find('a')[0].href === data);
|
||||
results.push(element.querySelector('a').href === data);
|
||||
}
|
||||
PrivateBin.AttachmentViewer.removeAttachment();
|
||||
results.push(
|
||||
$('#attachment').hasClass('hidden') &&
|
||||
$('#attachment').children().length === 0 &&
|
||||
$('#attachmentPreview').hasClass('hidden')
|
||||
document.getElementById('attachment').classList.contains('hidden') &&
|
||||
document.getElementById('attachment').children.length === 0 &&
|
||||
document.getElementById('attachmentPreview').classList.contains('hidden')
|
||||
);
|
||||
clean();
|
||||
return results.every(element => element);
|
||||
@@ -134,7 +136,7 @@ describe('AttachmentViewer', function () {
|
||||
'sanitizes file names in attachments',
|
||||
function() {
|
||||
const clean = globalThis.cleanup();
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="attachmentPreview" class="col-md-12 text-center hidden"></div>' +
|
||||
'<div id="attachment" class="hidden"></div>' +
|
||||
'<div id="templates">' +
|
||||
@@ -164,7 +166,7 @@ describe('AttachmentViewer', function () {
|
||||
];
|
||||
for (const filename of maliciousFileNames) {
|
||||
PrivateBin.AttachmentViewer.setAttachment('data:;base64,', filename);
|
||||
assert.ok(!$('body').html().includes(filename));
|
||||
assert.ok(!document.body.innerHTML.includes(filename));
|
||||
}
|
||||
clean();
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ describe('CopyToClipboard', function() {
|
||||
var clean = globalThis.cleanup();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="placeholder" class="hidden">+++ no document text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
@@ -28,7 +28,7 @@ describe('CopyToClipboard', function() {
|
||||
|
||||
PrivateBin.CopyToClipboard.init();
|
||||
|
||||
$('#prettyMessageCopyBtn').trigger('click');
|
||||
document.getElementById('prettyMessageCopyBtn').click();
|
||||
|
||||
const savedToClipboardText = await navigator.clipboard.readText();
|
||||
|
||||
@@ -49,7 +49,7 @@ describe('CopyToClipboard', function() {
|
||||
var clean = globalThis.cleanup();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="placeholder">+++ no document text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
@@ -65,7 +65,7 @@ describe('CopyToClipboard', function() {
|
||||
|
||||
PrivateBin.CopyToClipboard.init();
|
||||
|
||||
$('body').trigger('copy');
|
||||
document.body.dispatchEvent(new Event('copy'));
|
||||
|
||||
const copiedTextWithoutSelectedText = await navigator.clipboard.readText();
|
||||
|
||||
@@ -83,12 +83,12 @@ describe('CopyToClipboard', function() {
|
||||
var clean = globalThis.cleanup();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html('<button id="copyLink"></button>');
|
||||
document.body.innerHTML = '<button id="copyLink"></button>';
|
||||
|
||||
PrivateBin.CopyToClipboard.init();
|
||||
PrivateBin.CopyToClipboard.setUrl(text);
|
||||
|
||||
$('#copyLink').trigger('click');
|
||||
document.getElementById('copyLink').click();
|
||||
|
||||
const copiedText = await navigator.clipboard.readText();
|
||||
|
||||
@@ -105,12 +105,12 @@ describe('CopyToClipboard', function() {
|
||||
function (text) {
|
||||
var clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<small id="copyShortcutHintText"></small>');
|
||||
document.body.innerHTML = '<small id="copyShortcutHintText"></small>';
|
||||
|
||||
PrivateBin.CopyToClipboard.init();
|
||||
PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
const keyboardShortcutHint = document.getElementById('copyShortcutHintText').textContent;
|
||||
|
||||
clean();
|
||||
|
||||
@@ -123,12 +123,12 @@ describe('CopyToClipboard', function() {
|
||||
function (text) {
|
||||
var clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<small id="copyShortcutHintText">' + text + '</small>');
|
||||
document.body.innerHTML = '<small id="copyShortcutHintText">' + text + '</small>';
|
||||
|
||||
PrivateBin.CopyToClipboard.init();
|
||||
PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
const keyboardShortcutHint = document.getElementById('copyShortcutHintText').textContent;
|
||||
|
||||
clean();
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ describe('DiscussionViewer', function () {
|
||||
function (comments, commentKey, fadeOut, nickname, message, alertType, alert) {
|
||||
var clean = globalThis.cleanup(),
|
||||
results = [];
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="discussion"><h4>Discussion</h4>' +
|
||||
'<div id="commentcontainer"></div></div><div id="templates">' +
|
||||
'<article id="commenttemplate" class="comment">' +
|
||||
@@ -51,11 +51,11 @@ describe('DiscussionViewer', function () {
|
||||
PrivateBin.Model.init();
|
||||
PrivateBin.DiscussionViewer.init();
|
||||
results.push(
|
||||
!$('#discussion').hasClass('hidden')
|
||||
!document.getElementById('discussion').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.DiscussionViewer.prepareNewDiscussion();
|
||||
results.push(
|
||||
$('#discussion').hasClass('hidden')
|
||||
document.getElementById('discussion').classList.contains('hidden')
|
||||
);
|
||||
comments.forEach(function (comment) {
|
||||
comment.id = comment.idArray.join('');
|
||||
@@ -63,12 +63,12 @@ describe('DiscussionViewer', function () {
|
||||
PrivateBin.DiscussionViewer.addComment(PrivateBin.Helper.CommentFactory(comment), comment.data, comment.meta.nickname);
|
||||
});
|
||||
results.push(
|
||||
$('#discussion').hasClass('hidden')
|
||||
document.getElementById('discussion').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.DiscussionViewer.finishDiscussion();
|
||||
results.push(
|
||||
!$('#discussion').hasClass('hidden') &&
|
||||
comments.length + 1 >= $('#commentcontainer').children().length
|
||||
!document.getElementById('discussion').classList.contains('hidden') &&
|
||||
comments.length + 1 >= document.getElementById('commentcontainer').children.length
|
||||
);
|
||||
if (comments.length > 0) {
|
||||
if (commentKey >= comments.length) {
|
||||
@@ -76,19 +76,19 @@ describe('DiscussionViewer', function () {
|
||||
}
|
||||
PrivateBin.DiscussionViewer.highlightComment(comments[commentKey].id, fadeOut);
|
||||
results.push(
|
||||
$('#comment_' + comments[commentKey].id).hasClass('highlight')
|
||||
document.getElementById('comment_' + comments[commentKey].id).classList.contains('highlight')
|
||||
);
|
||||
}
|
||||
$('#commentcontainer').find('button')[0].click();
|
||||
document.getElementById('commentcontainer').querySelector('button').click();
|
||||
results.push(
|
||||
!$('#reply').hasClass('hidden')
|
||||
!document.getElementById('reply').classList.contains('hidden')
|
||||
);
|
||||
$('#reply #nickname').val(nickname);
|
||||
$('#reply #replymessage').val(message);
|
||||
document.querySelector('#reply #nickname').value = nickname;
|
||||
document.querySelector('#reply #replymessage').value = message;
|
||||
PrivateBin.DiscussionViewer.getReplyCommentId();
|
||||
results.push(
|
||||
PrivateBin.DiscussionViewer.getReplyNickname() === $('#reply #nickname').val() &&
|
||||
PrivateBin.DiscussionViewer.getReplyMessage() === $('#reply #replymessage').val()
|
||||
PrivateBin.DiscussionViewer.getReplyNickname() === document.querySelector('#reply #nickname').value &&
|
||||
PrivateBin.DiscussionViewer.getReplyMessage() === document.querySelector('#reply #replymessage').value
|
||||
);
|
||||
var notificationResult = PrivateBin.DiscussionViewer.handleNotification(alertType === 'other' ? alert : alertType);
|
||||
if (alertType === 'loading') {
|
||||
@@ -96,11 +96,11 @@ describe('DiscussionViewer', function () {
|
||||
} else {
|
||||
results.push(
|
||||
alertType === 'danger' ? (
|
||||
notificationResult.hasClass('alert-danger') &&
|
||||
!notificationResult.hasClass('alert-info')
|
||||
notificationResult.classList.contains('alert-danger') &&
|
||||
!notificationResult.classList.contains('alert-info')
|
||||
) : (
|
||||
!notificationResult.hasClass('alert-danger') &&
|
||||
notificationResult.hasClass('alert-info')
|
||||
!notificationResult.classList.contains('alert-danger') &&
|
||||
notificationResult.classList.contains('alert-info')
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('Editor', function () {
|
||||
function (text) {
|
||||
var clean = globalThis.cleanup(),
|
||||
results = [];
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<ul id="editorTabs" class="nav nav-tabs hidden"><li ' +
|
||||
'role="presentation" class="active"><a id="messageedit" ' +
|
||||
'href="#">Editor</a></li><li role="presentation"><a ' +
|
||||
@@ -25,18 +25,18 @@ describe('Editor', function () {
|
||||
);
|
||||
PrivateBin.Editor.init();
|
||||
results.push(
|
||||
$('#editorTabs').hasClass('hidden') &&
|
||||
$('#message').hasClass('hidden')
|
||||
document.getElementById('editorTabs').classList.contains('hidden') &&
|
||||
document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.Editor.show();
|
||||
results.push(
|
||||
!$('#editorTabs').hasClass('hidden') &&
|
||||
!$('#message').hasClass('hidden')
|
||||
!document.getElementById('editorTabs').classList.contains('hidden') &&
|
||||
!document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.Editor.hide();
|
||||
results.push(
|
||||
$('#editorTabs').hasClass('hidden') &&
|
||||
$('#message').hasClass('hidden')
|
||||
document.getElementById('editorTabs').classList.contains('hidden') &&
|
||||
document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.Editor.show();
|
||||
PrivateBin.Editor.focusInput();
|
||||
@@ -45,22 +45,22 @@ describe('Editor', function () {
|
||||
);
|
||||
PrivateBin.Editor.setText(text);
|
||||
results.push(
|
||||
PrivateBin.Editor.getText() === $('#message').val()
|
||||
PrivateBin.Editor.getText() === document.getElementById('message').value
|
||||
);
|
||||
PrivateBin.Editor.setText();
|
||||
results.push(
|
||||
!PrivateBin.Editor.isPreview() &&
|
||||
!$('#message').hasClass('hidden')
|
||||
!document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
$('#messagepreview').trigger('click');
|
||||
document.getElementById('messagepreview').click();
|
||||
results.push(
|
||||
PrivateBin.Editor.isPreview() &&
|
||||
$('#message').hasClass('hidden')
|
||||
document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
$('#messageedit').trigger('click');
|
||||
document.getElementById('messageedit').click();
|
||||
results.push(
|
||||
!PrivateBin.Editor.isPreview() &&
|
||||
!$('#message').hasClass('hidden')
|
||||
!document.getElementById('message').classList.contains('hidden')
|
||||
);
|
||||
clean();
|
||||
return results.every(element => element);
|
||||
|
||||
@@ -73,6 +73,12 @@ describe('Helper', function () {
|
||||
});
|
||||
|
||||
describe('urls2links', function () {
|
||||
function getTextAsRenderedHtml(stringContent) {
|
||||
const tempDiv = document.createElement('div');
|
||||
tempDiv.textContent = stringContent;
|
||||
return tempDiv.innerHTML;
|
||||
}
|
||||
|
||||
this.timeout(30000);
|
||||
before(function () {
|
||||
cleanup = globalThis.cleanup();
|
||||
@@ -85,11 +91,11 @@ describe('Helper', function () {
|
||||
// eslint-disable-next-line no-control-regex
|
||||
content = content.replace(/\r|\f/g, '\n').replace(/\u0000|\u000b/g, '');
|
||||
let clean = globalThis.cleanup();
|
||||
$('body').html('<div id="foo"></div>');
|
||||
let e = $('#foo');
|
||||
e.text(content);
|
||||
PrivateBin.Helper.urls2links(e[0]);
|
||||
let result = e.text();
|
||||
document.body.innerHTML = '<div id="foo"></div>';
|
||||
let e = document.getElementById('foo');
|
||||
e.textContent = content;
|
||||
PrivateBin.Helper.urls2links(e);
|
||||
let result = e.textContent;
|
||||
clean();
|
||||
return content === result;
|
||||
}
|
||||
@@ -108,8 +114,8 @@ describe('Helper', function () {
|
||||
url.fragment = fragment.join('');
|
||||
let urlString = common.urlToString(url),
|
||||
clean = globalThis.cleanup();
|
||||
$('body').html('<div id="foo"></div>');
|
||||
let e = $('#foo');
|
||||
document.body.innerHTML = '<div id="foo"></div>';
|
||||
let e = document.getElementById('foo');
|
||||
|
||||
// special cases: When the query string and fragment imply the beginning of an HTML entity, eg. � or &#x
|
||||
if (
|
||||
@@ -120,12 +126,14 @@ describe('Helper', function () {
|
||||
urlString = common.urlToString(url);
|
||||
postfix = '';
|
||||
}
|
||||
e.text(prefix + urlString + postfix);
|
||||
PrivateBin.Helper.urls2links(e[0]);
|
||||
let result = e.html();
|
||||
e.textContent = prefix + urlString + postfix;
|
||||
PrivateBin.Helper.urls2links(e);
|
||||
|
||||
let result = e.innerHTML;
|
||||
clean();
|
||||
urlString = $('<div />').text(urlString).html();
|
||||
const expected = $('<div />').text(prefix).html() + '<a href="' + urlString + '" target="_blank" rel="nofollow noopener noreferrer">' + urlString + '</a>' + $('<div />').text(postfix).html();
|
||||
|
||||
urlString = getTextAsRenderedHtml(urlString);
|
||||
const expected = getTextAsRenderedHtml(prefix) + '<a href="' + urlString + '" target="_blank" rel="nofollow noopener noreferrer">' + urlString + '</a>' + getTextAsRenderedHtml(postfix);
|
||||
return expected === result;
|
||||
}
|
||||
);
|
||||
@@ -141,14 +149,14 @@ describe('Helper', function () {
|
||||
postfix = ' ' + postfix.replace(/\r/g, '\n').replace(/\u0000/g, '');
|
||||
let url = 'magnet:?' + query.join('').replace(/^&+|&+$/gm, ''),
|
||||
clean = globalThis.cleanup();
|
||||
$('body').html('<div id="foo"></div>');
|
||||
let e = $('#foo');
|
||||
e.text(prefix + url + postfix);
|
||||
PrivateBin.Helper.urls2links(e[0]);
|
||||
let result = e.html();
|
||||
document.body.innerHTML = '<div id="foo"></div>';
|
||||
let e = document.getElementById('foo');
|
||||
e.textContent = prefix + url + postfix;
|
||||
PrivateBin.Helper.urls2links(e);
|
||||
let result = e.innerHTML;
|
||||
clean();
|
||||
url = $('<div />').text(url).html();
|
||||
return $('<div />').text(prefix).html() + '<a href="' + url + '" target="_blank" rel="nofollow noopener noreferrer">' + url + '</a>' + $('<div />').text(postfix).html() === result;
|
||||
url = getTextAsRenderedHtml(url);
|
||||
return getTextAsRenderedHtml(prefix) + '<a href="' + url + '" target="_blank" rel="nofollow noopener noreferrer">' + url + '</a>' + getTextAsRenderedHtml(postfix) === result;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -99,21 +99,24 @@ describe('I18n', function () {
|
||||
prefix = prefix.replace(/%(s|d)/g, '%%').replace(/<a/g, '');
|
||||
params[0] = params[0].replace(/%(s|d)/g, '%%');
|
||||
postfix = postfix.replace(/%(s|d)/g, '%%').replace(/<a/g, '');
|
||||
const translation = $('<textarea>').text((prefix + params[0] + postfix)).text();
|
||||
const tempDiv = document.createElement('textarea');
|
||||
tempDiv.textContent = (prefix + params[0] + postfix);
|
||||
const translation = tempDiv.textContent;
|
||||
let args = Array.prototype.slice.call(params);
|
||||
args.unshift(prefix + '%s' + postfix);
|
||||
let clean = globalThis.cleanup();
|
||||
$('body').html('<div id="i18n"></div>');
|
||||
args.unshift($('#i18n'));
|
||||
document.body.innerHTML = '<div id="i18n"></div>';
|
||||
const i18nElement = document.getElementById('i18n');
|
||||
args.unshift(i18nElement);
|
||||
PrivateBin.I18n.translate.apply(this, args);
|
||||
const result = $('#i18n').text();
|
||||
const result = i18nElement.textContent;
|
||||
PrivateBin.I18n.reset();
|
||||
clean();
|
||||
clean = globalThis.cleanup();
|
||||
$('body').html('<div id="i18n"></div>');
|
||||
args[0] = $('#i18n');
|
||||
document.body.innerHTML = '<div id="i18n"></div>';
|
||||
args[0] = document.getElementById('i18n');
|
||||
PrivateBin.I18n._.apply(this, args);
|
||||
const alias = $('#i18n').text();
|
||||
const alias = document.getElementById('i18n').textContent;
|
||||
PrivateBin.I18n.reset();
|
||||
clean();
|
||||
return translation === result && translation === alias;
|
||||
@@ -138,17 +141,18 @@ describe('I18n', function () {
|
||||
let args = Array.prototype.slice.call(params);
|
||||
args.unshift(prefix + '<a href="%s"></a>' + postfix);
|
||||
let clean = globalThis.cleanup();
|
||||
$('body').html('<div id="i18n"></div>');
|
||||
args.unshift($('#i18n'));
|
||||
document.body.innerHTML = '<div id="i18n"></div>';
|
||||
const i18nElement2 = document.getElementById('i18n');
|
||||
args.unshift(i18nElement2);
|
||||
PrivateBin.I18n.translate.apply(this, args);
|
||||
const result = $('#i18n').html();
|
||||
const result = i18nElement2.innerHTML;
|
||||
PrivateBin.I18n.reset();
|
||||
clean();
|
||||
clean = globalThis.cleanup();
|
||||
$('body').html('<div id="i18n"></div>');
|
||||
args[0] = $('#i18n');
|
||||
document.body.innerHTML = '<div id="i18n"></div>';
|
||||
args[0] = document.getElementById('i18n');
|
||||
PrivateBin.I18n._.apply(this, args);
|
||||
const alias = $('#i18n').html();
|
||||
const alias = document.getElementById('i18n').innerHTML;
|
||||
PrivateBin.I18n.reset();
|
||||
clean();
|
||||
return translation === result && translation === alias;
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('Model', function () {
|
||||
contents += '>' + value + '</option>';
|
||||
});
|
||||
contents += '</select>';
|
||||
$('body').html(contents);
|
||||
document.body.innerHTML = contents;
|
||||
var result = PrivateBin.Helper.htmlEntities(
|
||||
PrivateBin.Model.getExpirationDefault()
|
||||
);
|
||||
@@ -62,7 +62,7 @@ describe('Model', function () {
|
||||
contents += '>' + value + '</option>';
|
||||
});
|
||||
contents += '</select>';
|
||||
$('body').html(contents);
|
||||
document.body.innerHTML = contents;
|
||||
var result = PrivateBin.Helper.htmlEntities(
|
||||
PrivateBin.Model.getFormatDefault()
|
||||
);
|
||||
@@ -226,14 +226,17 @@ describe('Model', function () {
|
||||
element = 'p';
|
||||
}
|
||||
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="templates"><' + element + ' id="' + id +
|
||||
'template">' + value + '</' + element + '></div>'
|
||||
);
|
||||
PrivateBin.Model.init();
|
||||
var template = '<' + element + ' id="' + id + '">' + value +
|
||||
'</' + element + '>',
|
||||
result = PrivateBin.Model.getTemplate(id).wrap('<p/>').parent().html();
|
||||
templateEl = PrivateBin.Model.getTemplate(id),
|
||||
wrapper = document.createElement('p');
|
||||
wrapper.appendChild(templateEl.cloneNode(true));
|
||||
var result = wrapper.innerHTML;
|
||||
PrivateBin.Model.reset();
|
||||
return template === result;
|
||||
}
|
||||
|
||||
@@ -24,13 +24,13 @@ describe('PasteStatus', function () {
|
||||
|
||||
it('creates a notification after a successful document upload', function () {
|
||||
cleanup();
|
||||
$('body').html('<a href="#" id="deletelink"><span></span></a><div id="pastelink"></div>');
|
||||
document.body.innerHTML = '<a href="#" id="deletelink"><span></span></a><div id="pastelink"></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
const expected1 = 'https://example.com/long';
|
||||
const expected2 = 'https://example.com/short';
|
||||
PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
|
||||
const result1 = $('#pasteurl')[0].href,
|
||||
result2 = $('#deletelink')[0].href;
|
||||
const result1 = document.getElementById('pasteurl').href,
|
||||
result2 = document.getElementById('deletelink').href;
|
||||
assert.strictEqual(result1, expected1);
|
||||
assert.strictEqual(result2, expected2);
|
||||
});
|
||||
@@ -47,11 +47,11 @@ describe('PasteStatus', function () {
|
||||
const expected1 = common.urlToString(url1).replace(/&(gt|lt)$/, '&$1a'),
|
||||
expected2 = common.urlToString(url2).replace(/&(gt|lt)$/, '&$1a');
|
||||
cleanup();
|
||||
$('body').html('<a href="#" id="deletelink"><span></span></a><div id="pastelink"></div>');
|
||||
document.body.innerHTML = '<a href="#" id="deletelink"><span></span></a><div id="pastelink"></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.createPasteNotification(expected1, expected2);
|
||||
const result1 = $('#pasteurl')[0].href,
|
||||
result2 = $('#deletelink')[0].href;
|
||||
const result1 = document.getElementById('pasteurl').href,
|
||||
result2 = document.getElementById('deletelink').href;
|
||||
return result1 === expected1 && result2 === expected2;
|
||||
|
||||
}
|
||||
@@ -78,12 +78,12 @@ describe('PasteStatus', function () {
|
||||
expected = urlString.substring((schema + '://' + domain).length),
|
||||
clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<div><div id="pastelink"></div></div>');
|
||||
document.body.innerHTML = '<div><div id="pastelink"></div></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.createPasteNotification('', '');
|
||||
PrivateBin.PasteStatus.extractUrl(urlString);
|
||||
|
||||
const result = $('#pasteurl')[0].href;
|
||||
const result = document.getElementById('pasteurl').href;
|
||||
clean();
|
||||
|
||||
return result.endsWith(expected) && (
|
||||
@@ -117,12 +117,12 @@ describe('PasteStatus', function () {
|
||||
},
|
||||
clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<div><div id="pastelink"></div></div>');
|
||||
document.body.innerHTML = '<div><div id="pastelink"></div></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.createPasteNotification('', '');
|
||||
PrivateBin.PasteStatus.extractUrl(JSON.stringify(yourlsResponse, undefined, 4));
|
||||
|
||||
const result = $('#pasteurl')[0].href;
|
||||
const result = document.getElementById('pasteurl').href;
|
||||
clean();
|
||||
|
||||
return result === shortUrlString;
|
||||
@@ -144,12 +144,12 @@ describe('PasteStatus', function () {
|
||||
'</result>',
|
||||
clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<div><div id="pastelink"></div></div>');
|
||||
document.body.innerHTML = '<div><div id="pastelink"></div></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.createPasteNotification('', '');
|
||||
PrivateBin.PasteStatus.extractUrl(yourlsResponse);
|
||||
|
||||
const result = $('#pasteurl')[0].href;
|
||||
const result = document.getElementById('pasteurl').href;
|
||||
clean();
|
||||
|
||||
return result === shortUrlString;
|
||||
@@ -176,12 +176,12 @@ describe('PasteStatus', function () {
|
||||
'</html>',
|
||||
clean = globalThis.cleanup();
|
||||
|
||||
$('body').html('<div><div id="pastelink"></div></div>');
|
||||
document.body.innerHTML = '<div><div id="pastelink"></div></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.createPasteNotification('', '');
|
||||
PrivateBin.PasteStatus.extractUrl(yourlsResponse);
|
||||
|
||||
const result = $('#pasteurl')[0].href;
|
||||
const result = document.getElementById('pasteurl').href;
|
||||
clean();
|
||||
|
||||
return result === shortUrlString;
|
||||
@@ -200,7 +200,7 @@ describe('PasteStatus', function () {
|
||||
function (burnafterreading, remainingTime, url) {
|
||||
let clean = globalThis.cleanup('', {url: common.urlToString(url)}),
|
||||
result;
|
||||
$('body').html('<div id="remainingtime" class="hidden"></div>');
|
||||
document.body.innerHTML = '<div id="remainingtime" class="hidden"></div>';
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.showRemainingTime(PrivateBin.Helper.PasteFactory({
|
||||
'adata': [null, null, null, burnafterreading],
|
||||
@@ -210,14 +210,14 @@ describe('PasteStatus', function () {
|
||||
}
|
||||
}));
|
||||
if (burnafterreading) {
|
||||
result = $('#remainingtime').hasClass('foryoureyesonly') &&
|
||||
!$('#remainingtime').hasClass('hidden');
|
||||
result = document.getElementById('remainingtime').classList.contains('foryoureyesonly') &&
|
||||
!document.getElementById('remainingtime').classList.contains('hidden');
|
||||
} else if (remainingTime) {
|
||||
result =!$('#remainingtime').hasClass('foryoureyesonly') &&
|
||||
!$('#remainingtime').hasClass('hidden');
|
||||
result =!document.getElementById('remainingtime').classList.contains('foryoureyesonly') &&
|
||||
!document.getElementById('remainingtime').classList.contains('hidden');
|
||||
} else {
|
||||
result = $('#remainingtime').hasClass('hidden') &&
|
||||
!$('#remainingtime').hasClass('foryoureyesonly');
|
||||
result = document.getElementById('remainingtime').classList.contains('hidden') &&
|
||||
!document.getElementById('remainingtime').classList.contains('foryoureyesonly');
|
||||
}
|
||||
clean();
|
||||
return result;
|
||||
@@ -229,13 +229,13 @@ describe('PasteStatus', function () {
|
||||
it(
|
||||
'hides all messages',
|
||||
function() {
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="remainingtime"></div><div id="pastesuccess"></div>'
|
||||
);
|
||||
PrivateBin.PasteStatus.init();
|
||||
PrivateBin.PasteStatus.hideMessages();
|
||||
assert.ok($('#remainingtime').hasClass('hidden'));
|
||||
assert.ok($('#pastesuccess').hasClass('hidden'));
|
||||
assert.ok(document.getElementById('remainingtime').classList.contains('hidden'));
|
||||
assert.ok(document.getElementById('pastesuccess').classList.contains('hidden'));
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
@@ -7,7 +7,7 @@ describe('PasteViewer', function () {
|
||||
|
||||
it('basic plaintext display works', function () {
|
||||
cleanup();
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="placeholder" class="hidden">+++ no document text +++</div>' +
|
||||
'<div id="prettymessage" class="hidden"><pre id="prettyprint" class="prettyprint linenums:1"></pre></div>' +
|
||||
'<div id="plaintext" class="hidden"></div>'
|
||||
@@ -17,7 +17,7 @@ describe('PasteViewer', function () {
|
||||
PrivateBin.PasteViewer.setText('hello');
|
||||
PrivateBin.PasteViewer.run();
|
||||
assert.strictEqual(PrivateBin.PasteViewer.getText(), 'hello');
|
||||
assert.ok(!$('#plaintext').hasClass('hidden'));
|
||||
assert.ok(!document.getElementById('plaintext').classList.contains('hidden'));
|
||||
});
|
||||
|
||||
jsc.property(
|
||||
@@ -27,7 +27,7 @@ describe('PasteViewer', function () {
|
||||
function (format, text) {
|
||||
cleanup();
|
||||
var results = [];
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="placeholder" class="hidden">+++ no document text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden"><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
@@ -37,40 +37,40 @@ describe('PasteViewer', function () {
|
||||
PrivateBin.PasteViewer.setFormat(format);
|
||||
PrivateBin.PasteViewer.setText('');
|
||||
results.push(
|
||||
$('#placeholder').hasClass('hidden') &&
|
||||
$('#prettymessage').hasClass('hidden') &&
|
||||
$('#plaintext').hasClass('hidden') &&
|
||||
document.getElementById('placeholder').classList.contains('hidden') &&
|
||||
document.getElementById('prettymessage').classList.contains('hidden') &&
|
||||
document.getElementById('plaintext').classList.contains('hidden') &&
|
||||
PrivateBin.PasteViewer.getFormat() === format &&
|
||||
PrivateBin.PasteViewer.getText() === ''
|
||||
);
|
||||
PrivateBin.PasteViewer.run();
|
||||
results.push(
|
||||
!$('#placeholder').hasClass('hidden') &&
|
||||
$('#prettymessage').hasClass('hidden') &&
|
||||
$('#plaintext').hasClass('hidden')
|
||||
!document.getElementById('placeholder').classList.contains('hidden') &&
|
||||
document.getElementById('prettymessage').classList.contains('hidden') &&
|
||||
document.getElementById('plaintext').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.PasteViewer.hide();
|
||||
results.push(
|
||||
$('#placeholder').hasClass('hidden') &&
|
||||
$('#prettymessage').hasClass('hidden') &&
|
||||
$('#plaintext').hasClass('hidden')
|
||||
document.getElementById('placeholder').classList.contains('hidden') &&
|
||||
document.getElementById('prettymessage').classList.contains('hidden') &&
|
||||
document.getElementById('plaintext').classList.contains('hidden')
|
||||
);
|
||||
PrivateBin.PasteViewer.setText(text);
|
||||
PrivateBin.PasteViewer.run();
|
||||
results.push(
|
||||
$('#placeholder').hasClass('hidden') &&
|
||||
document.getElementById('placeholder').classList.contains('hidden') &&
|
||||
!PrivateBin.PasteViewer.isPrettyPrinted() &&
|
||||
PrivateBin.PasteViewer.getText() === text
|
||||
);
|
||||
if (format === 'markdown') {
|
||||
results.push(
|
||||
$('#prettymessage').hasClass('hidden') &&
|
||||
!$('#plaintext').hasClass('hidden')
|
||||
document.getElementById('prettymessage').classList.contains('hidden') &&
|
||||
!document.getElementById('plaintext').classList.contains('hidden')
|
||||
);
|
||||
} else {
|
||||
results.push(
|
||||
!$('#prettymessage').hasClass('hidden') &&
|
||||
$('#plaintext').hasClass('hidden')
|
||||
!document.getElementById('prettymessage').classList.contains('hidden') &&
|
||||
document.getElementById('plaintext').classList.contains('hidden')
|
||||
);
|
||||
}
|
||||
clean();
|
||||
@@ -114,7 +114,7 @@ describe('PasteViewer', function () {
|
||||
function (format, prefix, xss, suffix) {
|
||||
var clean = globalThis.cleanup(),
|
||||
text = prefix + xss + suffix;
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="placeholder" class="hidden">+++ no document text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden"><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
@@ -124,7 +124,7 @@ describe('PasteViewer', function () {
|
||||
PrivateBin.PasteViewer.setFormat(format);
|
||||
PrivateBin.PasteViewer.setText(text);
|
||||
PrivateBin.PasteViewer.run();
|
||||
var result = $('body').html().indexOf(xss) === -1;
|
||||
var result = document.body.innerHTML.indexOf(xss) === -1;
|
||||
clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@ describe('Prompt', function () {
|
||||
function (password) {
|
||||
password = password.replace(/\r+|\n+/g, '');
|
||||
const clean = globalThis.cleanup('', {url: 'ftp://example.com/?0000000000000000'});
|
||||
$('body').html(
|
||||
document.body.innerHTML = (
|
||||
'<div id="passwordmodal" class="modal fade" role="dialog">' +
|
||||
'<div class="modal-dialog"><div class="modal-content">' +
|
||||
'<div class="modal-body"><form id="passwordform" role="form">' +
|
||||
@@ -20,8 +20,9 @@ describe('Prompt', function () {
|
||||
'password"></div><button type="submit">Decrypt</button>' +
|
||||
'</form></div></div></div></div>'
|
||||
);
|
||||
$('#passworddecrypt').val(password);
|
||||
const result = $('#passworddecrypt').val();
|
||||
const passwordInput = document.getElementById('passworddecrypt');
|
||||
passwordInput.value = password;
|
||||
const result = passwordInput.value;
|
||||
clean();
|
||||
return result === password;
|
||||
}
|
||||
|
||||
@@ -334,15 +334,16 @@ describe('TopNav', function () {
|
||||
with the upgrade for bootstrap-3.3.7.js to bootstrap-3.4.1.js
|
||||
the mobile interface detection changed to check if the
|
||||
ontouchstart event exists, which broke this section of the test
|
||||
$('.navbar-toggle').trigger('click');
|
||||
const toggleBtn = document.querySelector('.navbar-toggle');
|
||||
toggleBtn.dispatchEvent(new MouseEvent('click'));
|
||||
results.push(
|
||||
!$('.navbar-toggle').hasClass('collapsed') &&
|
||||
$('#navbar').attr('aria-expanded') == 'true'
|
||||
!toggleBtn.classList.contains('collapsed') &&
|
||||
document.getElementById('navbar').getAttribute('aria-expanded') == 'true'
|
||||
);
|
||||
PrivateBin.TopNav.collapseBar();
|
||||
results.push(
|
||||
$('.navbar-toggle').hasClass('collapsed') &&
|
||||
$('#navbar').attr('aria-expanded') == 'false'
|
||||
document.querySelector('.navbar-toggle').classList.contains('collapsed') &&
|
||||
document.getElementById('navbar').getAttribute('aria-expanded') == 'false'
|
||||
);
|
||||
*/
|
||||
const result = results.every(element => element);
|
||||
|
||||
@@ -91,7 +91,7 @@ describe('UiHelper', function () {
|
||||
var clean = globalThis.cleanup(
|
||||
'<' + element + ' id="' + id + '"></' + element + '>'
|
||||
);
|
||||
var result = PrivateBin.UiHelper.isVisible($('#' + id));
|
||||
var result = PrivateBin.UiHelper.isVisible(document.getElementById(id));
|
||||
clean();
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user