1 | import ClipboardActionCopy from '../../src/actions/copy';
|
2 |
|
3 | describe('ClipboardActionCopy', () => {
|
4 | before(() => {
|
5 | global.input = document.createElement('input');
|
6 | global.input.setAttribute('id', 'input');
|
7 | global.input.setAttribute('value', 'abc');
|
8 | document.body.appendChild(global.input);
|
9 |
|
10 | global.paragraph = document.createElement('p');
|
11 | global.paragraph.setAttribute('id', 'paragraph');
|
12 | global.paragraph.textContent = 'abc';
|
13 | document.body.appendChild(global.paragraph);
|
14 | });
|
15 |
|
16 | after(() => {
|
17 | document.body.innerHTML = '';
|
18 | });
|
19 |
|
20 | describe('#selectText', () => {
|
21 | it('should select its value based on input target', () => {
|
22 | const selectedText = ClipboardActionCopy(
|
23 | document.querySelector('#input'),
|
24 | {
|
25 | container: document.body,
|
26 | }
|
27 | );
|
28 |
|
29 | assert.equal(selectedText, document.querySelector('#input').value);
|
30 | });
|
31 |
|
32 | it('should select its value based on element target', () => {
|
33 | const selectedText = ClipboardActionCopy(
|
34 | document.querySelector('#paragraph'),
|
35 | {
|
36 | container: document.body,
|
37 | }
|
38 | );
|
39 |
|
40 | assert.equal(
|
41 | selectedText,
|
42 | document.querySelector('#paragraph').textContent
|
43 | );
|
44 | });
|
45 |
|
46 | it('should select its value based on text', () => {
|
47 | const text = 'abc';
|
48 | const selectedText = ClipboardActionCopy(text, {
|
49 | container: document.body,
|
50 | });
|
51 |
|
52 | assert.equal(selectedText, text);
|
53 | });
|
54 | });
|
55 | });
|