forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConversationListBottomBarTests.m
186 lines (151 loc) · 5.38 KB
/
ConversationListBottomBarTests.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//
// 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 "ZMSnapshotTestCase.h"
#import "Wire_iOS_Tests-Swift.h"
#import "Wire-Swift.h"
#import <PureLayout/PureLayout.h>
#import <Classy/Classy.h>
@interface MockConversationListBottomBarDelegate : NSObject <ConversationListBottomBarControllerDelegate>
@property (nonatomic) NSUInteger contactsButtonTapCount;
@property (nonatomic) NSUInteger settingsButtonTapCount;
@property (nonatomic) NSUInteger archiveButtonTapCount;
@end
@implementation MockConversationListBottomBarDelegate
- (instancetype)init
{
self = [super init];
return self;
}
- (void)conversationListBottomBar:(ConversationListBottomBarController *)bar didTapButtonWithType:(enum ConversationListButtonType)buttonType
{
switch (buttonType) {
case ConversationListButtonTypeArchive:
self.archiveButtonTapCount++;
break;
case ConversationListButtonTypeContacts:
self.contactsButtonTapCount++;
break;
case ConversationListButtonTypeSettings:
self.settingsButtonTapCount++;
break;
default:
break;
}
}
@end
@interface ConversationListBottomBarTests : ZMSnapshotTestCase
@property (nonatomic) ConversationListBottomBarController *sut;
@property (nonatomic) MockConversationListBottomBarDelegate *mockDelegate;
@end
@implementation ConversationListBottomBarTests
- (void)setUp
{
[super setUp];
self.snapshotBackgroundColor = [UIColor colorWithWhite:0.2 alpha:1]; // In order to make the separator more visible
self.accentColor = ZMAccentColorBrightYellow;
self.mockDelegate = [MockConversationListBottomBarDelegate new];
[UIView performWithoutAnimation:^{
self.sut = [[ConversationListBottomBarController alloc] initWithDelegate:self.mockDelegate user:nil];
}];
[CASStyler.defaultStyler styleItem:self.sut];
}
- (void)testThatItRendersTheBottomBarCorrectlyInInitialState
{
// when
XCTAssertFalse(self.sut.showSeparator);
XCTAssertFalse(self.sut.showIndicator);
// then
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatTheSeparatorIsNotHiddenWhen_ShowSeparator_IsSetToYes
{
// when
self.sut.showSeparator = YES;
// then
XCTAssertFalse(self.sut.separator.hidden);
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatTheIndicatorIsNotHiddenWhen_ShowIndicator_IsSetToYes
{
// when
self.sut.showIndicator = YES;
// then
XCTAssertFalse(self.sut.indicator.hidden);
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatItHidesTheContactsTitleAndShowsArchivedButtonWhen_ShowArchived_IsSetToYes
{
// when
self.sut.showArchived = YES;
// then
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatItHidesTheContactsTitleAndShowsArchivedButtonAndShowsTheIndicatorWhen_ShowArchivedAndShowIndicator_AreSetToYes
{
// when
self.sut.showArchived = YES;
self.sut.showIndicator = YES;
// then
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatItShowsTheContactsTitleAndHidesTheArchivedButtonWhen_ShowArchived_WasSetToYesAndIsSetToNo
{
// given
self.accentColor = ZMAccentColorStrongBlue; // To make the snapshot distinguishable from the inital state
[CASStyler.defaultStyler styleItem:self.sut];
self.sut.showArchived = YES;
// when
self.sut.showArchived = NO;
// then
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatTheSelectionIsOn_showTooltipSetToYes
{
// when
self.sut.showTooltip = YES;
// then
ZMVerifyViewInAllIPhoneWidths(self.sut.view);
}
- (void)testThatItCallsTheDelegateWhenTheContactsButtonIsTapped
{
// when
[self.sut.contactsButton sendActionsForControlEvents:UIControlEventTouchUpInside];
// then
XCTAssertEqual(self.mockDelegate.contactsButtonTapCount, 1lu);
XCTAssertEqual(self.mockDelegate.settingsButtonTapCount, 0lu);
XCTAssertEqual(self.mockDelegate.archiveButtonTapCount, 0lu);
}
- (void)testThatItCallsTheDelegateWhenTheSettingsButtonIsTapped
{
// when
[self.sut.settingsButton sendActionsForControlEvents:UIControlEventTouchUpInside];
// then
XCTAssertEqual(self.mockDelegate.contactsButtonTapCount, 0lu);
XCTAssertEqual(self.mockDelegate.settingsButtonTapCount, 1lu);
XCTAssertEqual(self.mockDelegate.archiveButtonTapCount, 0lu);
}
- (void)testThatItCallsTheDelegateWhenTheArchivedButtonIsTapped
{
// when
[self.sut.archivedButton sendActionsForControlEvents:UIControlEventTouchUpInside];
// then
XCTAssertEqual(self.mockDelegate.contactsButtonTapCount, 0lu);
XCTAssertEqual(self.mockDelegate.settingsButtonTapCount, 0lu);
XCTAssertEqual(self.mockDelegate.archiveButtonTapCount, 1lu);
}
@end