mirror of
https://gitee.com/la-vie/console-pro-free.git
synced 2025-11-03 12:56:51 +00:00
first commit
This commit is contained in:
69
console-pro/node_modules/clipboard/test/actions/copy.js
generated
vendored
Normal file
69
console-pro/node_modules/clipboard/test/actions/copy.js
generated
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
import ClipboardActionCopy from '../../src/actions/copy';
|
||||
|
||||
describe('ClipboardActionCopy', () => {
|
||||
before(() => {
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
|
||||
global.paragraph = document.createElement('p');
|
||||
global.paragraph.setAttribute('id', 'paragraph');
|
||||
global.paragraph.textContent = 'abc';
|
||||
document.body.appendChild(global.paragraph);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#selectText', () => {
|
||||
it('should select its value based on input target', () => {
|
||||
const selectedText = ClipboardActionCopy(
|
||||
document.querySelector('#input'),
|
||||
{
|
||||
container: document.body,
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(selectedText, document.querySelector('#input').value);
|
||||
});
|
||||
|
||||
it('should select its value based on element target', () => {
|
||||
const selectedText = ClipboardActionCopy(
|
||||
document.querySelector('#paragraph'),
|
||||
{
|
||||
container: document.body,
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(
|
||||
selectedText,
|
||||
document.querySelector('#paragraph').textContent
|
||||
);
|
||||
});
|
||||
|
||||
it('should select its value based on text', () => {
|
||||
const text = 'abc';
|
||||
const selectedText = ClipboardActionCopy(text, {
|
||||
container: document.body,
|
||||
});
|
||||
|
||||
assert.equal(selectedText, text);
|
||||
});
|
||||
|
||||
it('should select its value in a input number based on text', () => {
|
||||
const value = 1;
|
||||
document.querySelector('#input').setAttribute('type', 'number');
|
||||
document.querySelector('#input').setAttribute('value', value);
|
||||
const selectedText = ClipboardActionCopy(
|
||||
document.querySelector('#input'),
|
||||
{
|
||||
container: document.body,
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(Number(selectedText), value);
|
||||
});
|
||||
});
|
||||
});
|
||||
32
console-pro/node_modules/clipboard/test/actions/cut.js
generated
vendored
Normal file
32
console-pro/node_modules/clipboard/test/actions/cut.js
generated
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
import ClipboardActionCut from '../../src/actions/cut';
|
||||
|
||||
describe('ClipboardActionCut', () => {
|
||||
before(() => {
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
|
||||
global.paragraph = document.createElement('p');
|
||||
global.paragraph.setAttribute('id', 'paragraph');
|
||||
global.paragraph.textContent = 'abc';
|
||||
document.body.appendChild(global.paragraph);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#selectText', () => {
|
||||
it('should select its value', () => {
|
||||
const selectedText = ClipboardActionCut(
|
||||
document.querySelector('#input'),
|
||||
{
|
||||
container: document.body,
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(selectedText, document.querySelector('#input').value);
|
||||
});
|
||||
});
|
||||
});
|
||||
80
console-pro/node_modules/clipboard/test/actions/default.js
generated
vendored
Normal file
80
console-pro/node_modules/clipboard/test/actions/default.js
generated
vendored
Normal file
@@ -0,0 +1,80 @@
|
||||
import ClipboardActionDefault from '../../src/actions/default';
|
||||
|
||||
describe('ClipboardActionDefault', () => {
|
||||
before(() => {
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
|
||||
global.paragraph = document.createElement('p');
|
||||
global.paragraph.setAttribute('id', 'paragraph');
|
||||
global.paragraph.textContent = 'abc';
|
||||
document.body.appendChild(global.paragraph);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#resolveOptions', () => {
|
||||
it('should set base properties', () => {
|
||||
const selectedText = ClipboardActionDefault({
|
||||
container: document.body,
|
||||
text: 'foo',
|
||||
});
|
||||
|
||||
assert.equal(selectedText, 'foo');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set action', () => {
|
||||
it('should throw an error since "action" is invalid', (done) => {
|
||||
try {
|
||||
let clip = ClipboardActionDefault({
|
||||
text: 'foo',
|
||||
action: 'paste',
|
||||
});
|
||||
} catch (e) {
|
||||
assert.equal(
|
||||
e.message,
|
||||
'Invalid "action" value, use either "copy" or "cut"'
|
||||
);
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set target', () => {
|
||||
it('should throw an error since "target" do not match any element', (done) => {
|
||||
try {
|
||||
let clip = ClipboardActionDefault({
|
||||
target: document.querySelector('#foo'),
|
||||
});
|
||||
} catch (e) {
|
||||
assert.equal(e.message, 'Invalid "target" value, use a valid Element');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectedText', () => {
|
||||
it('should select text from editable element', () => {
|
||||
const selectedText = ClipboardActionDefault({
|
||||
container: document.body,
|
||||
target: document.querySelector('#input'),
|
||||
});
|
||||
|
||||
assert.equal(selectedText, 'abc');
|
||||
});
|
||||
|
||||
it('should select text from non-editable element', () => {
|
||||
const selectedText = ClipboardActionDefault({
|
||||
container: document.body,
|
||||
target: document.querySelector('#paragraph'),
|
||||
});
|
||||
|
||||
assert.equal(selectedText, 'abc');
|
||||
});
|
||||
});
|
||||
});
|
||||
192
console-pro/node_modules/clipboard/test/clipboard.js
generated
vendored
Normal file
192
console-pro/node_modules/clipboard/test/clipboard.js
generated
vendored
Normal file
@@ -0,0 +1,192 @@
|
||||
import Clipboard from '../src/clipboard';
|
||||
|
||||
describe('Clipboard', () => {
|
||||
before(() => {
|
||||
global.button = document.createElement('button');
|
||||
global.button.setAttribute('class', 'btn');
|
||||
global.button.setAttribute('data-clipboard-text', 'foo');
|
||||
document.body.appendChild(global.button);
|
||||
|
||||
global.span = document.createElement('span');
|
||||
global.span.innerHTML = 'bar';
|
||||
|
||||
global.button.appendChild(span);
|
||||
|
||||
global.event = {
|
||||
target: global.button,
|
||||
currentTarget: global.button,
|
||||
};
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
describe('#resolveOptions', () => {
|
||||
before(() => {
|
||||
global.fn = () => {};
|
||||
});
|
||||
|
||||
it('should set action as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
action: global.fn,
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.action);
|
||||
});
|
||||
|
||||
it('should set target as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
target: global.fn,
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.target);
|
||||
});
|
||||
|
||||
it('should set text as a function', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
text: global.fn,
|
||||
});
|
||||
|
||||
assert.equal(global.fn, clipboard.text);
|
||||
});
|
||||
|
||||
it('should set container as an object', () => {
|
||||
let clipboard = new Clipboard('.btn', {
|
||||
container: document.body,
|
||||
});
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
|
||||
it('should set container as body by default', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
assert.equal(document.body, clipboard.container);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#listenClick', () => {
|
||||
it('should add a click event listener to the passed selector', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
assert.isObject(clipboard.listener);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#onClick', () => {
|
||||
it('should init when called', (done) => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.on('success', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
});
|
||||
|
||||
it("should use an event's currentTarget when not equal to target", (done) => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
let bubbledEvent = {
|
||||
target: global.span,
|
||||
currentTarget: global.button,
|
||||
};
|
||||
|
||||
clipboard.on('success', () => {
|
||||
done();
|
||||
});
|
||||
|
||||
clipboard.onClick(bubbledEvent);
|
||||
});
|
||||
|
||||
it('should throw an exception when target is invalid', (done) => {
|
||||
try {
|
||||
const clipboard = new Clipboard('.btn', {
|
||||
target() {
|
||||
return null;
|
||||
},
|
||||
});
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
} catch (e) {
|
||||
assert.equal(e.message, 'Invalid "target" value, use a valid Element');
|
||||
done();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('#static isSupported', () => {
|
||||
it('should return the support of the given action', () => {
|
||||
assert.equal(Clipboard.isSupported('copy'), true);
|
||||
assert.equal(Clipboard.isSupported('cut'), true);
|
||||
});
|
||||
|
||||
it('should return the support of the cut and copy actions', () => {
|
||||
assert.equal(Clipboard.isSupported(), true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#static copy', () => {
|
||||
it('should copy in an programatic way based on text', () => {
|
||||
assert.equal(Clipboard.copy('lorem'), 'lorem');
|
||||
});
|
||||
|
||||
it('should copy in an programatic way based on target', () => {
|
||||
assert.equal(Clipboard.copy(document.querySelector('span')), 'bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#static cut', () => {
|
||||
it('should cut in an programatic way based on text', () => {
|
||||
assert.equal(Clipboard.cut(document.querySelector('span')), 'bar');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#destroy', () => {
|
||||
it('should destroy an existing instance of ClipboardActionDefault', () => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
clipboard.destroy();
|
||||
|
||||
assert.equal(clipboard.clipboardAction, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#events', () => {
|
||||
it('should fire a success event with certain properties', (done) => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.on('success', (e) => {
|
||||
assert.property(e, 'action');
|
||||
assert.equal(e.action, 'copy');
|
||||
assert.property(e, 'text');
|
||||
assert.property(e, 'trigger');
|
||||
assert.property(e, 'clearSelection');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clearSelection', () => {
|
||||
it('should clear text selection without moving focus', (done) => {
|
||||
let clipboard = new Clipboard('.btn');
|
||||
|
||||
clipboard.on('success', (e) => {
|
||||
e.clearSelection();
|
||||
|
||||
let selectedElem = document.activeElement;
|
||||
let selectedText = window.getSelection().toString();
|
||||
|
||||
assert.equal(selectedElem, e.trigger);
|
||||
assert.equal(selectedText, '');
|
||||
|
||||
done();
|
||||
});
|
||||
|
||||
clipboard.onClick(global.event);
|
||||
});
|
||||
});
|
||||
});
|
||||
49
console-pro/node_modules/clipboard/test/common/command.js
generated
vendored
Normal file
49
console-pro/node_modules/clipboard/test/common/command.js
generated
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
import select from 'select';
|
||||
import command from '../../src/common/command';
|
||||
|
||||
describe('#command', () => {
|
||||
before(() => {
|
||||
global.stub = sinon.stub(document, 'execCommand');
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
global.stub.restore();
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
it('should execute cut', (done) => {
|
||||
global.stub.returns(true);
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isTrue(command('cut'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should execute copy', (done) => {
|
||||
global.stub.returns(true);
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isTrue(command('copy'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should not execute copy', (done) => {
|
||||
global.stub.returns(false);
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isFalse(command('copy'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should not execute cut', (done) => {
|
||||
global.stub.returns(false);
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isFalse(command('cut'));
|
||||
done();
|
||||
});
|
||||
});
|
||||
13
console-pro/node_modules/clipboard/test/common/create-fake-element.js
generated
vendored
Normal file
13
console-pro/node_modules/clipboard/test/common/create-fake-element.js
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
import createFakeElement from '../../src/common/create-fake-element';
|
||||
|
||||
describe('createFakeElement', () => {
|
||||
it('should define a fake element and set the position right style property', (done) => {
|
||||
// Set document direction
|
||||
document.documentElement.setAttribute('dir', 'rtl');
|
||||
|
||||
const el = createFakeElement(document.body);
|
||||
|
||||
assert.equal(el.style.right, '-9999px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user