From 4baf2673543d5072076dca5e6a8d00aff41b7ed4 Mon Sep 17 00:00:00 2001 From: Ryan Nystrom Date: Mon, 5 Dec 2016 17:29:34 -0800 Subject: [PATCH] Add missing adapter tests Summary: Couple more unit tests missing from `IGListAdapter`. - [x] All tests pass. Demo project builds and runs. - [x] I added tests, an experiment, or detailed why my change isn't tested. - [x] I have reviewed the [contributing guide](https://github.com/Instagram/IGListKit/blob/master/.github/CONTRIBUTING.md) Closes https://github.com/Instagram/IGListKit/pull/287 Differential Revision: D4281952 Pulled By: jessesquires fbshipit-source-id: da01d22b291071e5b2a7623b263574738456b8b8 --- Tests/IGListAdapterTests.m | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/Tests/IGListAdapterTests.m b/Tests/IGListAdapterTests.m index 5cd4ae5..437f71e 100644 --- a/Tests/IGListAdapterTests.m +++ b/Tests/IGListAdapterTests.m @@ -850,4 +850,27 @@ XCTAssertEqual(CGPointEqualToPoint(point, p), YES); \ XCTAssertEqual(self.collectionView.numberOfSections, 3); } +- (void)test_whenDeselectingThroughContext_thatCellDeselected { + self.dataSource.objects = @[@1, @2, @3]; + [self.adapter reloadDataWithCompletion:nil]; + + NSIndexPath *path = [NSIndexPath indexPathForItem:0 inSection:0]; + [self.collectionView selectItemAtIndexPath:path animated:NO scrollPosition:UICollectionViewScrollPositionTop]; + XCTAssertTrue([[self.collectionView cellForItemAtIndexPath:path] isSelected]); + + id section = [self.adapter sectionControllerForObject:@1]; + [self.adapter deselectItemAtIndex:0 sectionController:section animated:NO]; + XCTAssertFalse([[self.collectionView cellForItemAtIndexPath:path] isSelected]); +} + +- (void)test_whenScrollingToIndex_withSectionController_thatPositionCorrect { + self.dataSource.objects = @[@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16, @17, @18, @19]; + [self.adapter reloadDataWithCompletion:nil]; + + IGListSectionController *section = [self.adapter sectionControllerForObject:@8]; + [section.collectionContext scrollToSectionController:section atIndex:0 scrollPosition:UICollectionViewScrollPositionTop animated:NO]; + XCTAssertEqual(self.collectionView.contentOffset.x, 0); + XCTAssertEqual(self.collectionView.contentOffset.y, 280); +} + @end