|
10 | 10 | #import "FZAccordionTableViewTestBase.h"
|
11 | 11 | #include <stdlib.h>
|
12 | 12 |
|
| 13 | +@interface FZAccordionTableViewSectionInfo : NSObject |
| 14 | +@property (nonatomic, getter=isOpen) BOOL open; |
| 15 | +@property (nonatomic) NSInteger numberOfRows; |
| 16 | +@end |
| 17 | + |
| 18 | +@interface FZAccordionTableView(Private) |
| 19 | + |
| 20 | +@property (strong, nonatomic) NSMutableArray <FZAccordionTableViewSectionInfo *> *sectionInfos; |
| 21 | + |
| 22 | +@end |
| 23 | + |
13 | 24 | @interface FZAccordionTableViewGeneralTests : FZAccordionTableViewTestBase
|
14 | 25 |
|
15 | 26 | @end
|
@@ -86,51 +97,57 @@ - (void)testAllowMultipleSectionsOpenAsFalse {
|
86 | 97 | XCTAssert(![self.tableView isSectionOpen:0] && [self.tableView isSectionOpen:1], @"Section 0 should be closed when Section 1 was being forced to be open.");
|
87 | 98 | }
|
88 | 99 |
|
89 |
| -//#pragma mark - Deletion Tests - |
90 |
| -// |
91 |
| -//- (void)testDeletingRowWithOpenSection { |
92 |
| -// |
93 |
| -// NSInteger section = 0; |
94 |
| -// |
95 |
| -// [self.mainViewController.tableView toggleSection:section]; |
96 |
| -// XCTAssert([self.mainViewController.tableView isSectionOpen:section], @"Section %d should be open.", (int)section); |
97 |
| -// |
98 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.mainViewController.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section); |
99 |
| -// |
100 |
| -// NSInteger numberOfRows = [self.mainViewController.sections[section] integerValue]; |
101 |
| -// self.mainViewController.sections[section] = @(numberOfRows-1); |
102 |
| -// |
103 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] != [self.mainViewController.tableView.numOfRowsForSection[@(section)] integerValue], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says."); |
104 |
| -// |
105 |
| -// // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore. |
106 |
| -// @try { |
107 |
| -// [self.mainViewController.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
108 |
| -// } |
109 |
| -// @catch(NSException *exception) { } |
110 |
| -// |
111 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.mainViewController.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); |
112 |
| -//} |
113 |
| -// |
| 100 | +#pragma mark - Deletion Tests - |
| 101 | + |
| 102 | +- (void)testDeletingRowWithOpenSection { |
| 103 | + |
| 104 | + NSInteger section = 0; |
| 105 | + |
| 106 | + // Open the section |
| 107 | + [self waitForHeaderViewInSection:section]; |
| 108 | + [self.tableView toggleSection:section]; |
| 109 | + XCTAssert([self.tableView isSectionOpen:section], @"Section %d should be open.", (int)section); |
| 110 | + |
| 111 | + // Make sure initial conditions hold |
| 112 | + 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); |
| 113 | + |
| 114 | + // "Delete" in the user data source |
| 115 | + NSInteger numberOfRows = [self.mainViewController.sections[section] integerValue]; |
| 116 | + self.mainViewController.sections[section] = @(numberOfRows-1); |
| 117 | + |
| 118 | + 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."); |
| 119 | + |
| 120 | + // Delete in the tableView |
| 121 | + @try { |
| 122 | + [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
| 123 | + } |
| 124 | + @catch(NSException *exception) { |
| 125 | + // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore. |
| 126 | + } |
| 127 | + |
| 128 | + 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); |
| 129 | +} |
| 130 | + |
114 | 131 | //- (void)testDeletingRowWithClosedSection {
|
115 | 132 | //
|
116 | 133 | // NSInteger section = 0;
|
117 | 134 | //
|
118 |
| -// XCTAssert(![self.mainViewController.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section); |
| 135 | +// XCTAssert(![self.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section); |
119 | 136 | //
|
120 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.mainViewController.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section); |
| 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); |
121 | 138 | //
|
122 | 139 | // NSInteger numberOfRows = [self.mainViewController.sections[section] integerValue];
|
123 | 140 | // self.mainViewController.sections[section] = @(numberOfRows-1);
|
124 | 141 | //
|
125 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] != [self.mainViewController.tableView.numOfRowsForSection[@(section)] integerValue], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says."); |
| 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."); |
126 | 143 | //
|
127 | 144 | // // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore.
|
128 | 145 | // @try {
|
129 |
| -// [self.mainViewController.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
| 146 | +// [self.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
130 | 147 | // }
|
131 | 148 | // @catch(NSException *exception) { }
|
132 | 149 | //
|
133 |
| -// XCTAssert([self.mainViewController.sections[section] integerValue] == [self.mainViewController.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); |
| 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); |
134 | 151 | //}
|
135 | 152 |
|
136 | 153 | @end
|
0 commit comments