forked from ucfopen/Obojobo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmock-element.test.js
More file actions
137 lines (101 loc) · 3.44 KB
/
Copy pathmock-element.test.js
File metadata and controls
137 lines (101 loc) · 3.44 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import MockElement from '../../../src/scripts/common/mockdom/mock-element'
describe('MockElement', () => {
beforeEach(() => {
// jest.resetAllMocks()
// AssessmentStore.init()
// QuestionStore.init()
})
test('creates new instance', () => {
const el = new MockElement('type', { a: 1 })
expect(el.type).toBe('type')
expect(el.attrs).toEqual({ a: 1 })
expect(el.nodeType).toBe('element')
expect(el.children).toEqual([])
expect(el.parent).toBe(null)
})
test('adds child', () => {
const root = new MockElement('root')
const child = new MockElement('child')
root.addChild(child)
expect(root.parent).toBe(null)
expect(root.children).toEqual([child])
expect(child.parent).toBe(root)
expect(child.children).toEqual([])
})
test('addChildAt adds child at index', () => {
const root = new MockElement('root')
const childA = new MockElement('child-a')
const childB = new MockElement('child-b')
const childC = new MockElement('child-c')
const childD = new MockElement('child-d')
root.addChildAt(childA, 0)
expect(root.children).toEqual([childA])
root.addChildAt(childB, 0)
expect(root.children).toEqual([childB, childA])
root.addChildAt(childC, 1)
expect(root.children).toEqual([childB, childC, childA])
root.addChildAt(childD, 3)
expect(root.children).toEqual([childB, childC, childA, childD])
})
test('addBefore adds a child before another child', () => {
const root = new MockElement('root')
const childA = new MockElement('child-a')
const childB = new MockElement('child-b')
const childC = new MockElement('child-c')
root.addChild(childA)
root.addBefore(childB, childA)
expect(root.children).toEqual([childB, childA])
root.addBefore(childC, childA)
expect(root.children).toEqual([childB, childC, childA])
})
test('addAfter adds a child after another child', () => {
const root = new MockElement('root')
const childA = new MockElement('child-a')
const childB = new MockElement('child-b')
const childC = new MockElement('child-c')
root.addChild(childA)
root.addAfter(childB, childA)
expect(root.children).toEqual([childA, childB])
root.addAfter(childC, childA)
expect(root.children).toEqual([childA, childC, childB])
})
test('replaceChild will replace a child with another child', () => {
const root = new MockElement('root')
const childA = new MockElement('child-a')
const childB = new MockElement('child-b')
root.addChild(childA)
root.replaceChild(childA, childB)
expect(root.children).toEqual([childB])
})
test('firstChild and lastChild return the first and last children', () => {
const root = new MockElement('root')
const childA = new MockElement('child-a')
const childB = new MockElement('child-b')
const childC = new MockElement('child-c')
root.addChild(childA)
root.addChild(childB)
root.addChild(childC)
expect(root.firstChild).toBe(childA)
expect(root.lastChild).toBe(childC)
})
test('getColorOfFirstCharacter returns expected color if node is a list element', () => {
const root = new MockElement('root')
const li = new MockElement('li')
root.addChild(li)
li.addChild({
text: {
styleList: {
styles: [
{ type: 'mock', start: 12 },
{ type: 'underline', start: 1 },
{ type: 'color', start: 0, data: { text: '#ccc' } }
]
}
}
})
const rootColor = root.getColorOfFirstCharacter()
expect(rootColor).toBe('#000')
const liColor = li.getColorOfFirstCharacter()
expect(liColor).toBe('#ccc')
})
})