-
Notifications
You must be signed in to change notification settings - Fork 0
/
queue.test.js
220 lines (217 loc) · 6.03 KB
/
queue.test.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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// JSHint support
/* global INTERMediator,buster,INTERMediatorLib,INTERMediatorOnPage,IMLibElement, IMLibQueue */
const IMLibQueue = require('./index.js')
var counter1 = 0, counter2 = 0, counter3 = 0, counter4 = 0, counter5 = 0, counter6 = 0
test('IMLibQueue Test: should execute immidiately', function () {
'use strict'
counter1 = 1
IMLibQueue.setTask(finishProc => {
console.log('===check point 1-1 ===')
counter1++
expect(counter1).toBe(2)
finishProc()
}, true)
IMLibQueue.setTask(finishProc => {
console.log('===check point 1-2 ===')
counter1++
expect(counter1).toBe(3)
finishProc()
}, true)
console.log('===check point 1-3 ===')
expect(counter1).toBe(3)
})
test('IMLibQueue Test: execute lately', done => {
'use strict'
counter2 = 1
IMLibQueue.setTask(finishProc => {
console.log('===check point 2-1 ===')
counter2++
expect(counter2).toBe(2)
finishProc()
})
IMLibQueue.setTask(finishProc => {
console.log('===check point 2-2 ===')
counter2++
expect(counter2).toBe(3)
finishProc()
done()
})
console.log('===check point 2-3 ===')
expect(counter2).toBe(1)
}
)
test('IMLibQueue Test: execute sequential tasks', done => {
'use strict'
counter5 = 1
IMLibQueue.setTask(finishProc => {
console.log('===check point 5-1 ===')
counter5++
expect(counter5).toBe(2)
finishProc()
})
IMLibQueue.setSequentialTasks([finishProc => {
console.log('===check point 5-2 ===')
counter5++
expect(counter5).toBe(3)
finishProc()
}, finishProc => {
console.log('===check point 5-3 ===')
counter5++
expect(counter5).toBe(4)
finishProc()
}, finishProc => {
console.log('===check point 5-4 ===')
counter5++
expect(counter5).toBe(5)
finishProc()
}, finishProc => {
console.log('===check point 5-5 ===')
counter5++
expect(counter5).toBe(6)
finishProc()
}])
IMLibQueue.setTask(finishProc => {
console.log('===check point 5-6 ===')
counter5++
expect(counter5).toBe(7)
finishProc()
done()
})
console.log('===check point 5-7 ===')
expect(counter5).toBe(1)
}
)
test('IMLibQueue Test: execute sequential tasks reverse order', done => {
'use strict'
counter6 = 1
IMLibQueue.setPriorTask(finishProc => {
console.log('===check point 6-1 ===')
counter6++
expect(counter6).toBe(7)
finishProc()
})
IMLibQueue.setSequentialPriorTasks([finishProc => {
console.log('===check point 6-2 ===')
counter6++
expect(counter6).toBe(3)
finishProc()
}, finishProc => {
console.log('===check point 6-3 ===')
counter6++
expect(counter6).toBe(4)
finishProc()
}, finishProc => {
console.log('===check point 6-4 ===')
counter6++
expect(counter6).toBe(5)
finishProc()
}, finishProc => {
console.log('===check point 6-5 ===')
counter6++
expect(counter6).toBe(6)
finishProc()
done()
}])
IMLibQueue.setPriorTask(finishProc => {
//console.log('===check point 6-6 ===')
counter6++
expect(counter6).toBe(2)
finishProc()
})
console.log('===check point 6-7 ===')
expect(counter6).toBe(1)
}
)
test('IMLibQueue Test: execute lately with reverse order', done => {
'use strict'
counter4 = 1
IMLibQueue.setPriorTask(finishProc => {
console.log('===check point 4-1 ===')
counter4++
expect(counter4).toBe(3)
finishProc()
})
IMLibQueue.setPriorTask(finishProc => {
console.log('===check point 4-2 ===')
counter4++
expect(counter4).toBe(2)
finishProc()
done()
})
console.log('===check point 4-3 ===')
expect(counter4).toBe(1)
}
)
test('IMLibQueue Test: data relaying', done => {
'use strict'
var label = IMLibQueue.getNewLabel()
counter3 = 1
IMLibQueue.setTask(finishProc => {
var l = label
console.log('===check point 3-1 ===')
IMLibQueue.setDataStore(l, 'key1', 100)
IMLibQueue.setDataStore(l, 'key2', 200)
IMLibQueue.setDataStore(l, 'key3', 300)
finishProc()
})
IMLibQueue.setTask(finishProc => {
var l = label
console.log('===check point 3-2 ===')
expect(IMLibQueue.getDataStore(l, 'key3')).toBe(300)
finishProc()
})
IMLibQueue.setTask(finishProc => {
var l = label
console.log('===check point 3-3 ===')
expect(IMLibQueue.getDataStore(l, 'key2')).toBe(200)
IMLibQueue.setDataStore(l, 'key4', 400)
counter3++
expect(counter3).toBe(2)
finishProc()
})
IMLibQueue.setTask(finishProc => {
var l = label
console.log('===check point 3-4 ===')
expect(IMLibQueue.getDataStore(l, 'key4')).toBe(400)
expect(IMLibQueue.getDataStore(l, 'key1')).toBe(100)
finishProc()
done()
})
console.log('===check point 3-5 ===')
expect(counter3).toBe(1)
}
)
test('IMLibQueue Test: should execute immidiately once more', done => {
'use strict'
var label = IMLibQueue.getNewLabel()
IMLibQueue.setDataStore(label, 'counter', 100)
IMLibQueue.setTask(finishProc => {
var l = label
var c = IMLibQueue.getDataStore(l, 'counter')
console.log('===check point 11-1 ===')
expect(c).toBe(100)
IMLibQueue.setDataStore(l, 'counter', c + 1)
finishProc()
}, true)
IMLibQueue.setTask(finishProc => {
var l = label
var c = IMLibQueue.getDataStore(l, 'counter')
console.log('===check point 11-2 ===')
expect(c).toBe(101)
IMLibQueue.setDataStore(l, 'counter', c + 1)
expect(IMLibQueue.getDataStore(l, 'counter')).toBe(102)
finishProc()
done()
}, true)
console.log('===check point 11-3 ===')
var c = IMLibQueue.getDataStore(label, 'counter')
IMLibQueue.setDataStore(label, 'counter', c + 1)
expect(IMLibQueue.getDataStore(label, 'counter')).toBe(103)
})
//
// test('wait for somethin', done => {
// setTimeout(() => {
// expect(counter5).toBe(7)
// done()
// }, 1000)
// })