-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathrange-container.spec.js
94 lines (72 loc) · 2.35 KB
/
range-container.spec.js
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
94
import {expect} from 'chai'
import {createElement, createRange} from '../src/util/dom.js'
import RangeContainer from '../src/range-container.js'
describe('RangeContainer', function () {
describe('with no params', function () {
beforeEach(function () {
this.range = new RangeContainer()
})
it('has nothing selected', function () {
expect(this.range.isAnythingSelected).to.equal(false)
})
it('is no Cursor', function () {
expect(this.range.isCursor).to.equal(false)
})
it('is no Selection', function () {
expect(this.range.isSelection).to.equal(false)
})
describe('getCursor()', function () {
it('returns undefined', function () {
expect(this.range.getCursor()).to.equal(undefined)
})
})
describe('getSelection()', function () {
it('returns undefined', function () {
expect(this.range.getSelection()).to.equal(undefined)
})
})
})
describe('with a selection', function () {
beforeEach(function () {
const elem = createElement('<div>Text</div>')
let range = createRange()
range.selectNodeContents(elem)
range = new RangeContainer(elem, range)
this.range = range
})
it('has something selected', function () {
expect(this.range.isAnythingSelected).to.equal(true)
})
it('is no Cursor', function () {
expect(this.range.isCursor).to.equal(false)
})
it('is a Selection', function () {
expect(this.range.isSelection).to.equal(true)
})
it('can force a cursor', function () {
expect(this.range.host.innerHTML).to.equal('Text')
const cursor = this.range.forceCursor()
expect(cursor.isCursor).to.equal(true)
expect(this.range.host.innerHTML).to.equal('')
})
})
describe('with a cursor', function () {
beforeEach(function () {
const elem = createElement('<div>Text</div>')
let range = createRange()
range.selectNodeContents(elem)
range.collapse(true)
range = new RangeContainer(elem, range)
this.range = range
})
it('has something selected', function () {
expect(this.range.isAnythingSelected).to.equal(true)
})
it('is a Cursor', function () {
expect(this.range.isCursor).to.equal(true)
})
it('is no Selection', function () {
expect(this.range.isSelection).to.equal(false)
})
})
})