| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- 'use strict';
- const common = require('../common');
- describe('CopyToClipboard', function() {
- this.timeout(30000);
- describe ('Copy document to clipboard', function () {
- jsc.property('Copy with button click',
- common.jscFormats(),
- 'nestring',
- async function (format, text) {
- var clean = globalThis.cleanup();
- common.enableClipboard();
- 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>' +
- '<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();
- document.getElementById('prettyMessageCopyBtn').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 document 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) {
- var clean = globalThis.cleanup();
- common.enableClipboard();
- document.body.innerHTML = (
- '<div id="placeholder">+++ no document 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();
- document.body.dispatchEvent(new Event('copy'));
- const copiedTextWithoutSelectedText = await navigator.clipboard.readText();
- clean();
- return copiedTextWithoutSelectedText === text;
- }
- );
- });
- jsc.property('Copy link to clipboard',
- 'nestring',
- async function (text) {
- var clean = globalThis.cleanup();
- common.enableClipboard();
- document.body.innerHTML = '<button id="copyLink"></button>';
- PrivateBin.CopyToClipboard.init();
- PrivateBin.CopyToClipboard.setUrl(text);
- document.getElementById('copyLink').click();
- const copiedText = await navigator.clipboard.readText();
- clean();
- return text === copiedText;
- }
- );
- describe('Keyboard shortcut hint', function () {
- jsc.property('Show hint',
- 'nestring',
- function (text) {
- var clean = globalThis.cleanup();
- document.body.innerHTML = '<small id="copyShortcutHintText"></small>';
- PrivateBin.CopyToClipboard.init();
- PrivateBin.CopyToClipboard.showKeyboardShortcutHint();
- const keyboardShortcutHint = document.getElementById('copyShortcutHintText').textContent;
- clean();
- return keyboardShortcutHint.length > 0;
- }
- );
- jsc.property('Hide hint',
- 'nestring',
- function (text) {
- var clean = globalThis.cleanup();
- document.body.innerHTML = '<small id="copyShortcutHintText">' + text + '</small>';
- PrivateBin.CopyToClipboard.init();
- PrivateBin.CopyToClipboard.hideKeyboardShortcutHint();
- const keyboardShortcutHint = document.getElementById('copyShortcutHintText').textContent;
- clean();
- return keyboardShortcutHint.length === 0;
- }
- );
- });
- });
|