@@ -12,17 +12,21 @@ import XCTest
12
12
13
13
// UICollectionView
14
14
final class UICollectionViewTests : RxTest {
15
- func testCollectionView_DelegateEventCompletesOnDealloc ( ) {
15
+ func test_DelegateEventCompletesOnDealloc ( ) {
16
16
let layout = UICollectionViewFlowLayout ( )
17
17
let createView : ( ) -> UICollectionView = { UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout) }
18
18
19
19
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. itemSelected }
20
20
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. itemDeselected }
21
21
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. modelSelected ( Int . self) }
22
22
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. modelDeselected ( Int . self) }
23
+
24
+ #if os(tvOS)
25
+ ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. didUpdateFocusInContextWithAnimationCoordinator }
26
+ #endif
23
27
}
24
28
25
- func testCollectionView_itemSelected ( ) {
29
+ func test_itemSelected ( ) {
26
30
let layout = UICollectionViewFlowLayout ( )
27
31
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
28
32
@@ -40,7 +44,7 @@ final class UICollectionViewTests : RxTest {
40
44
subscription. dispose ( )
41
45
}
42
46
43
- func testCollectionView_itemDeselected ( ) {
47
+ func test_itemDeselected ( ) {
44
48
let layout = UICollectionViewFlowLayout ( )
45
49
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
46
50
@@ -58,7 +62,7 @@ final class UICollectionViewTests : RxTest {
58
62
subscription. dispose ( )
59
63
}
60
64
61
- func testCollectionView_itemHighlighted ( ) {
65
+ func test_itemHighlighted ( ) {
62
66
let layout = UICollectionViewFlowLayout ( )
63
67
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
64
68
@@ -76,7 +80,7 @@ final class UICollectionViewTests : RxTest {
76
80
subscription. dispose ( )
77
81
}
78
82
79
- func testCollectionView_itemUnhighlighted ( ) {
83
+ func test_itemUnhighlighted ( ) {
80
84
let layout = UICollectionViewFlowLayout ( )
81
85
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
82
86
@@ -94,7 +98,7 @@ final class UICollectionViewTests : RxTest {
94
98
subscription. dispose ( )
95
99
}
96
100
97
- func testCollectionView_willDisplayCell ( ) {
101
+ func test_willDisplayCell ( ) {
98
102
let layout = UICollectionViewFlowLayout ( )
99
103
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
100
104
@@ -117,7 +121,7 @@ final class UICollectionViewTests : RxTest {
117
121
subscription. dispose ( )
118
122
}
119
123
120
- func testCollectionView_willDisplaySupplementaryView ( ) {
124
+ func test_willDisplaySupplementaryView ( ) {
121
125
let layout = UICollectionViewFlowLayout ( )
122
126
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
123
127
@@ -145,7 +149,7 @@ final class UICollectionViewTests : RxTest {
145
149
subscription. dispose ( )
146
150
}
147
151
148
- func testCollectionView_didEndDisplayingCell ( ) {
152
+ func test_didEndDisplayingCell ( ) {
149
153
let layout = UICollectionViewFlowLayout ( )
150
154
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
151
155
@@ -168,7 +172,7 @@ final class UICollectionViewTests : RxTest {
168
172
subscription. dispose ( )
169
173
}
170
174
171
- func testCollectionView_didEndDisplayingSupplementaryView ( ) {
175
+ func test_didEndDisplayingSupplementaryView ( ) {
172
176
let layout = UICollectionViewFlowLayout ( )
173
177
let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
174
178
@@ -195,7 +199,7 @@ final class UICollectionViewTests : RxTest {
195
199
subscription. dispose ( )
196
200
}
197
201
198
- func testCollectionView_DelegateEventCompletesOnDealloc1 ( ) {
202
+ func test_DelegateEventCompletesOnDealloc1 ( ) {
199
203
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
200
204
201
205
let layout = UICollectionViewFlowLayout ( )
@@ -210,7 +214,7 @@ final class UICollectionViewTests : RxTest {
210
214
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. modelSelected ( Int . self) }
211
215
}
212
216
213
- func testCollectionView_DelegateEventCompletesOnDealloc2 ( ) {
217
+ func test_DelegateEventCompletesOnDealloc2 ( ) {
214
218
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
215
219
216
220
let layout = UICollectionViewFlowLayout ( )
@@ -227,7 +231,7 @@ final class UICollectionViewTests : RxTest {
227
231
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. modelSelected ( Int . self) }
228
232
}
229
233
230
- func testCollectionView_DelegateEventCompletesOnDealloc2_cellType ( ) {
234
+ func test_DelegateEventCompletesOnDealloc2_cellType ( ) {
231
235
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
232
236
233
237
let layout = UICollectionViewFlowLayout ( )
@@ -244,7 +248,7 @@ final class UICollectionViewTests : RxTest {
244
248
ensureEventDeallocated ( createView) { ( view: UICollectionView ) in view. rx. modelSelected ( Int . self) }
245
249
}
246
250
247
- func testCollectionView_ModelSelected_itemsWithCellFactory ( ) {
251
+ func test_ModelSelected_itemsWithCellFactory ( ) {
248
252
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
249
253
250
254
let layout = UICollectionViewFlowLayout ( )
@@ -277,7 +281,7 @@ final class UICollectionViewTests : RxTest {
277
281
s. dispose ( )
278
282
}
279
283
280
- func testCollectionView_ModelSelected_itemsWithCellIdentifier ( ) {
284
+ func test_ModelSelected_itemsWithCellIdentifier ( ) {
281
285
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
282
286
283
287
let layout = UICollectionViewFlowLayout ( )
@@ -308,7 +312,7 @@ final class UICollectionViewTests : RxTest {
308
312
dataSourceSubscription. dispose ( )
309
313
}
310
314
311
- func testCollectionView_ModelDeselected_itemsWithCellFactory ( ) {
315
+ func test_ModelDeselected_itemsWithCellFactory ( ) {
312
316
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
313
317
314
318
let layout = UICollectionViewFlowLayout ( )
@@ -342,7 +346,7 @@ final class UICollectionViewTests : RxTest {
342
346
s. dispose ( )
343
347
}
344
348
345
- func testCollectionView_ModelDeselected_itemsWithCellIdentifier ( ) {
349
+ func test_ModelDeselected_itemsWithCellIdentifier ( ) {
346
350
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
347
351
348
352
let layout = UICollectionViewFlowLayout ( )
@@ -373,7 +377,7 @@ final class UICollectionViewTests : RxTest {
373
377
dataSourceSubscription. dispose ( )
374
378
}
375
379
376
- func testCollectionView_modelAtIndexPath_normal ( ) {
380
+ func test_modelAtIndexPath_normal ( ) {
377
381
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
378
382
379
383
let layout = UICollectionViewFlowLayout ( )
@@ -394,6 +398,50 @@ final class UICollectionViewTests : RxTest {
394
398
395
399
dataSourceSubscription. dispose ( )
396
400
}
401
+
402
+ #if os(tvOS)
403
+
404
+ func test_didUpdateFocusInContextWithAnimationCoordinator( ) {
405
+ let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] )
406
+
407
+ let layout = UICollectionViewFlowLayout ( )
408
+ let createView : ( ) -> ( UICollectionView , Disposable ) = {
409
+ let collectionView = UICollectionView ( frame: CGRect ( x: 0 , y: 0 , width: 1 , height: 1 ) , collectionViewLayout: layout)
410
+ collectionView. register ( NSClassFromString ( " UICollectionViewCell " ) , forCellWithReuseIdentifier: " a " )
411
+ let dataSource = SectionedViewDataSourceMock ( )
412
+ let dataSourceSubscription = items. bind ( to: collectionView. rx. items ( dataSource: dataSource) )
413
+
414
+ return ( collectionView, dataSourceSubscription)
415
+
416
+ }
417
+
418
+ let ( collectionView, dataSourceSubscription) = createView ( )
419
+
420
+ var resultContext : UICollectionViewFocusUpdateContext ? = nil
421
+ var resultAnimationCoordinator : UIFocusAnimationCoordinator ? = nil
422
+
423
+ let subscription = collectionView. rx. didUpdateFocusInContextWithAnimationCoordinator
424
+ . subscribe ( onNext: { args in
425
+ let ( context, animationCoordinator) = args
426
+ resultContext = context
427
+ resultAnimationCoordinator = animationCoordinator
428
+ } )
429
+
430
+ let context = UICollectionViewFocusUpdateContext ( )
431
+ let animationCoordinator = UIFocusAnimationCoordinator ( )
432
+
433
+ XCTAssertEqual ( resultContext, nil )
434
+ XCTAssertEqual ( resultAnimationCoordinator, nil )
435
+
436
+ collectionView. delegate!. collectionView!( collectionView, didUpdateFocusIn: context, with: animationCoordinator)
437
+
438
+ XCTAssertEqual ( resultContext, context)
439
+ XCTAssertEqual ( resultAnimationCoordinator, animationCoordinator)
440
+
441
+ subscription. dispose ( )
442
+ dataSourceSubscription. dispose ( )
443
+ }
444
+ #endif
397
445
}
398
446
399
447
extension UICollectionViewTests {
@@ -465,7 +513,7 @@ extension UICollectionViewTests {
465
513
XCTAssert ( dataSourceDeallocated == true )
466
514
}
467
515
468
- func testCollectionViewDataSourceIsResetOnDispose ( ) {
516
+ func testDataSourceIsResetOnDispose ( ) {
469
517
var disposeEvents : [ String ] = [ ]
470
518
471
519
let items : Observable < [ Int ] > = Observable . just ( [ 1 , 2 , 3 ] ) . concat ( Observable . never ( ) )
0 commit comments