mirror of
https://github.com/zenorocha/clipboard.js.git
synced 2023-08-10 21:12:48 +03:00
Add/update tests
This commit is contained in:
parent
f99af48fd1
commit
f267fb88f2
55
test/clipboard-action-copy.js
Normal file
55
test/clipboard-action-copy.js
Normal file
@ -0,0 +1,55 @@
|
||||
import ClipboardActionCopy from '../src/clipboard-action-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.only('#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);
|
||||
});
|
||||
});
|
||||
});
|
32
test/clipboard-action-cut.js
Normal file
32
test/clipboard-action-cut.js
Normal file
@ -0,0 +1,32 @@
|
||||
import ClipboardActionCut from '../src/clipboard-action-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.only('#selectText', () => {
|
||||
it('should select its value', () => {
|
||||
const selectedText = ClipboardActionCut(
|
||||
document.querySelector('#input'),
|
||||
{
|
||||
container: document.body,
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(selectedText, document.querySelector('#input').value);
|
||||
});
|
||||
});
|
||||
});
|
@ -36,24 +36,6 @@ describe('ClipboardActionDefault', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#initSelection', () => {
|
||||
xit('should set the position right style property', (done) => {
|
||||
// Set document direction
|
||||
document.documentElement.setAttribute('dir', 'rtl');
|
||||
|
||||
let clip = new ClipboardActionDefault({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'foo',
|
||||
});
|
||||
|
||||
const el = clip.createFakeElement();
|
||||
|
||||
assert.equal(el.style.right, '-9999px');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('#set action', () => {
|
||||
it('should throw an error since "action" is invalid', (done) => {
|
||||
try {
|
||||
@ -84,34 +66,6 @@ describe('ClipboardActionDefault', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectText', () => {
|
||||
xit('should create a fake element and select its value', () => {
|
||||
let clip = new ClipboardActionDefault({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah',
|
||||
});
|
||||
|
||||
const el = clip.createFakeElement();
|
||||
|
||||
assert.equal(clip.selectedText, el.value);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#removeFake', () => {
|
||||
xit('should remove a temporary fake element', () => {
|
||||
let clip = new ClipboardActionDefault({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah',
|
||||
});
|
||||
|
||||
clip.removeFake();
|
||||
|
||||
assert.equal(clip.fakeElem, null);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#selectTarget', () => {
|
||||
it('should select text from editable element', () => {
|
||||
let clip = new ClipboardActionDefault({
|
||||
@ -158,9 +112,7 @@ describe('ClipboardActionDefault', () => {
|
||||
});
|
||||
});
|
||||
|
||||
xit('should fire an error event on browsers that support copy command', (done) => {
|
||||
global.stub.returns(false);
|
||||
|
||||
it('should fire an error event on browsers that support cut command', (done) => {
|
||||
let emitter = new Emitter();
|
||||
|
||||
emitter.on('error', () => {
|
||||
@ -171,6 +123,8 @@ describe('ClipboardActionDefault', () => {
|
||||
emitter,
|
||||
target: document.querySelector('#input'),
|
||||
});
|
||||
|
||||
clip.handleResult(false);
|
||||
});
|
||||
});
|
||||
|
||||
@ -230,19 +184,4 @@ describe('ClipboardActionDefault', () => {
|
||||
assert.equal(selectedText, '');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#destroy', () => {
|
||||
xit('should destroy an existing fake element', () => {
|
||||
let clip = new ClipboardActionDefault({
|
||||
emitter: new Emitter(),
|
||||
container: document.body,
|
||||
text: 'blah',
|
||||
});
|
||||
|
||||
clip.selectFake();
|
||||
clip.destroy();
|
||||
|
||||
assert.equal(clip.fakeElem, null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
35
test/common/command.js
Normal file
35
test/common/command.js
Normal file
@ -0,0 +1,35 @@
|
||||
import select from 'select';
|
||||
import command from '../../src/common/command';
|
||||
|
||||
describe('command', () => {
|
||||
before(() => {
|
||||
global.input = document.createElement('input');
|
||||
global.input.setAttribute('id', 'input');
|
||||
global.input.setAttribute('value', 'abc');
|
||||
document.body.appendChild(global.input);
|
||||
});
|
||||
|
||||
after(() => {
|
||||
document.body.innerHTML = '';
|
||||
});
|
||||
|
||||
it('should execute cut command', (done) => {
|
||||
// Set document direction
|
||||
document.documentElement.setAttribute('dir', 'rtl');
|
||||
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isTrue(command('cut'));
|
||||
done();
|
||||
});
|
||||
|
||||
it('should execute copy command', (done) => {
|
||||
// Set document direction
|
||||
document.documentElement.setAttribute('dir', 'rtl');
|
||||
|
||||
select(document.querySelector('#input'));
|
||||
|
||||
assert.isTrue(command('copy'));
|
||||
done();
|
||||
});
|
||||
});
|
13
test/common/create-fake-element.js
Normal file
13
test/common/create-fake-element.js
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();
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user