Skip to content

Commit 09e9011

Browse files
committed
Wrote more tests: Deleting sections, adding sections.
1 parent 4d7741c commit 09e9011

File tree

1 file changed

+97
-24
lines changed

1 file changed

+97
-24
lines changed

Tests/Testing_Example/FZAccordionTableViewUnitTests/FZAccordionTableViewGeneralTests.m

Lines changed: 97 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ - (void)testSectionToggling {
5555
self.tableView.keepOneSectionOpen = NO;
5656

5757
// First, open all of the sections
58-
for (NSInteger i = 0; i < [self.tableView numberOfSections]-1; i++) {
58+
for (NSInteger i = 0; i < [self.tableView numberOfSections]; i++) {
5959
[self waitForHeaderViewInSection:i];
6060
[self.tableView toggleSection:i];
6161

6262
XCTAssert([self.tableView isSectionOpen:i], @"Section %d should be open.", (int)i);
6363
}
6464

6565
// Second, close all of the section
66-
for (NSInteger i = 0; i < [self.tableView numberOfSections]-1; i++) {
66+
for (NSInteger i = 0; i < [self.tableView numberOfSections]; i++) {
6767
[self waitForHeaderViewInSection:i];
6868
[self.tableView toggleSection:i];
6969

@@ -97,7 +97,11 @@ - (void)testAllowMultipleSectionsOpenAsFalse {
9797
XCTAssert(![self.tableView isSectionOpen:0] && [self.tableView isSectionOpen:1], @"Section 0 should be closed when Section 1 was being forced to be open.");
9898
}
9999

100-
#pragma mark - Deletion Tests -
100+
#pragma mark - Test Adding Rows -
101+
102+
// rows must be open
103+
104+
#pragma mark - Deletion Row Tests -
101105

102106
- (void)testDeletingRowWithOpenSection {
103107

@@ -128,26 +132,95 @@ - (void)testDeletingRowWithOpenSection {
128132
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView.", (int)section);
129133
}
130134

131-
//- (void)testDeletingRowWithClosedSection {
132-
//
133-
// NSInteger section = 0;
134-
//
135-
// XCTAssert(![self.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section);
136-
//
137-
// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section);
138-
//
139-
// NSInteger numberOfRows = [self.mainViewController.sections[section] integerValue];
140-
// self.mainViewController.sections[section] = @(numberOfRows-1);
141-
//
142-
// XCTAssert([self.mainViewController.sections[section] integerValue] != [self.tableView.numOfRowsForSection[@(section)] integerValue], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says.");
143-
//
144-
// // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore.
145-
// @try {
146-
// [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone];
147-
// }
148-
// @catch(NSException *exception) { }
149-
//
150-
// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection' after deletion.", (int)section);
151-
//}
135+
- (void)testDeletingRowWithClosedSection {
136+
137+
NSInteger section = 0;
138+
139+
[self waitForHeaderViewInSection:section];
140+
XCTAssert(![self.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section);
141+
142+
// Make sure initial conditions hold
143+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section);
144+
145+
// "Delete" in the user data source
146+
NSInteger numberOfRows = [self.mainViewController.sections[section] integerValue];
147+
self.mainViewController.sections[section] = @(numberOfRows-1);
148+
149+
XCTAssert([self.mainViewController.sections[section] integerValue] != [self.tableView.sectionInfos[section] numberOfRows], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says.");
150+
151+
// Delete in the tableView
152+
@try {
153+
[self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone];
154+
}
155+
@catch(NSException *exception) {
156+
// Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore.
157+
}
158+
159+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView.", (int)section);
160+
}
161+
162+
#pragma mark - Add Section -
163+
164+
- (void)testAddingSection {
165+
166+
NSInteger section = 0;
167+
NSInteger numberOfRows = 33;
168+
169+
// Makes sure that sections are loaded.
170+
[self waitForHeaderViewInSection:section];
171+
172+
NSInteger initialSectionCount = self.mainViewController.sections.count;
173+
174+
// Add data into data source
175+
[self.mainViewController.sections insertObject:@(numberOfRows) atIndex:0];
176+
177+
// Add to tableview
178+
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section];
179+
[self.tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
180+
181+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The data source section rows should match up.");
182+
XCTAssert(initialSectionCount+1 == self.tableView.numberOfSections, @"The section counts should match up.");
183+
}
184+
185+
#pragma mark - Delete Section -
186+
187+
- (void)testDeleteClosedSection {
188+
189+
NSInteger section = 0;
190+
191+
// Open the section
192+
[self waitForHeaderViewInSection:section];
193+
XCTAssert(![self.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section);
194+
195+
// Remove from data source
196+
[self.mainViewController.sections removeObjectAtIndex:section];
197+
198+
// Remove from tableview
199+
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section];
200+
[self.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
201+
202+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The data source section rows should match up.");
203+
XCTAssert(self.mainViewController.sections.count == self.tableView.numberOfSections, @"The section counts should match up.");
204+
}
205+
206+
- (void)testDeleteOpenSection {
207+
208+
NSInteger section = 0;
209+
210+
// Open the section
211+
[self waitForHeaderViewInSection:section];
212+
[self.tableView toggleSection:section];
213+
XCTAssert([self.tableView isSectionOpen:section], @"Section %d should be open.", (int)section);
214+
215+
// Remove from data source
216+
[self.mainViewController.sections removeObjectAtIndex:section];
217+
218+
// Remove from tableview
219+
NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:section];
220+
[self.tableView deleteSections:indexSet withRowAnimation:UITableViewRowAnimationFade];
221+
222+
XCTAssert([self.mainViewController.sections[section] integerValue] == [self.tableView.sectionInfos[section] numberOfRows], @"The data source section rows should match up.");
223+
XCTAssert(self.mainViewController.sections.count == self.tableView.numberOfSections, @"The section counts should match up.");
224+
}
152225

153226
@end

0 commit comments

Comments
 (0)