MASCompositeConstraintSpec.m
2.99 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
//
// MASCompositeConstraintSpec.m
// Masonry
//
// Created by Jonas Budelmann on 22/07/13.
// Copyright (c) 2013 cloudling. All rights reserved.
//
#import "MASCompositeConstraint.h"
#import "MASViewConstraint.h"
#import "MASConstraintDelegateMock.h"
#import "View+MASAdditions.h"
@interface MASCompositeConstraint () <MASConstraintDelegate>
@property (nonatomic, strong) NSMutableArray *childConstraints;
@end
@interface MASViewConstraint ()
@property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
@property (nonatomic, assign) CGFloat layoutConstant;
@property (nonatomic, assign) MASLayoutPriority layoutPriority;
@end
SpecBegin(MASCompositeConstraint)
__block MASConstraintDelegateMock *delegate;
__block MAS_VIEW *superview;
__block MAS_VIEW *view;
__block MASCompositeConstraint *composite;
beforeEach(^{
delegate = MASConstraintDelegateMock.new;
view = MAS_VIEW.new;
superview = MAS_VIEW.new;
[superview addSubview:view];
NSArray *children = @[
[[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_width],
[[MASViewConstraint alloc] initWithFirstViewAttribute:view.mas_height]
];
composite = [[MASCompositeConstraint alloc] initWithChildren:children];
composite.delegate = delegate;
});
it(@"should complete children", ^{
MAS_VIEW *newView = MAS_VIEW.new;
//first equality statement
composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30)).priorityLow();
expect(composite.childConstraints).to.haveCountOf(2);
MASViewConstraint *viewConstraint = [composite.childConstraints objectAtIndex:0];
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(newView);
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeWidth);
expect(viewConstraint.layoutConstant).to.equal(90);
expect(viewConstraint.layoutPriority).to.equal(MASLayoutPriorityDefaultLow);
viewConstraint = [composite.childConstraints objectAtIndex:1];
expect(viewConstraint.secondViewAttribute.view).to.beIdenticalTo(newView);
expect(viewConstraint.secondViewAttribute.layoutAttribute).to.equal(NSLayoutAttributeHeight);
expect(viewConstraint.layoutConstant).to.equal(30);
expect(viewConstraint.layoutPriority).to.equal(MASLayoutPriorityDefaultLow);
});
it(@"should not remove on install", ^{
MAS_VIEW *newView = MAS_VIEW.new;
[superview addSubview:newView];
//first equality statement
composite.equalTo(newView).sizeOffset(CGSizeMake(90, 30));
[composite install];
expect(composite.childConstraints).to.haveCountOf(2);
});
it(@"should spawn child composite constraints", ^{
MAS_VIEW *otherView = MAS_VIEW.new;
[superview addSubview:otherView];
composite.lessThanOrEqualTo(@[@2, otherView]);
expect(composite.childConstraints).to.haveCountOf(2);
expect([composite.childConstraints objectAtIndex:0]).to.beKindOf(MASCompositeConstraint.class);
expect([composite.childConstraints objectAtIndex:1]).to.beKindOf(MASCompositeConstraint.class);
});
SpecEnd