mirror of
https://github.com/tappollo/IGListKit.git
synced 2026-05-12 16:23:41 +08:00
Add unit tests to reloadData updater
Summary: Adding a few more missing unit tests. Closes #185 Closes https://github.com/Instagram/IGListKit/pull/289 Differential Revision: D4284610 Pulled By: rnystrom fbshipit-source-id: a592fb9c12a3995a62b608f44cdcc693a0f79bec
This commit is contained in:
committed by
Facebook Github Bot
parent
10bdfb23f9
commit
0395ca31e9
@@ -27,6 +27,7 @@
|
||||
296177041D9D54E300F40F34 /* IGListSectionMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 296177001D9D54E300F40F34 /* IGListSectionMap.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
296177051D9D54E300F40F34 /* IGListSectionMap.m in Sources */ = {isa = PBXBuildFile; fileRef = 296177011D9D54E300F40F34 /* IGListSectionMap.m */; };
|
||||
296177061D9D54E300F40F34 /* IGListStackedSectionControllerInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 296177021D9D54E300F40F34 /* IGListStackedSectionControllerInternal.h */; settings = {ATTRIBUTES = (Private, ); }; };
|
||||
2997D4971DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 2997D4961DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m */; };
|
||||
29B5AFCD1DE39B0F004C27A2 /* NSString+IGListDiffable.h in Headers */ = {isa = PBXBuildFile; fileRef = 29B5AFCB1DE39B0F004C27A2 /* NSString+IGListDiffable.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
29B5AFCE1DE39B0F004C27A2 /* NSString+IGListDiffable.h in Headers */ = {isa = PBXBuildFile; fileRef = 29B5AFCB1DE39B0F004C27A2 /* NSString+IGListDiffable.h */; settings = {ATTRIBUTES = (Public, ); }; };
|
||||
29B5AFCF1DE39B0F004C27A2 /* NSString+IGListDiffable.m in Sources */ = {isa = PBXBuildFile; fileRef = 29B5AFCC1DE39B0F004C27A2 /* NSString+IGListDiffable.m */; };
|
||||
@@ -266,6 +267,7 @@
|
||||
296177001D9D54E300F40F34 /* IGListSectionMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListSectionMap.h; sourceTree = "<group>"; };
|
||||
296177011D9D54E300F40F34 /* IGListSectionMap.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGListSectionMap.m; sourceTree = "<group>"; };
|
||||
296177021D9D54E300F40F34 /* IGListStackedSectionControllerInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IGListStackedSectionControllerInternal.h; sourceTree = "<group>"; };
|
||||
2997D4961DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = IGReloadDataUpdaterTests.m; sourceTree = "<group>"; };
|
||||
29B5AFCB1DE39B0F004C27A2 /* NSString+IGListDiffable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+IGListDiffable.h"; sourceTree = "<group>"; };
|
||||
29B5AFCC1DE39B0F004C27A2 /* NSString+IGListDiffable.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+IGListDiffable.m"; sourceTree = "<group>"; };
|
||||
29B5AFD11DE39B2A004C27A2 /* NSNumber+IGListDiffable.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNumber+IGListDiffable.h"; sourceTree = "<group>"; };
|
||||
@@ -610,6 +612,7 @@
|
||||
88144EE31D870EDC007C7F66 /* IGListAdapterTests.m */,
|
||||
88144EE41D870EDC007C7F66 /* IGListAdapterUpdaterTests.m */,
|
||||
88144EE51D870EDC007C7F66 /* IGListBatchUpdateDataTests.m */,
|
||||
2997D4961DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m */,
|
||||
294AC6311DDE4C19002FCE5D /* IGListDiffResultTests.m */,
|
||||
88144EE61D870EDC007C7F66 /* IGListDiffSwiftTests.swift */,
|
||||
88144EE81D870EDC007C7F66 /* IGListDiffTests.m */,
|
||||
@@ -1133,6 +1136,7 @@
|
||||
8285404C1DE40C6E00118B94 /* IGListTestHorizontalSection.m in Sources */,
|
||||
88144F0A1D870EDC007C7F66 /* IGListBatchUpdateDataTests.m in Sources */,
|
||||
26271C8C1DAE96740073E116 /* IGListSingleNibItemControllerTests.m in Sources */,
|
||||
2997D4971DF5FC0B005A5DD2 /* IGReloadDataUpdaterTests.m in Sources */,
|
||||
829D7BAA1DD1819000549816 /* IGListSectionMapTests.m in Sources */,
|
||||
29C5792E1DE0DA89003A149B /* IGTestNibSupplementaryView.m in Sources */,
|
||||
88144F101D870EDC007C7F66 /* IGListSingleSectionControllerTests.m in Sources */,
|
||||
|
||||
89
Tests/IGReloadDataUpdaterTests.m
Normal file
89
Tests/IGReloadDataUpdaterTests.m
Normal file
@@ -0,0 +1,89 @@
|
||||
/**
|
||||
* Copyright (c) 2016-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import <IGListKit/IGListKit.h>
|
||||
|
||||
#import "IGListTestSection.h"
|
||||
#import "IGListTestAdapterDataSource.h"
|
||||
|
||||
@interface IGReloadDataUpdaterTests : XCTestCase
|
||||
|
||||
@property (nonatomic, strong) IGListCollectionView *collectionView;
|
||||
@property (nonatomic, strong) IGListAdapter *adapter;
|
||||
@property (nonatomic, strong) IGListTestAdapterDataSource *dataSource;
|
||||
@property (nonatomic, strong) UICollectionViewFlowLayout *layout;
|
||||
@property (nonatomic, strong) UIWindow *window;
|
||||
|
||||
@end
|
||||
|
||||
@implementation IGReloadDataUpdaterTests
|
||||
|
||||
- (void)setUp {
|
||||
[super setUp];
|
||||
|
||||
// minimum line spacing, item size, and minimum interim spacing are all set in IGListTestSection
|
||||
self.window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
|
||||
|
||||
self.layout = [[UICollectionViewFlowLayout alloc] init];
|
||||
self.collectionView = [[IGListCollectionView alloc] initWithFrame:self.window.bounds collectionViewLayout:self.layout];
|
||||
|
||||
[self.window addSubview:self.collectionView];
|
||||
|
||||
// syncronous reloads so we dont have to do expectations or other nonsense
|
||||
IGListReloadDataUpdater *updater = [[IGListReloadDataUpdater alloc] init];
|
||||
|
||||
self.dataSource = [[IGListTestAdapterDataSource alloc] init];
|
||||
self.adapter = [[IGListAdapter alloc] initWithUpdater:updater
|
||||
viewController:nil
|
||||
workingRangeSize:0];
|
||||
self.adapter.collectionView = self.collectionView;
|
||||
self.adapter.dataSource = self.dataSource;
|
||||
}
|
||||
|
||||
- (void)test_whenCompletionBlockExists_thatBlockExecuted {
|
||||
__block BOOL executed = NO;
|
||||
self.dataSource.objects = @[@0, @1, @2];
|
||||
[self.adapter reloadDataWithCompletion:^(BOOL finished) {
|
||||
executed = YES;
|
||||
}];
|
||||
XCTAssertTrue(executed);
|
||||
}
|
||||
|
||||
- (void)test_whenInsertingIntoContext_thatCollectionViewUpdated {
|
||||
self.dataSource.objects = @[@2];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
|
||||
IGListTestSection *section = [self.adapter sectionControllerForObject:@2];
|
||||
section.items = 3;
|
||||
[section.collectionContext insertInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 3);
|
||||
}
|
||||
|
||||
- (void)test_whenDeletingFromContext_thatCollectionViewUpdated {
|
||||
self.dataSource.objects = @[@2];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
|
||||
IGListTestSection *section = [self.adapter sectionControllerForObject:@2];
|
||||
section.items = 1;
|
||||
[section.collectionContext deleteInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 1);
|
||||
}
|
||||
|
||||
- (void)test_whenReloadingInContext_thatCollectionViewUpdated {
|
||||
self.dataSource.objects = @[@2];
|
||||
[self.adapter reloadDataWithCompletion:nil];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
|
||||
IGListTestSection *section = [self.adapter sectionControllerForObject:@2];
|
||||
[section.collectionContext insertInSectionController:section atIndexes:[NSIndexSet indexSetWithIndex:0]];
|
||||
XCTAssertEqual([self.collectionView numberOfItemsInSection:0], 2);
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user