select.js
2.7 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
var select = require('../src/select');
describe('select editable elements', function() {
before(function() {
global.input = document.createElement('input');
global.input.value = 'lorem ipsum';
global.textarea = document.createElement('textarea');
global.textarea.value = 'lorem ipsum';
document.body.appendChild(global.input);
document.body.appendChild(global.textarea);
});
after(function() {
document.body.innerHTML = '';
});
it('should return the selected text on input', function() {
var result = select(global.input);
assert.equal(result, global.input.value);
});
it('should return the selected text on textarea', function() {
var result = select(global.textarea);
assert.equal(result, global.textarea.value);
});
});
describe('select non-editable element with no children', function() {
before(function() {
global.paragraph = document.createElement('p');
global.paragraph.textContent = 'lorem ipsum';
document.body.appendChild(global.paragraph);
});
after(function() {
document.body.innerHTML = '';
});
it('should return the selected text', function() {
var result = select(global.paragraph);
assert.equal(result, global.paragraph.textContent);
});
});
describe('select non-editable element with child node', function() {
before(function() {
global.li = document.createElement('li');
global.li.textContent = 'lorem ipsum';
global.ul = document.createElement('ul');
global.ul.appendChild(global.li);
document.body.appendChild(global.ul);
});
after(function() {
document.body.innerHTML = '';
});
it('should return the selected text', function() {
var result = select(global.ul);
assert.equal(result, global.ul.textContent);
});
});
describe('select non-editable svg element w/ multiple text children', function() {
before(function() {
global.text1 = document.createElement('text');
global.text1.textContent = 'lorem ipsum';
global.text2 = document.createElement('text');
global.text2.textContent = 'dolor zet';
global.svg = document.createElement('svg');
global.svg.appendChild(global.text1);
global.svg.appendChild(global.text2);
document.body.appendChild(global.svg);
});
after(function() {
document.body.innerHTML = '';
});
it('should return the selected text', function() {
var result = select(global.svg);
assert.equal(result, global.text1.textContent +
global.text2.textContent);
});
});