@@ -15,6 +15,7 @@ private func waitForOperation<T>(fromProducer producer: SignalProducer<Operation
15
15
when: ( ) -> ( ) ,
16
16
onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
17
17
onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
18
+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
18
19
onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
19
20
20
21
waitUntil { done in
@@ -24,6 +25,8 @@ private func waitForOperation<T>(fromProducer producer: SignalProducer<Operation
24
25
onAppend ( value)
25
26
case . Insert( let value, let index) :
26
27
onInsert ( value, index)
28
+ case . Update( let value, let index) :
29
+ onUpdate ( value, index)
27
30
case . RemoveElement( let index) :
28
31
onDelete ( index)
29
32
}
@@ -38,19 +41,21 @@ private func waitForOperation<T>(fromSignal signal: Signal<Operation<T>, NoError
38
41
when: ( ) -> ( ) ,
39
42
onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
40
43
onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
44
+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
41
45
onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
42
46
43
47
let producer = SignalProducer < Operation < T > , NoError > { ( observer, disposable) in signal. observe ( observer) }
44
- waitForOperation ( fromProducer: producer, when: when, onAppend: onAppend, onInsert: onInsert, onDelete: onDelete)
48
+ waitForOperation ( fromProducer: producer, when: when, onAppend: onAppend, onInsert: onInsert, onUpdate : onUpdate , onDelete: onDelete)
45
49
}
46
50
47
51
private func waitForOperation< T> ( fromArray array: ReactiveArray < T > ,
48
52
when: ( ) -> ( ) ,
49
53
onAppend: T -> ( ) = { fail ( " Invalid operation type: .Append( \( $0) ) " ) } ,
50
54
onInsert: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Insert( \( $0) , \( $1) ) " ) } ,
55
+ onUpdate: ( T , Int ) -> ( ) = { fail ( " Invalid operation type: .Update( \( $0) , \( $1) ) " ) } ,
51
56
onDelete: Int -> ( ) = { fail ( " Invalid operation type: .Delete( \( $0) ) " ) } ) {
52
57
53
- waitForOperation ( fromSignal: array. signal, when: when, onAppend: onAppend, onInsert: onInsert, onDelete: onDelete)
58
+ waitForOperation ( fromSignal: array. signal, when: when, onAppend: onAppend, onInsert: onInsert, onUpdate : onUpdate , onDelete: onDelete)
54
59
}
55
60
56
61
class ReactiveArraySpec : QuickSpec {
@@ -101,6 +106,7 @@ class ReactiveArraySpec: QuickSpec {
101
106
array. insert ( 5 , atIndex: 1 )
102
107
103
108
expect ( array [ 1 ] ) . to ( equal ( 5 ) )
109
+ expect ( array. toArray ( ) ) . to ( equal ( [ 1 , 5 , 2 , 3 , 4 ] ) )
104
110
}
105
111
106
112
it ( " signals an insert operation " ) {
@@ -171,15 +177,16 @@ class ReactiveArraySpec: QuickSpec {
171
177
array [ 1 ] = 5
172
178
173
179
expect ( array [ 1 ] ) . to ( equal ( 5 ) )
180
+ expect ( array. toArray ( ) ) . to ( equal ( [ 1 , 5 , 3 , 4 ] ) )
174
181
}
175
182
176
- it ( " signals an insert operation " ) {
183
+ it ( " signals an update operation " ) {
177
184
waitForOperation (
178
185
fromArray: array,
179
186
when: {
180
187
array [ 1 ] = 5
181
188
} ,
182
- onInsert : { ( value, index) in
189
+ onUpdate : { ( value, index) in
183
190
expect ( value) . to ( equal ( 5 ) )
184
191
expect ( index) . to ( equal ( 1 ) )
185
192
}
@@ -210,7 +217,7 @@ class ReactiveArraySpec: QuickSpec {
210
217
when: {
211
218
array [ 1 ] = 5
212
219
} ,
213
- onInsert : { ( value, index) in
220
+ onUpdate : { ( value, index) in
214
221
expect ( value) . to ( equal ( 15 ) )
215
222
expect ( index) . to ( equal ( 1 ) )
216
223
}
@@ -365,6 +372,23 @@ class ReactiveArraySpec: QuickSpec {
365
372
366
373
}
367
374
375
+ context ( " when an update operation is executed " ) {
376
+
377
+ it ( " signals the operations " ) {
378
+ waitForOperation (
379
+ fromSignal: array. signal,
380
+ when: {
381
+ array [ 1 ] = 5
382
+ } ,
383
+ onUpdate: { ( value, index) in
384
+ expect ( value) . to ( equal ( 5 ) )
385
+ expect ( index) . to ( equal ( 1 ) )
386
+ }
387
+ )
388
+ }
389
+
390
+ }
391
+
368
392
context ( " when a delete operation is executed " ) {
369
393
370
394
it ( " signals the operations " ) {
@@ -411,7 +435,7 @@ class ReactiveArraySpec: QuickSpec {
411
435
. take ( 1 )
412
436
. collect ( )
413
437
. startWithNext { counts in
414
- expect ( counts) . to ( equal ( [ countBeforeOperation + 1 ] ) )
438
+ expect ( counts) . to ( equal ( [ countBeforeOperation + 2 ] ) )
415
439
done ( )
416
440
}
417
441
@@ -422,6 +446,21 @@ class ReactiveArraySpec: QuickSpec {
422
446
423
447
}
424
448
449
+ context ( " when an update operation is executed " ) {
450
+
451
+ beforeEach {
452
+ producer = producer. skip ( 1 )
453
+ }
454
+
455
+ it ( " updates the count " ) {
456
+ waitUntil { done in
457
+ array [ 1 ] = 656
458
+ expect ( array. count) . to ( equal ( countBeforeOperation) )
459
+ done ( )
460
+ }
461
+ }
462
+
463
+ }
425
464
426
465
context ( " when an append operation is executed " ) {
427
466
0 commit comments