|
9 | 9 | #import <UIKit/UIKit.h>
|
10 | 10 | #import <XCTest/XCTest.h>
|
11 | 11 | #import "FZAccordionTableViewSimulator.h"
|
| 12 | +#import "FZAccordionTableView+Internals.h" |
12 | 13 |
|
13 | 14 | @interface FZAccordionTableViewTests : XCTestCase
|
14 | 15 |
|
@@ -149,4 +150,51 @@ - (void)testSectionsAlwaysOpen {
|
149 | 150 | }
|
150 | 151 | }
|
151 | 152 |
|
| 153 | +#pragma mark - Deletion Tests - |
| 154 | + |
| 155 | +- (void)testDeletingRowWithOpenSection { |
| 156 | + |
| 157 | + NSInteger section = 0; |
| 158 | + |
| 159 | + [self.tableViewSimulator.tableView toggleSection:section]; |
| 160 | + XCTAssert([self.tableViewSimulator.tableView isSectionOpen:section], @"Section %d should be open.", (int)section); |
| 161 | + |
| 162 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] == [self.tableViewSimulator.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section); |
| 163 | + |
| 164 | + NSInteger numberOfRows = [self.tableViewSimulator.sections[section] integerValue]; |
| 165 | + self.tableViewSimulator.sections[section] = @(numberOfRows-1); |
| 166 | + |
| 167 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] != [self.tableViewSimulator.tableView.numOfRowsForSection[@(section)] integerValue], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says."); |
| 168 | + |
| 169 | + // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore. |
| 170 | + @try { |
| 171 | + [self.tableViewSimulator.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
| 172 | + } |
| 173 | + @catch(NSException *exception) { } |
| 174 | + |
| 175 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] == [self.tableViewSimulator.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); |
| 176 | +} |
| 177 | + |
| 178 | +- (void)testDeletingRowWithClosedSection { |
| 179 | + |
| 180 | + NSInteger section = 0; |
| 181 | + |
| 182 | + XCTAssert(![self.tableViewSimulator.tableView isSectionOpen:section], @"Section %d should be closed.", (int)section); |
| 183 | + |
| 184 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] == [self.tableViewSimulator.tableView.numOfRowsForSection[@(section)] integerValue], @"The number of rows in section %d of our data source should match those of the FZAccordionTableView 'numOfRowsForSection'", (int)section); |
| 185 | + |
| 186 | + NSInteger numberOfRows = [self.tableViewSimulator.sections[section] integerValue]; |
| 187 | + self.tableViewSimulator.sections[section] = @(numberOfRows-1); |
| 188 | + |
| 189 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] != [self.tableViewSimulator.tableView.numOfRowsForSection[@(section)] integerValue], @"Without calling 'deleteForRows' there should be a difference between data source and what the tableView says."); |
| 190 | + |
| 191 | + // Calling 'deleteRowsAtIndexPaths' propogates the necessary methods/changes, but throws an exception that we can just ignore. |
| 192 | + @try { |
| 193 | + [self.tableViewSimulator.tableView deleteRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:numberOfRows-1 inSection:section]] withRowAnimation:UITableViewRowAnimationNone]; |
| 194 | + } |
| 195 | + @catch(NSException *exception) { } |
| 196 | + |
| 197 | + XCTAssert([self.tableViewSimulator.sections[section] integerValue] == [self.tableViewSimulator.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); |
| 198 | +} |
| 199 | + |
152 | 200 | @end
|
0 commit comments