Skip to content

Commit 5873ae4

Browse files
committed
Further refactored tests and added delegate tests.
1 parent 9298a74 commit 5873ae4

File tree

8 files changed

+155
-143
lines changed

8 files changed

+155
-143
lines changed

Tests/Testing_Example/FZAccordionTableViewTestApp/MainViewController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111

1212
@interface MainViewController : UIViewController
1313

14+
@property (weak, nonatomic) id <FZAccordionTableViewDelegate> delegate;
1415
@property (weak, nonatomic) IBOutlet FZAccordionTableView *tableView;
1516
@property (strong, nonatomic) NSMutableArray <NSNumber *> *sections;
1617

1718
- (void)connectTableView;
1819

1920
@end
20-

Tests/Testing_Example/FZAccordionTableViewTestApp/MainViewController.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,19 +149,19 @@ - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEd
149149
#pragma mark - <FZAccordionTableViewDelegate> -
150150

151151
- (void)tableView:(FZAccordionTableView *)tableView willOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header {
152-
152+
[self.delegate tableView:tableView willOpenSection:section withHeader:header];
153153
}
154154

155155
- (void)tableView:(FZAccordionTableView *)tableView didOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header {
156-
156+
[self.delegate tableView:tableView didOpenSection:section withHeader:header];
157157
}
158158

159159
- (void)tableView:(FZAccordionTableView *)tableView willCloseSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header {
160-
160+
[self.delegate tableView:tableView willCloseSection:section withHeader:header];
161161
}
162162

163163
- (void)tableView:(FZAccordionTableView *)tableView didCloseSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView *)header {
164-
164+
[self.delegate tableView:tableView didCloseSection:section withHeader:header];
165165
}
166166

167167
@end

Tests/Testing_Example/FZAccordionTableViewTests.xcodeproj/project.pbxproj

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
0156F14E1CCD2A7600E0530C /* AccordionHeaderView.xib in Resources */ = {isa = PBXBuildFile; fileRef = 01D1F3671B24DD86007B97BD /* AccordionHeaderView.xib */; };
1717
0156F14F1CCD2A7B00E0530C /* AccordionHeaderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 01D1F3651B24DD61007B97BD /* AccordionHeaderView.m */; };
1818
0156F1501CCD2A7E00E0530C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 01D1F3371B24D94A007B97BD /* AppDelegate.m */; };
19-
0156F1581CCD2BA400E0530C /* FZAccordionTableViewUnitTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0156F1571CCD2BA400E0530C /* FZAccordionTableViewUnitTests.m */; };
19+
0156F1581CCD2BA400E0530C /* FZAccordionTableViewGeneralTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 0156F1571CCD2BA400E0530C /* FZAccordionTableViewGeneralTests.m */; };
2020
01B0D1B81CD037BC0012BBCA /* FZAccordionTableViewDelegateTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 01B0D1B71CD037BC0012BBCA /* FZAccordionTableViewDelegateTests.m */; };
2121
01B0D1BA1CD038000012BBCA /* FZAccordionTableViewTestBase.m in Sources */ = {isa = PBXBuildFile; fileRef = 01B0D1B91CD038000012BBCA /* FZAccordionTableViewTestBase.m */; };
2222
01D1F3351B24D94A007B97BD /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 01D1F3341B24D94A007B97BD /* main.m */; };
@@ -55,10 +55,11 @@
5555
0156F1431CCD219800E0530C /* FZAccordionTableViewUITests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FZAccordionTableViewUITests.m; sourceTree = "<group>"; };
5656
0156F1451CCD219800E0530C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
5757
0156F1551CCD2BA400E0530C /* FZAccordionTableViewUnitTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = FZAccordionTableViewUnitTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
58-
0156F1571CCD2BA400E0530C /* FZAccordionTableViewUnitTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FZAccordionTableViewUnitTests.m; sourceTree = "<group>"; };
58+
0156F1571CCD2BA400E0530C /* FZAccordionTableViewGeneralTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = FZAccordionTableViewGeneralTests.m; sourceTree = "<group>"; };
5959
0156F1591CCD2BA400E0530C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6060
01B0D1B71CD037BC0012BBCA /* FZAccordionTableViewDelegateTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FZAccordionTableViewDelegateTests.m; sourceTree = "<group>"; };
6161
01B0D1B91CD038000012BBCA /* FZAccordionTableViewTestBase.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = FZAccordionTableViewTestBase.m; sourceTree = "<group>"; };
62+
01B0D1BB1CD039A10012BBCA /* FZAccordionTableViewTestBase.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FZAccordionTableViewTestBase.h; sourceTree = "<group>"; };
6263
01D1F32F1B24D94A007B97BD /* FZAccordionTableViewTests.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = FZAccordionTableViewTests.app; sourceTree = BUILT_PRODUCTS_DIR; };
6364
01D1F3331B24D94A007B97BD /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
6465
01D1F3341B24D94A007B97BD /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
@@ -113,17 +114,26 @@
113114
0156F1561CCD2BA400E0530C /* FZAccordionTableViewUnitTests */ = {
114115
isa = PBXGroup;
115116
children = (
116-
0137E0EE1CCDAF0400C2CFAC /* FZAccordionTableViewTestHelpers.h */,
117-
0137E0EF1CCDAF0400C2CFAC /* FZAccordionTableViewTestHelpers.m */,
118-
01B0D1B91CD038000012BBCA /* FZAccordionTableViewTestBase.m */,
119-
0156F1571CCD2BA400E0530C /* FZAccordionTableViewUnitTests.m */,
117+
01B0D1BC1CD03B690012BBCA /* TestHelpers */,
120118
0137E0EC1CCDAED200C2CFAC /* FZAccordionTableViewInitializationTests.m */,
119+
0156F1571CCD2BA400E0530C /* FZAccordionTableViewGeneralTests.m */,
121120
01B0D1B71CD037BC0012BBCA /* FZAccordionTableViewDelegateTests.m */,
122121
0156F1591CCD2BA400E0530C /* Info.plist */,
123122
);
124123
path = FZAccordionTableViewUnitTests;
125124
sourceTree = "<group>";
126125
};
126+
01B0D1BC1CD03B690012BBCA /* TestHelpers */ = {
127+
isa = PBXGroup;
128+
children = (
129+
0137E0EE1CCDAF0400C2CFAC /* FZAccordionTableViewTestHelpers.h */,
130+
0137E0EF1CCDAF0400C2CFAC /* FZAccordionTableViewTestHelpers.m */,
131+
01B0D1BB1CD039A10012BBCA /* FZAccordionTableViewTestBase.h */,
132+
01B0D1B91CD038000012BBCA /* FZAccordionTableViewTestBase.m */,
133+
);
134+
name = TestHelpers;
135+
sourceTree = "<group>";
136+
};
127137
01D1F3261B24D949007B97BD = {
128138
isa = PBXGroup;
129139
children = (
@@ -331,7 +341,7 @@
331341
01B0D1BA1CD038000012BBCA /* FZAccordionTableViewTestBase.m in Sources */,
332342
01B0D1B81CD037BC0012BBCA /* FZAccordionTableViewDelegateTests.m in Sources */,
333343
0137E0ED1CCDAED200C2CFAC /* FZAccordionTableViewInitializationTests.m in Sources */,
334-
0156F1581CCD2BA400E0530C /* FZAccordionTableViewUnitTests.m in Sources */,
344+
0156F1581CCD2BA400E0530C /* FZAccordionTableViewGeneralTests.m in Sources */,
335345
);
336346
runOnlyForDeploymentPostprocessing = 0;
337347
};

Tests/Testing_Example/FZAccordionTableViewUnitTests/FZAccordionTableViewDelegateTests.m

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,89 @@
66
// Copyright © 2016 Fuzz. All rights reserved.
77
//
88

9-
#import <XCTest/XCTest.h>
9+
#import "FZAccordionTableViewTestBase.h"
1010

11-
@interface FZAccordionTableViewDelegateTests : XCTestCase
11+
@interface FZAccordionTableViewDelegateTests : FZAccordionTableViewTestBase <FZAccordionTableViewDelegate>
12+
13+
@property (nonatomic) BOOL willOpenSectionCalled;
14+
@property (nonatomic) BOOL didOpenSectionCalled;
15+
@property (nonatomic) BOOL willCloseSectionCalled;
16+
@property (nonatomic) BOOL didCloseSectionCalled;
1217

1318
@end
1419

1520
@implementation FZAccordionTableViewDelegateTests
1621

22+
#pragma mark - Setup -
23+
1724
- (void)setUp {
1825
[super setUp];
19-
// Put setup code here. This method is called before the invocation of each test method in the class.
26+
[self.mainViewController connectTableView];
27+
self.mainViewController.delegate = self;
28+
self.willOpenSectionCalled = NO;
29+
self.didOpenSectionCalled = NO;
30+
self.willCloseSectionCalled = NO;
31+
self.didCloseSectionCalled = NO;
2032
}
2133

2234
- (void)tearDown {
23-
// Put teardown code here. This method is called after the invocation of each test method in the class.
2435
[super tearDown];
36+
self.mainViewController.delegate = nil;
37+
}
38+
39+
#pragma mark - Tests -
40+
41+
- (void)testOpening {
42+
[self waitForHeaderViewInSection:0];
43+
[self.tableView toggleSection:0];
44+
45+
XCTAssert(self.willOpenSectionCalled, @"On opening of a section, 'willOpenSection:' must be called");
46+
47+
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
48+
49+
XCTAssert(self.didOpenSectionCalled, @"On opening of a section, 'didOpenSection:' must be called");
50+
}
51+
52+
- (void)testClosing {
53+
54+
[self waitForHeaderViewInSection:0];
55+
// First open
56+
[self.tableView toggleSection:0];
57+
// Now, close
58+
[self.tableView toggleSection:0];
59+
60+
XCTAssert(self.willCloseSectionCalled, @"On closing of a section, 'willCloseSection:' must be called");
61+
62+
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.5]];
63+
64+
XCTAssert(self.didCloseSectionCalled, @"On closing of a section, 'didCloseSection:' must be called");
65+
}
66+
67+
68+
#pragma mark - <FZAccordionTableViewDelegate> -
69+
70+
- (void)tableView:(FZAccordionTableView * _Nonnull)tableView willOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView * _Nonnull)header {
71+
XCTAssertNotNil(tableView);
72+
XCTAssertNotNil(header);
73+
self.willOpenSectionCalled = YES;
74+
}
75+
76+
- (void)tableView:(FZAccordionTableView * _Nonnull)tableView didOpenSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView * _Nonnull)header {
77+
XCTAssertNotNil(tableView);
78+
XCTAssertNotNil(header);
79+
self.didOpenSectionCalled = YES;
2580
}
2681

27-
- (void)testExample {
28-
// This is an example of a functional test case.
29-
// Use XCTAssert and related functions to verify your tests produce the correct results.
82+
- (void)tableView:(FZAccordionTableView * _Nonnull)tableView willCloseSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView * _Nonnull)header {
83+
XCTAssertNotNil(tableView);
84+
XCTAssertNotNil(header);
85+
self.willCloseSectionCalled = YES;
3086
}
3187

32-
- (void)testPerformanceExample {
33-
// This is an example of a performance test case.
34-
[self measureBlock:^{
35-
// Put the code you want to measure the time of here.
36-
}];
88+
- (void)tableView:(FZAccordionTableView * _Nonnull)tableView didCloseSection:(NSInteger)section withHeader:(UITableViewHeaderFooterView * _Nonnull)header {
89+
XCTAssertNotNil(tableView);
90+
XCTAssertNotNil(header);
91+
self.didCloseSectionCalled = YES;
3792
}
3893

3994
@end

Tests/Testing_Example/FZAccordionTableViewUnitTests/FZAccordionTableViewUnitTests.m renamed to Tests/Testing_Example/FZAccordionTableViewUnitTests/FZAccordionTableViewGeneralTests.m

Lines changed: 21 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,133 +7,85 @@
77
//
88

99
#import <XCTest/XCTest.h>
10-
#import "FZAccordionTableViewTestHelpers.h"
11-
#import "MainViewController.h"
10+
#import "FZAccordionTableViewTestBase.h"
1211
#include <stdlib.h>
1312

14-
@interface FZAccordionTableViewUnitTests : XCTestCase
15-
16-
@property (strong, nonatomic) MainViewController *mainViewController;
17-
@property (weak, nonatomic) FZAccordionTableView *tableView;
13+
@interface FZAccordionTableViewGeneralTests : FZAccordionTableViewTestBase
1814

1915
@end
2016

21-
@implementation FZAccordionTableViewUnitTests
17+
@implementation FZAccordionTableViewGeneralTests
2218

2319
#pragma mark - Setup
2420

2521
- (void)setUp {
2622
[super setUp];
27-
self.mainViewController = [FZAccordionTableViewTestHelpers setupMainViewController];
28-
self.tableView = self.mainViewController.tableView;
29-
30-
XCTAssertNotNil(self.mainViewController);
31-
XCTAssertNotNil(self.tableView);
32-
3323
[self.mainViewController connectTableView];
3424
}
3525

3626
- (void)tearDown {
37-
[FZAccordionTableViewTestHelpers tearDownMainViewController];
38-
self.mainViewController = nil;
39-
self.tableView = nil;
4027
[super tearDown];
4128
}
4229

43-
#pragma mark - Helpers
44-
45-
- (void)waitForHeaderViewInSection:(NSInteger)section
46-
{
47-
[FZAccordionTableViewTestHelpers waitForHeaderViewInSection:section tableView:self.tableView];
48-
}
49-
5030
#pragma mark - Method 'isSectionOpen' Tests -
5131

5232
- (void)testClosedSections {
53-
for (NSInteger i = 0; i < [self tableView].numberOfSections; i++) {
33+
for (NSInteger i = 0; i < self.tableView.numberOfSections; i++) {
5434
[self waitForHeaderViewInSection:i];
5535

56-
XCTAssert(![[self tableView] isSectionOpen:i], @"All sections should be initially closed.");
36+
XCTAssert(![self.tableView isSectionOpen:i], @"All sections should be initially closed.");
5737
}
5838
}
5939

6040
#pragma mark - Metohod 'toggleSection' Tests -
6141

62-
6342
- (void)testSectionToggling {
64-
[self tableView].allowMultipleSectionsOpen = YES;
65-
[self tableView].keepOneSectionOpen = NO;
43+
self.tableView.allowMultipleSectionsOpen = YES;
44+
self.tableView.keepOneSectionOpen = NO;
6645

6746
// First, open all of the sections
68-
for (NSInteger i = 0; i < [[self tableView] numberOfSections]-1; i++) {
47+
for (NSInteger i = 0; i < [self.tableView numberOfSections]-1; i++) {
6948
[self waitForHeaderViewInSection:i];
70-
[[self tableView] toggleSection:i];
49+
[self.tableView toggleSection:i];
7150

72-
XCTAssert([[self tableView] isSectionOpen:i], @"Section %d should be open.", (int)i);
51+
XCTAssert([self.tableView isSectionOpen:i], @"Section %d should be open.", (int)i);
7352
}
7453

7554
// Second, close all of the section
76-
for (NSInteger i = 0; i < [[self tableView] numberOfSections]-1; i++) {
55+
for (NSInteger i = 0; i < [self.tableView numberOfSections]-1; i++) {
7756
[self waitForHeaderViewInSection:i];
78-
[[self tableView] toggleSection:i];
57+
[self.tableView toggleSection:i];
7958

80-
XCTAssert(![[self tableView] isSectionOpen:i], @"Section %d should be closed.", (int)i);
59+
XCTAssert(![self.tableView isSectionOpen:i], @"Section %d should be closed.", (int)i);
8160
}
8261
}
8362

8463
#pragma mark - Property 'allowMultipleSectionsOpen' Tests -
8564

8665
- (void)testAllowMultipleSectionsOpenAsTrue {
87-
[self tableView].allowMultipleSectionsOpen = YES;
66+
self.tableView.allowMultipleSectionsOpen = YES;
8867

8968
[self waitForHeaderViewInSection:0];
90-
[[self tableView] toggleSection:0];
69+
[self.tableView toggleSection:0];
9170

9271
[self waitForHeaderViewInSection:1];
93-
[[self tableView] toggleSection:1];
72+
[self.tableView toggleSection:1];
9473

95-
XCTAssert([[self tableView] isSectionOpen:0] && [[self tableView] isSectionOpen:1], @"Both sections should be open.");
74+
XCTAssert([self.tableView isSectionOpen:0] && [self.tableView isSectionOpen:1], @"Both sections should be open.");
9675
}
9776

9877
- (void)testAllowMultipleSectionsOpenAsFalse {
99-
[self tableView].allowMultipleSectionsOpen = NO;
78+
self.tableView.allowMultipleSectionsOpen = NO;
10079

10180
[self waitForHeaderViewInSection:0];
102-
[[self tableView] toggleSection:0];
81+
[self.tableView toggleSection:0];
10382

10483
[self waitForHeaderViewInSection:1];
105-
[[self tableView] toggleSection:1];
84+
[self.tableView toggleSection:1];
10685

107-
XCTAssert(![[self tableView] isSectionOpen:0] && [[self tableView] isSectionOpen:1], @"Section 0 should be closed when Section 1 was being forced to be open.");
86+
XCTAssert(![self.tableView isSectionOpen:0] && [self.tableView isSectionOpen:1], @"Section 0 should be closed when Section 1 was being forced to be open.");
10887
}
10988

110-
111-
//
112-
//#pragma mark - Property 'sectionsAlwaysOpen' Tests -
113-
//
114-
//- (void)testSectionsAlwaysOpen {
115-
// NSMutableArray *sectionsAlwaysOpen = [NSMutableArray new];
116-
// for (NSInteger i = 0; i < self.tableView.numberOfSections; i++) {
117-
// [sectionsAlwaysOpen addObject:@(i)];
118-
// }
119-
// self.tableView.sectionsAlwaysOpen = [NSSet setWithArray:sectionsAlwaysOpen];
120-
//
121-
// // Test that no matter which way you toggle the section, the section remains open.
122-
// for (NSInteger i = 0; i < self.tableView.numberOfSections; i++) {
123-
// [self waitForHeaderViewInSection:i];
124-
// [self.tableView toggleSection:i];
125-
//
126-
// XCTAssert([self.tableView isSectionOpen:i], @"Section %d should be open.", (int)i);
127-
// }
128-
//
129-
// for (NSInteger i = 0; i < self.tableView.numberOfSections; i++) {
130-
// [self waitForHeaderViewInSection:i];
131-
// [self.tableView toggleSection:i];
132-
//
133-
// XCTAssert([self.tableView isSectionOpen:i], @"Section %d should be open.", (int)i);
134-
// }
135-
//}
136-
13789
//#pragma mark - Deletion Tests -
13890
//
13991
//- (void)testDeletingRowWithOpenSection {
@@ -181,19 +133,4 @@ - (void)testAllowMultipleSectionsOpenAsFalse {
181133
// 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);
182134
//}
183135

184-
#pragma mark - Duds
185-
186-
//- (void)testExample {
187-
// // This is an example of a functional test case.
188-
// // Use XCTAssert and related functions to verify your tests produce the correct results.
189-
// [self mainViewController];
190-
//}
191-
//
192-
//- (void)testPerformanceExample {
193-
// // This is an example of a performance test case.
194-
// [self measureBlock:^{
195-
// // Put the code you want to measure the time of here.
196-
// }];
197-
//}
198-
199136
@end

0 commit comments

Comments
 (0)