File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
Tests/FZAccordionTableViewUnitTests Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,15 @@ - (void)setDataSource:(id<UITableViewDataSource>)dataSource {
150150 super.dataSource = self;
151151}
152152
153+ - (void )insertSections : (NSIndexSet *)sections withRowAnimation : (UITableViewRowAnimation)animation {
154+ [sections enumerateIndexesUsingBlock: ^(NSUInteger section, BOOL * _Nonnull stop) {
155+ FZAccordionTableViewSectionInfo *sectionInfo = [[FZAccordionTableViewSectionInfo alloc ] initWithNumberOfRows: 0 ];
156+ [self .sectionInfos insertObject: sectionInfo atIndex: section];
157+ }];
158+
159+ [super insertSections: sections withRowAnimation: animation];
160+ }
161+
153162- (void )deleteSections : (NSIndexSet *)sections withRowAnimation : (UITableViewRowAnimation)animation {
154163
155164 // Remove section info in reverse order to prevent array from
@@ -431,7 +440,11 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
431440
432441 [self .sectionInfos[section] setNumberOfRows: numOfRows];
433442
434- return ([self isSectionOpen: section]) ? numOfRows : 0 ;
443+ if (![self isSectionOpen: section]) {
444+ numOfRows = 0 ;
445+ }
446+
447+ return numOfRows;
435448}
436449
437450- (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
Original file line number Diff line number Diff line change @@ -203,6 +203,32 @@ - (void)testAddingSection {
203203 XCTAssert (initialSectionCount+1 == self.tableView .numberOfSections , @" The section counts should match up." );
204204}
205205
206+ - (void )testAddingSectionWhileOtherSectionsAreOpen {
207+
208+ // First, open all of the sections
209+ self.tableView .allowMultipleSectionsOpen = YES ;
210+ for (NSInteger i = 0 ; i < [self .tableView numberOfSections ]; i++) {
211+ [self waitForHeaderViewInSection: i];
212+ [self .tableView toggleSection: i];
213+
214+ XCTAssert ([self .tableView isSectionOpen: i], @" Section %d should be open." , (int )i);
215+ }
216+
217+ NSInteger section = 1 ;
218+ NSInteger numberOfRows = 33 ;
219+ NSInteger initialSectionCount = self.mainViewController .sections .count ;
220+
221+ // Add data into data source
222+ [self .mainViewController.sections insertObject: @(numberOfRows) atIndex: section];
223+
224+ // Add to tableview
225+ NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex: section];
226+ [self .tableView insertSections: indexSet withRowAnimation: UITableViewRowAnimationFade];
227+
228+ XCTAssert ([self .mainViewController.sections[section] integerValue ] == [self .tableView.sectionInfos[section] numberOfRows ], @" The data source section rows should match up." );
229+ XCTAssert (initialSectionCount+1 == self.tableView .numberOfSections , @" The section counts should match up." );
230+ }
231+
206232#pragma mark - Delete Section -
207233
208234- (void )testDeleteClosedSection {
You can’t perform that action at this time.
0 commit comments