diff --git a/IGListKit.xcodeproj/project.pbxproj b/IGListKit.xcodeproj/project.pbxproj index d0bc6b6a4..cc85c5f75 100644 --- a/IGListKit.xcodeproj/project.pbxproj +++ b/IGListKit.xcodeproj/project.pbxproj @@ -50,7 +50,6 @@ 2997D4971DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2997D4961DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m */; }; 29C4748C1DDF45F400AE68CE /* IGListAdapterProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */; }; 29C4748D1DDF45F900AE68CE /* IGListAdapterProxyTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */; }; - 29C4748E1DDF460500AE68CE /* IGListAdapterStoryboardTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */; }; 29C4748F1DDF460500AE68CE /* IGListDiffResultTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 294AC6311DDE4C19002FCE5D /* IGListDiffResultTests.m */; }; 29C474901DDF460500AE68CE /* IGListSectionMapTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 829D7BA81DD1816400549816 /* IGListSectionMapTests.m */; }; 29C5792E1DE0DA89003A149B /* IGTestNibSupplementaryView.m in Sources */ = {isa = PBXBuildFile; fileRef = 2904861F1DCD02750007F41D /* IGTestNibSupplementaryView.m */; }; @@ -63,9 +62,7 @@ 29DA5CA71EA7D37000113926 /* IGListTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DA5CA61EA7D37000113926 /* IGListTestCase.m */; }; 29DA5CA81EA7D37000113926 /* IGListTestCase.m in Sources */ = {isa = PBXBuildFile; fileRef = 29DA5CA61EA7D37000113926 /* IGListTestCase.m */; }; 29EA6C491DB43A8000957A88 /* IGTestNibCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */; }; - 401B5E63230111EC004099D5 /* IGTestNibCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = 294369B01DB1B7AE0025F6E7 /* IGTestNibCell.xib */; }; - 401B5E64230111F3004099D5 /* IGTestNibSupplementaryView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 2904861C1DCD02140007F41D /* IGTestNibSupplementaryView.xib */; }; - 401B5E65230111F7004099D5 /* IGTestStoryboard.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 821BC4C21DB8CAE900172ED0 /* IGTestStoryboard.storyboard */; }; + 5E8F3959238B299F00CB02A0 /* IGListAdapterTests_IB.m in Sources */ = {isa = PBXBuildFile; fileRef = 5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */; }; 6A9EB3611F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */; }; 6A9EB3621F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */; }; 7A02CEEE2361511100B49FAE /* IGListReloadDataUpdater.h in Headers */ = {isa = PBXBuildFile; fileRef = 7A02CEC72361510F00B49FAE /* IGListReloadDataUpdater.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -361,8 +358,6 @@ 885FE2301DC51B76009CE2B4 /* IGListDiffTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE81D870EDC007C7F66 /* IGListDiffTests.m */; }; 885FE2311DC51B76009CE2B4 /* IGListDisplayHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EE91D870EDC007C7F66 /* IGListDisplayHandlerTests.m */; }; 885FE2331DC51B76009CE2B4 /* IGListSingleSectionControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EED1D870EDC007C7F66 /* IGListSingleSectionControllerTests.m */; }; - 885FE2341DC51B76009CE2B4 /* IGListSingleNibItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 26271C8B1DAE96740073E116 /* IGListSingleNibItemControllerTests.m */; }; - 885FE2351DC51B76009CE2B4 /* IGListSingleStoryboardItemControllerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 821BC4BE1DB8C95300172ED0 /* IGListSingleStoryboardItemControllerTests.m */; }; 885FE2371DC51B76009CE2B4 /* IGListWorkingRangeHandlerTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EEF1D870EDC007C7F66 /* IGListWorkingRangeHandlerTests.m */; }; 885FE2381DC51B86009CE2B4 /* IGListTestAdapterDataSource.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EF21D870EDC007C7F66 /* IGListTestAdapterDataSource.m */; }; 885FE2391DC51B86009CE2B4 /* IGListTestOffsettingLayout.m in Sources */ = {isa = PBXBuildFile; fileRef = 88144EF41D870EDC007C7F66 /* IGListTestOffsettingLayout.m */; }; @@ -485,6 +480,7 @@ 29DA5CA61EA7D37000113926 /* IGListTestCase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListTestCase.m; sourceTree = ""; }; 29DA5CA91EA7D39B00113926 /* IGListTestCase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestCase.h; sourceTree = ""; }; 29DA5CAA1EA7D3FF00113926 /* IGListTestHelpers.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListTestHelpers.h; sourceTree = ""; }; + 5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListAdapterTests_IB.m; sourceTree = ""; }; 6A9EB35F1F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IGTestSingleWithoutDeselectionDelegate.h; sourceTree = ""; }; 6A9EB3601F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = IGTestSingleWithoutDeselectionDelegate.m; sourceTree = ""; }; 7A02CEC72361510F00B49FAE /* IGListReloadDataUpdater.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListReloadDataUpdater.h; sourceTree = ""; }; @@ -1037,6 +1033,7 @@ 29C4748A1DDF45E700AE68CE /* IGListAdapterProxyTests.m */, 8240C7F11DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m */, 88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */, + 5E8F3956238B284C00CB02A0 /* IGListAdapterTests_IB.m */, 88144EE41D870EDC007C7F66 /* IGListAdapterUpdaterTests.m */, 88144EE51D870EDC007C7F66 /* IGListBatchUpdateDataTests.m */, 298DD9CD1E3ADD1400F76F50 /* IGListBindingSectionControllerTests.m */, @@ -1522,9 +1519,6 @@ isa = PBXResourcesBuildPhase; buildActionMask = 2147483647; files = ( - 401B5E65230111F7004099D5 /* IGTestStoryboard.storyboard in Resources */, - 401B5E64230111F3004099D5 /* IGTestNibSupplementaryView.xib in Resources */, - 401B5E63230111EC004099D5 /* IGTestNibCell.xib in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -1739,7 +1733,6 @@ 8285404D1DE40C6E00118B94 /* IGListTestHorizontalSection.m in Sources */, 298DDA061E3AE2B000F76F50 /* IGTestNumberBindableCell.m in Sources */, 885FE2381DC51B86009CE2B4 /* IGListTestAdapterDataSource.m in Sources */, - 885FE2341DC51B76009CE2B4 /* IGListSingleNibItemControllerTests.m in Sources */, 0B40C5F31E01CB8200378109 /* IGReloadDataUpdaterTests.m in Sources */, 885FE2391DC51B86009CE2B4 /* IGListTestOffsettingLayout.m in Sources */, 29C4748F1DDF460500AE68CE /* IGListDiffResultTests.m in Sources */, @@ -1755,8 +1748,6 @@ 885FE22C1DC51B76009CE2B4 /* IGListAdapterTests.m in Sources */, 298DDA051E3AE2B000F76F50 /* IGTestStringBindableCell.m in Sources */, 885FE22D1DC51B76009CE2B4 /* IGListAdapterUpdaterTests.m in Sources */, - 885FE2351DC51B76009CE2B4 /* IGListSingleStoryboardItemControllerTests.m in Sources */, - 29C4748E1DDF460500AE68CE /* IGListAdapterStoryboardTests.m in Sources */, 885FE2411DC51B86009CE2B4 /* IGTestSingleNibItemDataSource.m in Sources */, 6A9EB3621F841E5D0070C572 /* IGTestSingleWithoutDeselectionDelegate.m in Sources */, 885FE2461DC51B86009CE2B4 /* IGTestSupplementarySource.m in Sources */, @@ -1857,6 +1848,7 @@ 88144F081D870EDC007C7F66 /* IGListAdapterTests.m in Sources */, 8240C7F21DC284C300B3AAE7 /* IGListAdapterStoryboardTests.m in Sources */, 8240C7F01DC272CA00B3AAE7 /* IGTestStoryboardSupplementaryView.m in Sources */, + 5E8F3959238B299F00CB02A0 /* IGListAdapterTests_IB.m in Sources */, 88379728202236AB00B94676 /* IGListAdapterUpdateTester.m in Sources */, 821BC4CB1DB8D60100172ED0 /* IGTestStoryboardViewController.m in Sources */, 821BC4D01DB8D90900172ED0 /* IGTestStoryboardCell.m in Sources */, @@ -2163,6 +2155,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Tests/IGListKitTests-Bridging-Header.h"; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; SWIFT_VERSION = 4.0; + TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 10.0; }; name = Debug; @@ -2185,6 +2178,7 @@ SWIFT_OBJC_BRIDGING_HEADER = "Tests/IGListKitTests-Bridging-Header.h"; SWIFT_TREAT_WARNINGS_AS_ERRORS = YES; SWIFT_VERSION = 4.0; + TARGETED_DEVICE_FAMILY = "1,2,3"; TVOS_DEPLOYMENT_TARGET = 10.0; }; name = Release; diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index f641417dc..6b54e8cc9 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -41,7 +41,7 @@ - (void)setUp { self.adapter.collectionView = self.collectionView; self.adapter.dataSource = self.dataSource; - if (@available(iOS 11.0, *)) { + if (@available(iOS 11.0, tvOS 11.0, *)) { self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; } } @@ -284,23 +284,6 @@ - (void)DISABLED_test_whenCellsExtendBeyondBounds_thatVisibleSectionControllersA XCTAssertTrue([visibleSectionControllers containsObject:[self.adapter sectionControllerForObject:@4]]); } -- (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect { - self.dataSource.objects = @[@0]; - [self.adapter reloadDataWithCompletion:nil]; - IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; - supplementarySource.dequeueFromNib = YES; - supplementarySource.collectionContext = self.adapter; - supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; - IGListSectionController *controller = [self.adapter sectionControllerForObject:@0]; - controller.supplementaryViewSource = supplementarySource; - supplementarySource.sectionController = controller; - [self.adapter performUpdatesAnimated:NO completion:nil]; - NSArray *visibleSectionControllers = [self.adapter visibleSectionControllers]; - - XCTAssertTrue([visibleSectionControllers count] == 1); - XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource); -} - - (void)DISABLED_test_whenCellsExtendBeyondBounds_thatVisibleCellsExistForSectionControllers { self.dataSource.objects = @[@2, @3, @4, @5, @6]; [self.adapter reloadDataWithCompletion:nil]; @@ -475,30 +458,6 @@ - (void)test_whenSupplementarySourceSupportsFooter_thatHeaderViewsAreNil { XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); } -- (void)test_whenSupplementarySourceSupportsFooter_withNibs_thatHeaderViewsAreNil { - self.dataSource.objects = @[@1, @2]; - [self.adapter reloadDataWithCompletion:nil]; - - IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; - supplementarySource.dequeueFromNib = YES; - supplementarySource.collectionContext = self.adapter; - supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; - - IGListSectionController *controller = [self.adapter sectionControllerForObject:@1]; - controller.supplementaryViewSource = supplementarySource; - supplementarySource.sectionController = controller; - - [self.adapter performUpdatesAnimated:NO completion:nil]; - - id view = [self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; - XCTAssertTrue([view isKindOfClass:IGTestNibSupplementaryView.class]); - XCTAssertEqualObjects([[(IGTestNibSupplementaryView *)view label] text], @"Foo bar baz"); - - XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); - XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); - XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); -} - - (void)test_whenAdapterReleased_withSectionControllerStrongRefToCell_thatSectionControllersRelease { __weak id weakCollectionView = nil, weakAdapter = nil, weakSectionController = nil; diff --git a/Tests/IGListAdapterTests_IB.m b/Tests/IGListAdapterTests_IB.m new file mode 100644 index 000000000..4fb29e1ae --- /dev/null +++ b/Tests/IGListAdapterTests_IB.m @@ -0,0 +1,84 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import + +#import + +#import +#import + +#import "IGListTestAdapterDataSource.h" +#import "IGListTestCase.h" +#import "IGTestSupplementarySource.h" +#import "IGListAdapterInternal.h" +#import "IGTestNibSupplementaryView.h" + +@interface IGListAdapterTests_IB : IGListTestCase +@end + +@implementation IGListAdapterTests_IB + +- (void)setUp { + self.dataSource = [IGListTestAdapterDataSource new]; + self.updater = [IGListReloadDataUpdater new]; + + [super setUp]; + + // test case doesn't use -setupWithObjects for more control over update events + self.adapter.collectionView = self.collectionView; + self.adapter.dataSource = self.dataSource; + + if (@available(iOS 11.0, tvOS 11.0, *)) { + self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever; + } +} + +- (void) test_withEmptySectionPlusFooter_thatVisibleSectionControllersAreCorrect { + self.dataSource.objects = @[@0]; + [self.adapter reloadDataWithCompletion:nil]; + IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; + supplementarySource.dequeueFromNib = YES; + supplementarySource.collectionContext = self.adapter; + supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; + IGListSectionController *controller = [self.adapter sectionControllerForObject:@0]; + controller.supplementaryViewSource = supplementarySource; + supplementarySource.sectionController = controller; + [self.adapter performUpdatesAnimated:NO completion:nil]; + NSArray *visibleSectionControllers = [self.adapter visibleSectionControllers]; + + XCTAssertTrue([visibleSectionControllers count] == 1); + XCTAssertTrue(visibleSectionControllers.firstObject.supplementaryViewSource == supplementarySource); +} + +- (void)test_whenSupplementarySourceSupportsFooter_withNibs_thatHeaderViewsAreNil { + self.dataSource.objects = @[@1, @2]; + [self.adapter reloadDataWithCompletion:nil]; + + IGTestSupplementarySource *supplementarySource = [IGTestSupplementarySource new]; + supplementarySource.dequeueFromNib = YES; + supplementarySource.collectionContext = self.adapter; + supplementarySource.supportedElementKinds = @[UICollectionElementKindSectionFooter]; + + IGListSectionController *controller = [self.adapter sectionControllerForObject:@1]; + controller.supplementaryViewSource = supplementarySource; + supplementarySource.sectionController = controller; + + [self.adapter performUpdatesAnimated:NO completion:nil]; + + id view = [self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + XCTAssertTrue([view isKindOfClass:IGTestNibSupplementaryView.class]); + XCTAssertEqualObjects([[(IGTestNibSupplementaryView *)view label] text], @"Foo bar baz"); + + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]); + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionHeader atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); + XCTAssertNil([self.collectionView supplementaryViewForElementKind:UICollectionElementKindSectionFooter atIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]); +} + +@end diff --git a/Tests/IGListSingleSectionControllerTests.m b/Tests/IGListSingleSectionControllerTests.m index 68db8ce0c..788b295d5 100644 --- a/Tests/IGListSingleSectionControllerTests.m +++ b/Tests/IGListSingleSectionControllerTests.m @@ -75,14 +75,14 @@ - (void)test_whenItemUpdated_thatCellIsConfigured { genTestObject(@3, @"Baz"), ]]; self.dataSource.objects = @[ - genTestObject(@1, @"Foo"), - genTestObject(@2, @"Qux"), // new value + genTestObject(@1, @"Qux"), // new value + genTestObject(@2, @"Bar"), genTestObject(@3, @"Baz"), ]; XCTestExpectation *expectation = genExpectation; [self.adapter performUpdatesAnimated:YES completion:^(BOOL finished) { - IGTestCell *cell2 = (IGTestCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:1]]; - XCTAssertEqualObjects(cell2.label.text, @"Qux"); + IGTestCell *cell1 = (IGTestCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]]; + XCTAssertEqualObjects(cell1.label.text, @"Qux"); [expectation fulfill]; }]; [self waitForExpectationsWithTimeout:30 handler:nil];