forked from ParisiLabs/wire-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToolTipViewControllerTests.m
147 lines (111 loc) · 4.99 KB
/
ToolTipViewControllerTests.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
//
// 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 ToolTipViewControllerTests : ZMSnapshotTestCase
@property (nonatomic) ToolTipViewController *sut;
@end
@implementation ToolTipViewControllerTests
- (void)setUp {
[super setUp];
self.accentColor = ZMAccentColorBrightOrange;
self.sut = [[ToolTipViewController alloc] initWithToolTip:[self toolTipWithHandler:nil]];
}
- (void)testThatItConfiguresTheViewCorrectlyWhenToolTipIsSet_ArrowLeft {
// given
UIView *contentView = [[UIView alloc] initForAutoLayout];
UIView *referenceView = [[UIView alloc] initForAutoLayout];
[contentView addSubview:referenceView];
[contentView addSubview:self.sut.view];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeRight];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[referenceView autoSetDimensionsToSize:CGSizeMake(50, 50)];
[referenceView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[referenceView autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
[referenceView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.sut.view];
// when
[self.sut makeTipPointToView:referenceView];
// then
ZMVerifyViewInAllIPhoneWidths(contentView);
}
- (void)testThatItConfiguresTheViewCorrectlyWhenToolTipIsSet_ArrowRight {
// given
UIView *contentView = [[UIView alloc] initForAutoLayout];
UIView *referenceView = [[UIView alloc] initForAutoLayout];
[contentView addSubview:referenceView];
[contentView addSubview:self.sut.view];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeRight];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[referenceView autoSetDimensionsToSize:CGSizeMake(50, 50)];
[referenceView autoPinEdgeToSuperviewEdge:ALEdgeTop];
[referenceView autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
[referenceView autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.sut.view];
// when
[self.sut makeTipPointToView:referenceView];
// then
ZMVerifyViewInAllIPhoneWidths(contentView);
}
- (void)testThatItConfiguresTheViewCorrectlyWhenToolTipIsModified {
// given
UIView *contentView = [[UIView alloc] initForAutoLayout];
UIView *referenceView1 = [[UIView alloc] initForAutoLayout];
UIView *referenceView2 = [[UIView alloc] initForAutoLayout];
[contentView addSubview:referenceView1];
[contentView addSubview:referenceView2];
[contentView addSubview:self.sut.view];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeLeft];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeRight];
[self.sut.view autoPinEdgeToSuperviewEdge:ALEdgeBottom];
[referenceView1 autoSetDimensionsToSize:CGSizeMake(50, 50)];
[referenceView1 autoPinEdgeToSuperviewEdge:ALEdgeTop];
[referenceView1 autoPinEdgeToSuperviewEdge:ALEdgeRight withInset:10];
[referenceView1 autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.sut.view];
[referenceView2 autoSetDimensionsToSize:CGSizeMake(50, 50)];
[referenceView2 autoPinEdgeToSuperviewEdge:ALEdgeTop];
[referenceView2 autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:10];
[referenceView2 autoPinEdge:ALEdgeBottom toEdge:ALEdgeTop ofView:self.sut.view];
[self.sut makeTipPointToView:referenceView1];
// when
[self.sut makeTipPointToView:referenceView2];
// then
ZMVerifyViewInAllIPhoneWidths(contentView);
}
- (void)testThatItExecutesTheToolTipHandlerWhenTheViewIsTapped {
// given
__block NSUInteger tapCount = 0;
self.sut = [[ToolTipViewController alloc] initWithToolTip:[self toolTipWithHandler:^{
tapCount++;
}]];
// when
[self.sut didTapView:[UITapGestureRecognizer new]];
// then
XCTAssertEqual(tapCount, 1lu);
}
#pragma mark - Helper
- (ToolTip *)toolTipWithHandler:(dispatch_block_t)handler
{
return [[ToolTip alloc] initWithTitle:@"This is an awesome title!"
description:@"This is a very descriptive description. This describes exaclty what you should do next."
handler:handler];
}
@end