@@ -10,13 +10,11 @@ import UIKit
10
10
import XCTest
11
11
import SnapLayout
12
12
13
- class SnapLayoutTests : XCTestCase {
13
+ /// Tests SnapLayout
14
+ class SnapLayoutTests : BaseTestCase {
14
15
15
16
/// Tests Snap Layout where no constraints were applied.
16
17
func testSnapInActiveError( ) {
17
- let childView = UIView ( )
18
- let superview = UIView ( )
19
- superview. addSubview ( childView)
20
18
let snapManager = childView. snap ( )
21
19
XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
22
20
XCTAssertNil ( snapManager. top)
@@ -31,58 +29,31 @@ class SnapLayoutTests: XCTestCase {
31
29
32
30
/// Tests Snap Width method
33
31
func testSnapWidth( ) {
34
- let view1 = UIView ( )
35
- let view2 = UIView ( )
36
- let containerView = UIView ( )
37
- containerView. addSubview ( view1)
38
- containerView. addSubview ( view2)
39
- let snapManager = view1. snapWidth ( to: view2, multiplier: 0.5 )
40
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
41
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
32
+ let snapManager = childView. snapWidth ( to: childView2, multiplier: 0.5 )
33
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
34
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
42
35
XCTAssertNotNil ( snapManager. width)
43
36
XCTAssertEqual ( snapManager. width!. isActive, true )
44
37
XCTAssertEqual ( snapManager. width!. constant, 0 )
45
38
XCTAssertEqual ( snapManager. width!. multiplier, 0.5 )
46
39
}
47
40
48
- /// Tests Snap Width where constraint was not applied
49
- func testsSnapWidthError( ) {
50
- let view1 = UIView ( )
51
- let snapManager = view1. snapWidth ( multiplier: 0.5 )
52
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, true )
53
- XCTAssertNil ( snapManager. width)
54
- }
55
-
56
41
/// Tets Snap Height method
57
42
func testSnapHeight( ) {
58
- let view1 = UIView ( )
59
- let view2 = UIView ( )
60
- let containerView = UIView ( )
61
- containerView. addSubview ( view1)
62
- containerView. addSubview ( view2)
63
- let snapManager = view1. snapHeight ( to: view2, multiplier: 0.5 )
64
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
65
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
43
+ let snapManager = childView. snapHeight ( to: childView2, multiplier: 0.5 )
44
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
45
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
66
46
XCTAssertNotNil ( snapManager. height)
67
47
XCTAssertEqual ( snapManager. height!. isActive, true )
68
48
XCTAssertEqual ( snapManager. height!. constant, 0 )
69
49
XCTAssertEqual ( snapManager. height!. multiplier, 0.5 )
70
50
}
71
51
72
- /// Tests Snap Height where constraint was not applied
73
- func testsSnapHeightError( ) {
74
- let view1 = UIView ( )
75
- let snapManager = view1. snapHeight ( multiplier: 0.5 )
76
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, true )
77
- XCTAssertNil ( snapManager. height)
78
- }
79
-
80
52
/// Tests Snap Size method
81
53
func testSnapSize( ) {
82
54
let size = CGSize ( width: 30 , height: 40 )
83
- let view1 = UIView ( )
84
- let snapManager = view1. snapSize ( size: size)
85
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
55
+ let snapManager = view. snapSize ( size: size)
56
+ XCTAssertEqual ( view. translatesAutoresizingMaskIntoConstraints, false )
86
57
XCTAssertNotNil ( snapManager. width)
87
58
XCTAssertNotNil ( snapManager. height)
88
59
XCTAssertEqual ( snapManager. width!. isActive, true )
@@ -96,14 +67,9 @@ class SnapLayoutTests: XCTestCase {
96
67
/// Tests Snap Trailing View
97
68
func testSnapTrailingView( ) {
98
69
let trailingConstant = CGFloat ( 8 )
99
- let view1 = UIView ( )
100
- let view2 = UIView ( )
101
- let containerView = UIView ( )
102
- containerView. addSubview ( view1)
103
- containerView. addSubview ( view2)
104
- let snapManager = view1. snap ( trailingView: view2, constant: trailingConstant)
105
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
106
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
70
+ let snapManager = childView. snap ( trailingView: childView2, constant: trailingConstant)
71
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
72
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
107
73
XCTAssertNotNil ( snapManager. trailing)
108
74
XCTAssertEqual ( snapManager. trailing!. isActive, true )
109
75
XCTAssertEqual ( snapManager. trailing!. constant, trailingConstant)
@@ -113,14 +79,9 @@ class SnapLayoutTests: XCTestCase {
113
79
/// Tests Snap Leading View
114
80
func testSnapLeadingView( ) {
115
81
let leadingConstant = CGFloat ( 8 )
116
- let view1 = UIView ( )
117
- let view2 = UIView ( )
118
- let containerView = UIView ( )
119
- containerView. addSubview ( view1)
120
- containerView. addSubview ( view2)
121
- let snapManager = view1. snap ( leadingView: view2, constant: leadingConstant)
122
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
123
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
82
+ let snapManager = childView. snap ( leadingView: childView2, constant: leadingConstant)
83
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
84
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
124
85
XCTAssertNotNil ( snapManager. leading)
125
86
XCTAssertEqual ( snapManager. leading!. isActive, true )
126
87
XCTAssertEqual ( snapManager. leading!. constant, leadingConstant)
@@ -130,14 +91,9 @@ class SnapLayoutTests: XCTestCase {
130
91
/// Tests Snap Bottom View
131
92
func testSnapBottomView( ) {
132
93
let bottomConstant = CGFloat ( 8 )
133
- let view1 = UIView ( )
134
- let view2 = UIView ( )
135
- let containerView = UIView ( )
136
- containerView. addSubview ( view1)
137
- containerView. addSubview ( view2)
138
- let snapManager = view1. snap ( bottomView: view2, constant: bottomConstant)
139
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
140
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
94
+ let snapManager = childView. snap ( bottomView: childView2, constant: bottomConstant)
95
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
96
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
141
97
XCTAssertNotNil ( snapManager. bottom)
142
98
XCTAssertEqual ( snapManager. bottom!. isActive, true )
143
99
XCTAssertEqual ( snapManager. bottom!. constant, bottomConstant)
@@ -147,14 +103,9 @@ class SnapLayoutTests: XCTestCase {
147
103
/// Tests Snap Trailing View
148
104
func testSnapTopView( ) {
149
105
let topConstant = CGFloat ( 8 )
150
- let view1 = UIView ( )
151
- let view2 = UIView ( )
152
- let containerView = UIView ( )
153
- containerView. addSubview ( view1)
154
- containerView. addSubview ( view2)
155
- let snapManager = view1. snap ( topView: view2, constant: topConstant)
156
- XCTAssertEqual ( view1. translatesAutoresizingMaskIntoConstraints, false )
157
- XCTAssertEqual ( view2. translatesAutoresizingMaskIntoConstraints, true )
106
+ let snapManager = childView. snap ( topView: childView2, constant: topConstant)
107
+ XCTAssertEqual ( childView. translatesAutoresizingMaskIntoConstraints, false )
108
+ XCTAssertEqual ( childView2. translatesAutoresizingMaskIntoConstraints, true )
158
109
XCTAssertNotNil ( snapManager. top)
159
110
XCTAssertEqual ( snapManager. top!. isActive, true )
160
111
XCTAssertEqual ( snapManager. top!. constant, topConstant)
0 commit comments