Migrate clipboard-action-default to functional approach. Update tests. Add tests

This commit is contained in:
Beto Muniz
2021-04-15 00:59:47 -03:00
parent 455b7fdb0c
commit e7e38a18e0
9 changed files with 198 additions and 436 deletions

View File

@ -1,8 +1,9 @@
import select from 'select';
import command from '../../src/common/command';
describe('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');
@ -10,26 +11,39 @@ describe('command', () => {
});
after(() => {
global.stub.restore();
document.body.innerHTML = '';
});
it('should execute cut command', (done) => {
// Set document direction
document.documentElement.setAttribute('dir', 'rtl');
it('should execute cut', (done) => {
global.stub.returns(true);
select(document.querySelector('#input'));
assert.isTrue(command('cut'));
done();
});
it('should execute copy command', (done) => {
// Set document direction
document.documentElement.setAttribute('dir', 'rtl');
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();
});
});