forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathContactsDataSourceTests.m
107 lines (86 loc) · 3.44 KB
/
ContactsDataSourceTests.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//
// Wire
// Copyright (C) 2016 Wire Swiss GmbH
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
@import UIKit;
@import XCTest;
#import "ContactsDataSource.h"
#import "ContactsDataSource+Private.h"
#import "ContactsDataSource+Testing.h"
#import "MockLoader.h"
#import "MockUser.h"
#import "MockConversation.h"
@interface ContactsDataSourceTests : XCTestCase
@property (nonatomic, strong) ContactsDataSource *dataSource;
@end
@implementation ContactsDataSourceTests
- (void)setUp
{
[super setUp];
[NSThread sleepForTimeInterval:0.5];
self.dataSource = [[ContactsDataSource alloc] initForTesting];
// Put setup code here. This method is called before the invocation of each test method in the class.
}
- (void)tearDown
{
// Put teardown code here. This method is called after the invocation of each test method in the class.
[super tearDown];
}
- (void)testThatDataSourceHasCorrectNumberOfSectionsForSmallNumberOfUsers
{
// GIVEN
NSArray *mockUsers = [MockLoader mockObjectsOfClass:[MockUser class] fromFile:@"people-01.json"];
// WHEN
self.dataSource.ungroupedSearchResults = mockUsers;
// THEN
NSUInteger sections = [self.dataSource numberOfSectionsInTableView:[UITableView new]];
XCTAssertFalse(self.dataSource.shouldShowSectionIndex);
XCTAssertEqual(sections, 1ul, @"Number of sections must be 1");
}
- (void)testThatDataSourceHasCorrectNumberOfSectionsForLargeNumberOfUsers
{
// GIVEN
NSArray *mockUsers = [MockLoader mockObjectsOfClass:[MockUser class] fromFile:@"a_lot_of_people.json"];
// WHEN
self.dataSource.ungroupedSearchResults = mockUsers;
// THEN
NSUInteger sections = [self.dataSource numberOfSectionsInTableView:[UITableView new]];
XCTAssertTrue(self.dataSource.shouldShowSectionIndex);
XCTAssertEqual(sections, 27ul, @"Number of sections");
}
- (void)testThatDataSourceHasCorrectNumbersOfRowsInSectionsForLargeNumberOfUsers
{
// GIVEN
NSArray *mockUsers = [MockLoader mockObjectsOfClass:[MockUser class] fromFile:@"a_lot_of_people.json"];
// WHEN
self.dataSource.ungroupedSearchResults = mockUsers;
// THEN
NSUInteger numberOfRawsInFirstSection = [self.dataSource tableView:[UITableView new] numberOfRowsInSection:0];
XCTAssertEqual(numberOfRawsInFirstSection, 20ul, @"");
NSUInteger numberOfSections = [self.dataSource numberOfSectionsInTableView:[UITableView new]];
NSUInteger numberOfRawsInLastSection = [self.dataSource tableView:[UITableView new] numberOfRowsInSection:numberOfSections - 2];
XCTAssertEqual(numberOfRawsInLastSection, 3ul, @"");
}
- (void)testPerformanceExample
{
// GIVEN
NSArray *mockUsers = [MockLoader mockObjectsOfClass:[MockUser class] fromFile:@"a_lot_of_people.json"];
[self measureBlock:^{
// WHEN
self.dataSource.ungroupedSearchResults = mockUsers;
}];
}
@end