Skip to content

Commit a859ff7

Browse files
committed
make unit tests runnable for tvOS
1 parent 662d81b commit a859ff7

File tree

4 files changed

+95
-58
lines changed

4 files changed

+95
-58
lines changed

IGListKit.xcodeproj/project.pbxproj

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050
2997D4971DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2997D4961DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m */; };
5151
29C4748C1DDF45F400AE68CE /* IGListAdapterProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */; };
5252
29C4748D1DDF45F900AE68CE /* IGListAdapterProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */; };
53-
29C4748E1DDF460500AE68CE /* IGListAdapterStoryboardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */; };
5453
29C4748F1DDF460500AE68CE /* IGListDiffResultTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 294AC6311DDE4C19002FCE5D /* IGListDiffResultTests.m */; };
5554
29C474901DDF460500AE68CE /* IGListSectionMapTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 829D7BA81DD1816400549816 /* IGListSectionMapTests.m */; };
5655
29C5792E1DE0DA89003A149B /* IGTestNibSupplementaryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */; };
@@ -63,9 +62,7 @@
6362
29DA5CA71EA7D37000113926 /* IGListTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DA5CA61EA7D37000113926 /* IGListTestCase.m */; };
6463
29DA5CA81EA7D37000113926 /* IGListTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DA5CA61EA7D37000113926 /* IGListTestCase.m */; };
6564
29EA6C491DB43A8000957A88 /* IGTestNibCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */; };
66-
401B5E63230111EC004099D5 /* IGTestNibCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */; };
67-
401B5E64230111F3004099D5 /* IGTestNibSupplementaryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */; };
68-
401B5E65230111F7004099D5 /* IGTestStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */; };
65+
5E8F3959238B299F00CB02A0 /* IGListAdapterTests_IB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */; };
6966
6A9EB3611F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */; };
7067
6A9EB3621F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */; };
7168
7A02CEEE2361511100B49FAE /* IGListReloadDataUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A02CEC72361510F00B49FAE /* IGListReloadDataUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; };
@@ -361,8 +358,6 @@
361358
885FE2301DC51B76009CE2B4 /* IGListDiffTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE81D870EDC007C7F66 /* IGListDiffTests.m */; };
362359
885FE2311DC51B76009CE2B4 /* IGListDisplayHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE91D870EDC007C7F66 /* IGListDisplayHandlerTests.m */; };
363360
885FE2331DC51B76009CE2B4 /* IGListSingleSectionControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EED1D870EDC007C7F66 /* IGListSingleSectionControllerTests.m */; };
364-
885FE2341DC51B76009CE2B4 /* IGListSingleNibItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */; };
365-
885FE2351DC51B76009CE2B4 /* IGListSingleStoryboardItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4BE1DB8C95300172ED0 /* IGListSingleStoryboardItemControllerTests.m */; };
366361
885FE2371DC51B76009CE2B4 /* IGListWorkingRangeHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EEF1D870EDC007C7F66 /* IGListWorkingRangeHandlerTests.m */; };
367362
885FE2381DC51B86009CE2B4 /* IGListTestAdapterDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EF21D870EDC007C7F66 /* IGListTestAdapterDataSource.m */; };
368363
885FE2391DC51B86009CE2B4 /* IGListTestOffsettingLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EF41D870EDC007C7F66 /* IGListTestOffsettingLayout.m */; };
@@ -485,6 +480,7 @@
485480
29DA5CA61EA7D37000113926 /* IGListTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListTestCase.m; sourceTree = "<group>"; };
486481
29DA5CA91EA7D39B00113926 /* IGListTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestCase.h; sourceTree = "<group>"; };
487482
29DA5CAA1EA7D3FF00113926 /* IGListTestHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestHelpers.h; sourceTree = "<group>"; };
483+
5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListAdapterTests_IB.m; sourceTree = "<group>"; };
488484
6A9EB35F1F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IGTestSingleWithoutDeselectionDelegate.h; sourceTree = "<group>"; };
489485
6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleWithoutDeselectionDelegate.m; sourceTree = "<group>"; };
490486
7A02CEC72361510F00B49FAE /* IGListReloadDataUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListReloadDataUpdater.h; sourceTree = "<group>"; };
@@ -1037,6 +1033,7 @@
10371033
29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */,
10381034
8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */,
10391035
88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */,
1036+
5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */,
10401037
88144EE41D870EDC007C7F66 /* IGListAdapterUpdaterTests.m */,
10411038
88144EE51D870EDC007C7F66 /* IGListBatchUpdateDataTests.m */,
10421039
298DD9CD1E3ADD1400F76F50 /* IGListBindingSectionControllerTests.m */,
@@ -1522,9 +1519,6 @@
15221519
isa = PBXResourcesBuildPhase;
15231520
buildActionMask = 2147483647;
15241521
files = (
1525-
401B5E65230111F7004099D5 /* IGTestStoryboard.storyboard in Resources */,
1526-
401B5E64230111F3004099D5 /* IGTestNibSupplementaryView.xib in Resources */,
1527-
401B5E63230111EC004099D5 /* IGTestNibCell.xib in Resources */,
15281522
);
15291523
runOnlyForDeploymentPostprocessing = 0;
15301524
};
@@ -1739,7 +1733,6 @@
17391733
8285404D1DE40C6E00118B94 /* IGListTestHorizontalSection.m in Sources */,
17401734
298DDA061E3AE2B000F76F50 /* IGTestNumberBindableCell.m in Sources */,
17411735
885FE2381DC51B86009CE2B4 /* IGListTestAdapterDataSource.m in Sources */,
1742-
885FE2341DC51B76009CE2B4 /* IGListSingleNibItemControllerTests.m in Sources */,
17431736
0B40C5F31E01CB8200378109 /* IGReloadDataUpdaterTests.m in Sources */,
17441737
885FE2391DC51B86009CE2B4 /* IGListTestOffsettingLayout.m in Sources */,
17451738
29C4748F1DDF460500AE68CE /* IGListDiffResultTests.m in Sources */,
@@ -1755,8 +1748,6 @@
17551748
885FE22C1DC51B76009CE2B4 /* IGListAdapterTests.m in Sources */,
17561749
298DDA051E3AE2B000F76F50 /* IGTestStringBindableCell.m in Sources */,
17571750
885FE22D1DC51B76009CE2B4 /* IGListAdapterUpdaterTests.m in Sources */,
1758-
885FE2351DC51B76009CE2B4 /* IGListSingleStoryboardItemControllerTests.m in Sources */,
1759-
29C4748E1DDF460500AE68CE /* IGListAdapterStoryboardTests.m in Sources */,
17601751
885FE2411DC51B86009CE2B4 /* IGTestSingleNibItemDataSource.m in Sources */,
17611752
6A9EB3621F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */,
17621753
885FE2461DC51B86009CE2B4 /* IGTestSupplementarySource.m in Sources */,
@@ -1857,6 +1848,7 @@
18571848
88144F081D870EDC007C7F66 /* IGListAdapterTests.m in Sources */,
18581849
8240C7F21DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m in Sources */,
18591850
8240C7F01DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m in Sources */,
1851+
5E8F3959238B299F00CB02A0 /* IGListAdapterTests_IB.m in Sources */,
18601852
88379728202236AB00B94676 /* IGListAdapterUpdateTester.m in Sources */,
18611853
821BC4CB1DB8D60100172ED0 /* IGTestStoryboardViewController.m in Sources */,
18621854
821BC4D01DB8D90900172ED0 /* IGTestStoryboardCell.m in Sources */,
@@ -2163,6 +2155,7 @@
21632155
SWIFT_OBJC_BRIDGING_HEADER = "Tests/IGListKitTests-Bridging-Header.h";
21642156
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
21652157
SWIFT_VERSION = 4.0;
2158+
TARGETED_DEVICE_FAMILY = "1,2,3";
21662159
TVOS_DEPLOYMENT_TARGET = 10.0;
21672160
};
21682161
name = Debug;
@@ -2185,6 +2178,7 @@
21852178
SWIFT_OBJC_BRIDGING_HEADER = "Tests/IGListKitTests-Bridging-Header.h";
21862179
SWIFT_TREAT_WARNINGS_AS_ERRORS = YES;
21872180
SWIFT_VERSION = 4.0;
2181+
TARGETED_DEVICE_FAMILY = "1,2,3";
21882182
TVOS_DEPLOYMENT_TARGET = 10.0;
21892183
};
21902184
name = Release;

Tests/IGListAdapterTests.m

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ - (void)setUp {
4141
self.adapter.collectionView = self.collectionView;
4242
self.adapter.dataSource = self.dataSource;
4343

44-
if (@available(iOS 11.0, *)) {
44+
if (@available(iOS 11.0, tvOS 11.0, *)) {
4545
self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
4646
}
4747
}
@@ -284,23 +284,6 @@ - (void)DISABLED_test_whenCellsExtendBeyondBounds_thatVisibleSectionControllersA
284284
XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@4]]);
285285
}
286286

287-
- (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect {
288-
self.dataSource.objects = @[@0];
289-
[self.adapter reloadDataWithCompletion:nil];
290-
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
291-
supplementarySource.dequeueFromNib = YES;
292-
supplementarySource.collectionContext = self.adapter;
293-
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter];
294-
IGListSectionController *controller = [self.adapter sectionControllerForObject:@0];
295-
controller.supplementaryViewSource = supplementarySource;
296-
supplementarySource.sectionController = controller;
297-
[self.adapter performUpdatesAnimated:NO completion:nil];
298-
NSArray<IGListSectionController *> *visibleSectionControllers = [self.adapter visibleSectionControllers];
299-
300-
XCTAssertTrue([visibleSectionControllers count] == 1);
301-
XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource);
302-
}
303-
304287
- (void)DISABLED_test_whenCellsExtendBeyondBounds_thatVisibleCellsExistForSectionControllers {
305288
self.dataSource.objects = @[@2, @3, @4, @5, @6];
306289
[self.adapter reloadDataWithCompletion:nil];
@@ -475,30 +458,6 @@ - (void)test_whenSupplementarySourceSupportsFooter_thatHeaderViewsAreNil {
475458
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]);
476459
}
477460

478-
- (void)test_whenSupplementarySourceSupportsFooter_withNibs_thatHeaderViewsAreNil {
479-
self.dataSource.objects = @[@1, @2];
480-
[self.adapter reloadDataWithCompletion:nil];
481-
482-
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
483-
supplementarySource.dequeueFromNib = YES;
484-
supplementarySource.collectionContext = self.adapter;
485-
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter];
486-
487-
IGListSectionController *controller = [self.adapter sectionControllerForObject:@1];
488-
controller.supplementaryViewSource = supplementarySource;
489-
supplementarySource.sectionController = controller;
490-
491-
[self.adapter performUpdatesAnimated:NO completion:nil];
492-
493-
id view = [self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
494-
XCTAssertTrue([view isKindOfClass:IGTestNibSupplementaryView.class]);
495-
XCTAssertEqualObjects([[(IGTestNibSupplementaryView *)view label] text], @"Foo bar baz");
496-
497-
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]);
498-
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]);
499-
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]);
500-
}
501-
502461
- (void)test_whenAdapterReleased_withSectionControllerStrongRefToCell_thatSectionControllersRelease {
503462
__weak id weakCollectionView = nil, weakAdapter = nil, weakSectionController = nil;
504463

Tests/IGListAdapterTests_IB.m

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import <objc/runtime.h>
9+
10+
#import <XCTest/XCTest.h>
11+
12+
#import <OCMock/OCMock.h>
13+
14+
#import <IGListDiffKit/IGListExperiments.h>
15+
#import <IGListKit/IGListKit.h>
16+
17+
#import "IGListTestAdapterDataSource.h"
18+
#import "IGListTestCase.h"
19+
#import "IGTestSupplementarySource.h"
20+
#import "IGListAdapterInternal.h"
21+
#import "IGTestNibSupplementaryView.h"
22+
23+
@interface IGListAdapterTests_IB : IGListTestCase
24+
@end
25+
26+
@implementation IGListAdapterTests_IB
27+
28+
- (void)setUp {
29+
self.dataSource = [IGListTestAdapterDataSource new];
30+
self.updater = [IGListReloadDataUpdater new];
31+
32+
[super setUp];
33+
34+
// test case doesn't use -setupWithObjects for more control over update events
35+
self.adapter.collectionView = self.collectionView;
36+
self.adapter.dataSource = self.dataSource;
37+
38+
if (@available(iOS 11.0, tvOS 11.0, *)) {
39+
self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
40+
}
41+
}
42+
43+
- (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect {
44+
self.dataSource.objects = @[@0];
45+
[self.adapter reloadDataWithCompletion:nil];
46+
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
47+
supplementarySource.dequeueFromNib = YES;
48+
supplementarySource.collectionContext = self.adapter;
49+
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter];
50+
IGListSectionController *controller = [self.adapter sectionControllerForObject:@0];
51+
controller.supplementaryViewSource = supplementarySource;
52+
supplementarySource.sectionController = controller;
53+
[self.adapter performUpdatesAnimated:NO completion:nil];
54+
NSArray<IGListSectionController *> *visibleSectionControllers = [self.adapter visibleSectionControllers];
55+
56+
XCTAssertTrue([visibleSectionControllers count] == 1);
57+
XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource);
58+
}
59+
60+
- (void)test_whenSupplementarySourceSupportsFooter_withNibs_thatHeaderViewsAreNil {
61+
self.dataSource.objects = @[@1, @2];
62+
[self.adapter reloadDataWithCompletion:nil];
63+
64+
IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new];
65+
supplementarySource.dequeueFromNib = YES;
66+
supplementarySource.collectionContext = self.adapter;
67+
supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter];
68+
69+
IGListSectionController *controller = [self.adapter sectionControllerForObject:@1];
70+
controller.supplementaryViewSource = supplementarySource;
71+
supplementarySource.sectionController = controller;
72+
73+
[self.adapter performUpdatesAnimated:NO completion:nil];
74+
75+
id view = [self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
76+
XCTAssertTrue([view isKindOfClass:IGTestNibSupplementaryView.class]);
77+
XCTAssertEqualObjects([[(IGTestNibSupplementaryView *)view label] text], @"Foo bar baz");
78+
79+
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]);
80+
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]);
81+
XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]);
82+
}
83+
84+
@end

Tests/IGListSingleSectionControllerTests.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ - (void)test_whenItemUpdated_thatCellIsConfigured {
7575
genTestObject(@3, @"Baz"),
7676
]];
7777
self.dataSource.objects = @[
78-
genTestObject(@1, @"Foo"),
79-
genTestObject(@2, @"Qux"), // new value
78+
genTestObject(@1, @"Qux"), // new value
79+
genTestObject(@2, @"Bar"),
8080
genTestObject(@3, @"Baz"),
8181
];
8282
XCTestExpectation *expectation = genExpectation;
8383
[self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) {
84-
IGTestCell *cell2 = (IGTestCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]];
85-
XCTAssertEqualObjects(cell2.label.text, @"Qux");
84+
IGTestCell *cell1 = (IGTestCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
85+
XCTAssertEqualObjects(cell1.label.text, @"Qux");
8686
[expectation fulfill];
8787
}];
8888
[self waitForExpectationsWithTimeout:30 handler:nil];

0 commit comments

Comments
 (0)