Skip to content

Commit 89dc9b0

Browse files
committed
Added tests for adding of rows and data source mapping integrity.
1 parent 09e9011 commit 89dc9b0

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

Tests/Testing_Example/FZAccordionTableViewUnitTests/FZAccordionTableViewGeneralTests.m

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,28 @@ - (void)testAllowMultipleSectionsOpenAsFalse {
9999

100100
#pragma mark - Test Adding Rows -
101101

102-
// rows must be open
102+
- (void)testAddingRows {
103+
104+
NSInteger section = 0;
105+
NSInteger numberOfRowsToAdd = 33;
106+
107+
// We can only add rows to an open section
108+
[self waitForHeaderViewInSection:0];
109+
[self.tableView toggleSection:0];
110+
111+
NSInteger numberOfRowsExisting = [self.mainViewController.sections[section] integerValue];
112+
113+
NSMutableArray *rowsIndexPaths = [NSMutableArray new];
114+
for (int i = (int)numberOfRowsExisting; i < numberOfRowsToAdd+numberOfRowsExisting; i++) {
115+
[rowsIndexPaths addObject:[NSIndexPath indexPathForRow:i inSection:section]];
116+
}
117+
118+
self.mainViewController.sections[section] = @(numberOfRowsExisting + numberOfRowsToAdd);
119+
[self.tableView insertRowsAtIndexPaths:rowsIndexPaths withRowAnimation:UITableViewRowAnimationFade];
120+
121+
XCTAssert(numberOfRowsExisting + numberOfRowsToAdd == [self.tableView.sectionInfos[section] numberOfRows], @"Unequal number of rows in section %d.", (int)section);
122+
123+
}
103124

104125
#pragma mark - Deletion Row Tests -
105126

@@ -223,4 +244,13 @@ - (void)testDeleteOpenSection {
223244
XCTAssert(self.mainViewController.sections.count == self.tableView.numberOfSections, @"The section counts should match up.");
224245
}
225246

247+
#pragma mark - Method 'isSectionOpen' Tests -
248+
249+
- (void)testDataSourceMapping {
250+
for (NSInteger section = 0; section < self.tableView.numberOfSections; section++) {
251+
[self waitForHeaderViewInSection:section];
252+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The external data source does not match the internal FZAccordionTableView datasource in section %d.", (int)section);
253+
}
254+
}
255+
226256
@end

0 commit comments

Comments
 (0)