command.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import select from 'select';
  2. import command from '../../src/common/command';
  3. describe('#command', () => {
  4. before(() => {
  5. global.stub = sinon.stub(document, 'execCommand');
  6. global.input = document.createElement('input');
  7. global.input.setAttribute('id', 'input');
  8. global.input.setAttribute('value', 'abc');
  9. document.body.appendChild(global.input);
  10. });
  11. after(() => {
  12. global.stub.restore();
  13. document.body.innerHTML = '';
  14. });
  15. it('should execute cut', (done) => {
  16. global.stub.returns(true);
  17. select(document.querySelector('#input'));
  18. assert.isTrue(command('cut'));
  19. done();
  20. });
  21. it('should execute copy', (done) => {
  22. global.stub.returns(true);
  23. select(document.querySelector('#input'));
  24. assert.isTrue(command('copy'));
  25. done();
  26. });
  27. it('should not execute copy', (done) => {
  28. global.stub.returns(false);
  29. select(document.querySelector('#input'));
  30. assert.isFalse(command('copy'));
  31. done();
  32. });
  33. it('should not execute cut', (done) => {
  34. global.stub.returns(false);
  35. select(document.querySelector('#input'));
  36. assert.isFalse(command('cut'));
  37. done();
  38. });
  39. });