-
Notifications
You must be signed in to change notification settings - Fork 3
/
GeneratorSpec.js
201 lines (164 loc) · 6.85 KB
/
GeneratorSpec.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
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
'use strict'
let testElement = {
title: 'test',
out: '%m',
preview: '[+]'
}
describe('testGenerator', function () {
let testGenerator
describe('Testing testGenerator', function () {
beforeEach(function () {
testGenerator = new Generator()
})
it('elements should be empty on initialise', function () {
expect(testGenerator.leftElements.length).toEqual(0)
expect(testGenerator.rightElements.length).toEqual(0)
})
it('should clear elements', function () {
testGenerator.leftElements.push('a')
testGenerator.rightElements.push('a')
expect(testGenerator.leftElements.length).toEqual(1)
expect(testGenerator.rightElements.length).toEqual(1)
testGenerator.removeAllElements()
expect(testGenerator.leftElements.length).toEqual(0)
expect(testGenerator.rightElements.length).toEqual(0)
})
describe('if align is left', function () {
it('should add element to left', function () {
testGenerator.addElement(testElement, LEFT_ALIGN)
expect(testGenerator.leftElements.length).toEqual(1)
})
it('should build statusline preview', function () {
testGenerator.leftElements.push(testElement)
let preview = testGenerator.buildPreview(LEFT_ALIGN)
expect(preview).toEqual('[+]')
})
it('should build statusline code', function () {
testGenerator.leftElements.push(testElement)
let out = testGenerator.buildOutput()
expect(out).toEqual('set laststatus=2\nset statusline=\nset statusline+=%m\n')
})
it('should remove last left element', function () {
testGenerator.leftElements.push(testElement)
expect(testGenerator.leftElements.length).toEqual(1)
testGenerator.removeElement(LEFT_ALIGN)
expect(testGenerator.leftElements.length).toEqual(0)
})
})
describe('if align is right', function () {
it('should add element to right', function () {
testGenerator.addElement(testElement, RIGHT_ALIGN)
expect(testGenerator.rightElements.length).toEqual(1)
})
it('should build statusline preview', function () {
testGenerator.rightElements.push(testElement)
let preview = testGenerator.buildPreview(RIGHT_ALIGN)
expect(preview).toEqual('[+]')
})
it('should build statusline code', function () {
testGenerator.rightElements.push(testElement)
let out = testGenerator.buildOutput()
expect(out).toEqual('set laststatus=2\nset statusline=\nset statusline+=%=\nset statusline+=%m\n')
})
})
})
describe('Testing webpage', function () {
let testGenDom, output, leftPreview, rightPreview, leftButton, rightButton, options, dropdowns
beforeEach(function () {
output = document.createElement('input')
leftPreview = document.createElement('input')
rightPreview = document.createElement('input')
leftButton = document.createElement('button')
rightButton = document.createElement('button')
options = document.createElement('div')
dropdowns = document.createElement('div')
output.setAttribute('id', 'output')
leftPreview.setAttribute('id', 'leftPreview')
rightPreview.setAttribute('id', 'rightPreview')
leftButton.setAttribute('id', 'leftButton')
rightButton.setAttribute('id', 'rightButton')
options.setAttribute('id', 'options')
dropdowns.setAttribute('id', 'dropdowns')
document.body.appendChild(output)
document.body.appendChild(leftPreview)
document.body.appendChild(rightPreview)
document.body.appendChild(leftButton)
document.body.appendChild(rightButton)
document.body.appendChild(options)
document.body.appendChild(dropdowns)
testGenDom = new GeneratorDom()
})
afterEach(function () {
document.body.removeChild(output)
document.body.removeChild(leftPreview)
document.body.removeChild(rightPreview)
document.body.removeChild(leftButton)
document.body.removeChild(rightButton)
document.body.removeChild(options)
document.body.removeChild(dropdowns)
})
it('should initialise with buttons', function () {
expect(testGenDom.initButtons().childNodes.length).not.toBeLessThan(0)
})
it('should initialise with dropdowns', function () {
expect(testGenDom.initDropdowns().childNodes.length).not.toBeLessThan(0)
})
it('should add element to left', function () {
testGenDom.setAlign(LEFT_ALIGN)
testGenDom.addElement(testElement)
expect(testGenDom.generator.leftElements.length).toEqual(1)
})
it('should add element to right', function () {
testGenDom.setAlign(RIGHT_ALIGN)
testGenDom.addElement(testElement)
expect(testGenDom.generator.rightElements.length).toEqual(1)
})
it('should update output', function () {
testGenDom.generator.addElement(testElement, LEFT_ALIGN)
testGenDom.updateOutput()
expect(output.value).toEqual('set laststatus=2set statusline=set statusline+=%m')
})
it('should update preview text on left', function () {
testGenDom.generator.addElement(testElement, LEFT_ALIGN)
testGenDom.updatePreview()
expect(leftPreview.innerHTML).toEqual('[+]')
})
it('should update preview text on right', function () {
testGenDom.setAlign(RIGHT_ALIGN)
testGenDom.generator.addElement(testElement, RIGHT_ALIGN)
testGenDom.updatePreview()
expect(rightPreview.innerHTML).toEqual('[+]')
})
it('should clear output and preview', function () {
output.value = 'fo'
leftPreview.value = 'ob'
rightPreview.value = 'ar'
testGenDom.clear()
expect(output.value).toEqual('')
expect(leftPreview.innerHTML).toEqual('')
expect(rightPreview.innerHTML).toEqual('')
})
it('should undo last added element', function () {
testGenDom.generator.addElement(testElement, LEFT_ALIGN)
testGenDom.generator.addElement(testElement, LEFT_ALIGN)
expect(testGenDom.generator.leftElements.length).toEqual(2)
testGenDom.undo()
expect(testGenDom.generator.leftElements.length).toEqual(1)
})
it('should change foreground and background colours', function () {
let element = testGenDom.addColour('green', 'lightgray')
testGenDom.generator.addElement(element, LEFT_ALIGN)
testGenDom.generator.addElement(testElement, LEFT_ALIGN)
testGenDom.updatePreview()
expect(leftPreview.innerHTML).toEqual('<span style="color:green;background-color:lightgray;">[+]</span>')
})
it('should undo and remove button', function () {
let element = testGenDom.addColour('green', 'lightgray')
testGenDom.generator.addElement(element, LEFT_ALIGN)
testGenDom.update()
expect(testGenDom.colourButtons.length).toEqual(1)
testGenDom.undo()
expect(testGenDom.colourButtons.length).toEqual(0)
})
})
})