WXL
6 天以前 871522ed7e06fd9c62a87c178d7f5c88d7853a20
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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();
  });
});