NSArray+MASAdditionsSpec.m
4.7 KB
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
//
// NSArray+MASAdditionsSpec.m
// Masonry
//
// Created by Daniel Hammond on 11/26/13.
//
#import "NSArray+MASAdditions.h"
#import "MASViewConstraint.h"
SpecBegin(NSArray_MASAdditions)
- (void)testShouldFailWhenArrayContainsNonViews {
NSArray *array = @[ MAS_VIEW.new, [NSObject new] ];
expect(^{
[array mas_makeConstraints:^(MASConstraintMaker *make) {}];
}).to.raise(@"NSInternalInconsistencyException");
}
- (void)testShouldCreateConstraintsForEachView {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
NSArray *views = @[ subject1, subject2 ];
NSArray *constraints = [views mas_makeConstraints:^(MASConstraintMaker *make) {
expect(make.updateExisting).to.beFalsy();
make.width.equalTo(superView);
}];
expect(constraints).to.haveCountOf(views.count);
for (MASViewConstraint *constraint in constraints) {
MASViewAttribute *firstAttribute = [constraint firstViewAttribute];
expect([views indexOfObject:firstAttribute.view]).toNot.equal(NSNotFound);
expect(firstAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
MASViewAttribute *second = [constraint secondViewAttribute];
expect(second.view).to.equal(superView);
expect(second.layoutAttribute).to.equal(NSLayoutAttributeWidth);
}
}
- (void)testShouldSetUpdateExistingForArray {
NSArray *views = @[ MAS_VIEW.new ];
[views mas_updateConstraints:^(MASConstraintMaker *make) {
expect(make.updateExisting).to.beTruthy();
}];
}
- (void)testShouldSetRemoveExistingForArray {
NSArray *views = @[ MAS_VIEW.new ];
[views mas_remakeConstraints:^(MASConstraintMaker *make) {
expect(make.removeExisting).to.beTruthy();
}];
}
- (void)testDistributeViewsWithFixedSpacingShouldFailWhenArrayContainsLessTwoViews {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
NSArray *views = @[ subject1];
expect(^{
[views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10.0 leadSpacing:5.0 tailSpacing:5.0];
}).to.raiseAny();
}
- (void)testDistributeViewsWithFixedItemLengthShouldFailWhenArrayContainsLessTwoViews {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
NSArray *views = @[ subject1];
expect(^{
[views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10.0 leadSpacing:5.0 tailSpacing:5.0];
}).to.raiseAny();
}
- (void)testDistributeViewsWithFixedSpacingShouldHaveCorrectNumberOfConstraints {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
MAS_VIEW *subject3 = MAS_VIEW.new;
[superView addSubview:subject3];
NSArray *views = @[ subject1,subject2,subject3 ];
[views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedSpacing:10.0 leadSpacing:5.0 tailSpacing:5.0];
//left view
NSArray *arr1 = [MASViewConstraint installedConstraintsForView:subject1];
expect(arr1).to.haveCountOf(1);
//middle view
NSArray *arr2 = [MASViewConstraint installedConstraintsForView:subject2];
expect(arr2).to.haveCountOf(2);
//right view
NSArray *arr3 = [MASViewConstraint installedConstraintsForView:subject3];
expect(arr3).to.haveCountOf(3);
}
- (void)testDistributeViewsWithFixedItemLengthShouldHaveCorrectNumberOfConstraints {
MAS_VIEW *superView = MAS_VIEW.new;
MAS_VIEW *subject1 = MAS_VIEW.new;
[superView addSubview:subject1];
MAS_VIEW *subject2 = MAS_VIEW.new;
[superView addSubview:subject2];
MAS_VIEW *subject3 = MAS_VIEW.new;
[superView addSubview:subject3];
NSArray *views = @[ subject1,subject2,subject3 ];
[views mas_distributeViewsAlongAxis:MASAxisTypeHorizontal withFixedItemLength:30.0 leadSpacing:5.0 tailSpacing:5.0];
//left view
NSArray *arr1 = [MASViewConstraint installedConstraintsForView:subject1];
expect(arr1).to.haveCountOf(2);
//middle view
NSArray *arr2 = [MASViewConstraint installedConstraintsForView:subject2];
expect(arr2).to.haveCountOf(2);
//right view
NSArray *arr3 = [MASViewConstraint installedConstraintsForView:subject3];
expect(arr3).to.haveCountOf(2);
}
SpecEnd