mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2026-04-20 22:05:35 -04:00
update jsdom dependency, fix tests
This commit is contained in:
+114
-98
@@ -4,120 +4,136 @@ const common = require('../common');
|
||||
describe('CopyToClipboard', function() {
|
||||
this.timeout(30000);
|
||||
|
||||
describe ('Copy paste co clipboard', function () {
|
||||
jsc.property('Copy with button click', common.jscFormats(), 'nestring', async function (format, text) {
|
||||
var clean = jsdom();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html(
|
||||
'<div id="placeholder" class="hidden">+++ no paste text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
'<svg id="copySuccessIcon"></svg></button><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
'</div><div id="plaintext" class="hidden"></div>'
|
||||
);
|
||||
|
||||
$.PrivateBin.PasteViewer.init();
|
||||
$.PrivateBin.PasteViewer.setFormat(format);
|
||||
$.PrivateBin.PasteViewer.setText(text);
|
||||
$.PrivateBin.PasteViewer.run();
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
|
||||
$('#prettyMessageCopyBtn').trigger('click');
|
||||
describe ('Copy paste to clipboard', function () {
|
||||
jsc.property('Copy with button click',
|
||||
common.jscFormats(),
|
||||
'nestring',
|
||||
async function (format, text) {
|
||||
var clean = jsdom();
|
||||
common.enableClipboard();
|
||||
|
||||
const savedToClipboardText = await navigator.clipboard.readText();
|
||||
|
||||
clean();
|
||||
|
||||
return text === savedToClipboardText;
|
||||
});
|
||||
$('body').html(
|
||||
'<div id="placeholder" class="hidden">+++ no paste text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
'<svg id="copySuccessIcon"></svg></button><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
'</div><div id="plaintext" class="hidden"></div>'
|
||||
);
|
||||
|
||||
$.PrivateBin.PasteViewer.init();
|
||||
$.PrivateBin.PasteViewer.setFormat(format);
|
||||
$.PrivateBin.PasteViewer.setText(text);
|
||||
$.PrivateBin.PasteViewer.run();
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
|
||||
$('#prettyMessageCopyBtn').trigger('click');
|
||||
|
||||
const savedToClipboardText = await navigator.clipboard.readText();
|
||||
|
||||
clean();
|
||||
|
||||
return text === savedToClipboardText;
|
||||
}
|
||||
);
|
||||
|
||||
/**
|
||||
* Unfortunately in JSVerify impossible to check if copy with shortcut when user selected some text on the page
|
||||
* (the copy paste to clipboard should not work in this case) due to lucking window.getSelection() in jsdom.
|
||||
* (the copy paste to clipboard should not work in this case) due to lacking window.getSelection() in jsdom.
|
||||
*/
|
||||
jsc.property('Copy with keyboard shortcut', common.jscFormats(), 'nestring', async function (format, text) {
|
||||
jsc.property('Copy with keyboard shortcut',
|
||||
common.jscFormats(),
|
||||
'nestring',
|
||||
async function (format, text) {
|
||||
var clean = jsdom();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html(
|
||||
'<div id="placeholder">+++ no paste text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
'<svg id="copySuccessIcon"></svg></button><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
'</div><div id="plaintext" class="hidden"></div>'
|
||||
);
|
||||
|
||||
$.PrivateBin.PasteViewer.init();
|
||||
$.PrivateBin.PasteViewer.setFormat(format);
|
||||
$.PrivateBin.PasteViewer.setText(text);
|
||||
$.PrivateBin.PasteViewer.run();
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
|
||||
$('body').trigger('copy');
|
||||
|
||||
const copiedTextWithoutSelectedText = await navigator.clipboard.readText();
|
||||
|
||||
clean();
|
||||
|
||||
return copiedTextWithoutSelectedText === text;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
jsc.property('Copy link to clipboard',
|
||||
'nestring',
|
||||
async function (text) {
|
||||
var clean = jsdom();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html(
|
||||
'<div id="placeholder">+++ no paste text ' +
|
||||
'+++</div><div id="prettymessage" class="hidden">' +
|
||||
'<button type="button" id="prettyMessageCopyBtn"><svg id="copyIcon"></svg>' +
|
||||
'<svg id="copySuccessIcon"></svg></button><pre ' +
|
||||
'id="prettyprint" class="prettyprint linenums:1"></pre>' +
|
||||
'</div><div id="plaintext" class="hidden"></div>'
|
||||
);
|
||||
|
||||
$.PrivateBin.PasteViewer.init();
|
||||
$.PrivateBin.PasteViewer.setFormat(format);
|
||||
$.PrivateBin.PasteViewer.setText(text);
|
||||
$.PrivateBin.PasteViewer.run();
|
||||
|
||||
|
||||
$('body').html('<button id="copyLink"></button>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.setUrl(text);
|
||||
|
||||
$('body').trigger('copy');
|
||||
$('#copyLink').trigger('click');
|
||||
|
||||
const copiedTextWithoutSelectedText = await navigator.clipboard.readText();
|
||||
const copiedText = await navigator.clipboard.readText();
|
||||
|
||||
clean();
|
||||
|
||||
return copiedTextWithoutSelectedText === text;
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
jsc.property('Copy link to clipboard', 'nestring', async function (text) {
|
||||
var clean = jsdom();
|
||||
common.enableClipboard();
|
||||
|
||||
$('body').html('<button id="copyLink"></button>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.setUrl(text);
|
||||
|
||||
$('#copyLink').trigger('click');
|
||||
|
||||
const copiedText = await navigator.clipboard.readText();
|
||||
|
||||
clean();
|
||||
|
||||
return text === copiedText;
|
||||
});
|
||||
return text === copiedText;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
describe('Keyboard shortcut hint', function () {
|
||||
jsc.property('Show hint', 'nestring', function (text) {
|
||||
var clean = jsdom();
|
||||
|
||||
$('body').html('<small id="copyShortcutHintText"></small>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
|
||||
clean();
|
||||
|
||||
return keyboardShortcutHint.length > 0;
|
||||
});
|
||||
jsc.property('Show hint',
|
||||
'nestring',
|
||||
function (text) {
|
||||
var clean = jsdom();
|
||||
|
||||
jsc.property('Hide hint', 'nestring', function (text) {
|
||||
var clean = jsdom();
|
||||
|
||||
$('body').html('<small id="copyShortcutHintText">' + text + '</small>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
|
||||
clean();
|
||||
|
||||
return keyboardShortcutHint.length === 0;
|
||||
});
|
||||
$('body').html('<small id="copyShortcutHintText"></small>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
|
||||
clean();
|
||||
|
||||
return keyboardShortcutHint.length > 0;
|
||||
}
|
||||
);
|
||||
|
||||
jsc.property('Hide hint',
|
||||
'nestring',
|
||||
function (text) {
|
||||
var clean = jsdom();
|
||||
|
||||
$('body').html('<small id="copyShortcutHintText">' + text + '</small>');
|
||||
|
||||
$.PrivateBin.CopyToClipboard.init();
|
||||
$.PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
|
||||
|
||||
const keyboardShortcutHint = $('#copyShortcutHintText').text();
|
||||
|
||||
clean();
|
||||
|
||||
return keyboardShortcutHint.length === 0;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user