mirror of
https://github.com/PrivateBin/PrivateBin.git
synced 2025-07-20 13:39:07 -04:00
CopyToClipboard unit tests
This commit is contained in:
parent
42b7b9060d
commit
6c651ea676
3 changed files with 172 additions and 8 deletions
|
@ -5454,12 +5454,14 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|||
const CopyToClipboard = (function () {
|
||||
const me = {};
|
||||
|
||||
let copyButton = $('#prettyMessageCopyBtn'),
|
||||
copyLinkButton = $('#copyLink'),
|
||||
copyIcon = $('#copyIcon'),
|
||||
successIcon = $('#copySuccessIcon'),
|
||||
shortcutHint = $('#copyShortcutHintText'),
|
||||
url;
|
||||
let copyButton,
|
||||
copyLinkButton,
|
||||
copyIcon,
|
||||
successIcon,
|
||||
shortcutHint,
|
||||
url,
|
||||
testMode,
|
||||
testClipboard;
|
||||
|
||||
/**
|
||||
* Handle copy to clipboard button click
|
||||
|
@ -5540,7 +5542,11 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|||
* @function
|
||||
*/
|
||||
function saveToClipboard(text) {
|
||||
navigator.clipboard.writeText(text);
|
||||
if (testMode) {
|
||||
testClipboard = text;
|
||||
} else {
|
||||
navigator.clipboard.writeText(text);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -5606,6 +5612,35 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|||
url = newUrl;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enable test mode, using for unit tests
|
||||
*
|
||||
* @name CopyToClipboard.testMode
|
||||
* @function
|
||||
*/
|
||||
me.enableTestMode = function () {
|
||||
testMode = true;
|
||||
};
|
||||
|
||||
/**
|
||||
* Read text from user's clipboard
|
||||
*
|
||||
* @name CopyToClipboard.readFromClipboard
|
||||
* @function
|
||||
* @returns {string}
|
||||
*/
|
||||
me.readFromClipboard = function () {
|
||||
let clipboardData = "";
|
||||
|
||||
if (testMode) {
|
||||
clipboardData = testClipboard;
|
||||
} else {
|
||||
clipboardData = navigator.clipboard.readText();
|
||||
}
|
||||
|
||||
return clipboardData;
|
||||
};
|
||||
|
||||
/**
|
||||
* Initialize
|
||||
*
|
||||
|
@ -5613,6 +5648,12 @@ jQuery.PrivateBin = (function($, RawDeflate) {
|
|||
* @function
|
||||
*/
|
||||
me.init = function() {
|
||||
copyButton = $('#prettyMessageCopyBtn');
|
||||
copyLinkButton = $('#copyLink');
|
||||
copyIcon = $('#copyIcon');
|
||||
successIcon = $('#copySuccessIcon');
|
||||
shortcutHint = $('#copyShortcutHintText');
|
||||
|
||||
handleCopyButtonClick();
|
||||
handleCopyLinkButtonClick();
|
||||
handleKeyboardShortcut();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue