1 | import ClipboardActionDefault from '../../src/actions/default';
|
2 |
|
3 | describe('ClipboardActionDefault', () => {
|
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('#resolveOptions', () => {
|
21 | it('should set base properties', () => {
|
22 | const selectedText = ClipboardActionDefault({
|
23 | container: document.body,
|
24 | text: 'foo',
|
25 | });
|
26 |
|
27 | assert.equal(selectedText, 'foo');
|
28 | });
|
29 | });
|
30 |
|
31 | describe('#set action', () => {
|
32 | it('should throw an error since "action" is invalid', (done) => {
|
33 | try {
|
34 | let clip = ClipboardActionDefault({
|
35 | text: 'foo',
|
36 | action: 'paste',
|
37 | });
|
38 | } catch (e) {
|
39 | assert.equal(
|
40 | e.message,
|
41 | 'Invalid "action" value, use either "copy" or "cut"'
|
42 | );
|
43 | done();
|
44 | }
|
45 | });
|
46 | });
|
47 |
|
48 | describe('#set target', () => {
|
49 | it('should throw an error since "target" do not match any element', (done) => {
|
50 | try {
|
51 | let clip = ClipboardActionDefault({
|
52 | target: document.querySelector('#foo'),
|
53 | });
|
54 | } catch (e) {
|
55 | assert.equal(e.message, 'Invalid "target" value, use a valid Element');
|
56 | done();
|
57 | }
|
58 | });
|
59 | });
|
60 |
|
61 | describe('#selectedText', () => {
|
62 | it('should select text from editable element', () => {
|
63 | const selectedText = ClipboardActionDefault({
|
64 | container: document.body,
|
65 | target: document.querySelector('#input'),
|
66 | });
|
67 |
|
68 | assert.equal(selectedText, 'abc');
|
69 | });
|
70 |
|
71 | it('should select text from non-editable element', () => {
|
72 | const selectedText = ClipboardActionDefault({
|
73 | container: document.body,
|
74 | target: document.querySelector('#paragraph'),
|
75 | });
|
76 |
|
77 | assert.equal(selectedText, 'abc');
|
78 | });
|
79 | });
|
80 | });
|