NSLayoutConstraint+MASDebugAdditionsSpec.m
2.41 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
//
// NSLayoutConstraint+MASDebugAdditionsSpec.m
// Masonry
//
// Created by Jonas Budelmann on 8/09/13.
// Copyright (c) 2013 Jonas Budelmann. All rights reserved.
//
#import "NSLayoutConstraint+MASDebugAdditions.h"
#import "View+MASAdditions.h"
#import "MASLayoutConstraint.h"
#import "MASCompositeConstraint.h"
#import "MASViewConstraint.h"
SpecBegin(NSLayoutConstraint_MASDebugAdditions)
it(@"should display view key", ^{
MAS_VIEW *newView = MAS_VIEW.new;
newView.mas_key = @"newView";
MASLayoutConstraint *layoutConstraint = [MASLayoutConstraint constraintWithItem:newView attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationGreaterThanOrEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1 constant:300];
layoutConstraint.priority = MASLayoutPriorityDefaultLow;
NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:%p %@:newView.width >= 300 ^low>", layoutConstraint, MAS_VIEW.class];
expect([layoutConstraint description]).to.equal(description);
});
it(@"should display layoutConstraint key", ^{
MAS_VIEW *newView1 = MAS_VIEW.new;
newView1.mas_key = @"newView1";
MAS_VIEW *newView2 = MAS_VIEW.new;
newView2.mas_key = @"newView2";
MASLayoutConstraint *layoutConstraint = [MASLayoutConstraint constraintWithItem:newView1 attribute:NSLayoutAttributeBaseline relatedBy:NSLayoutRelationEqual toItem:newView2 attribute:NSLayoutAttributeTop multiplier:2 constant:300];
layoutConstraint.mas_key = @"helloConstraint";
NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:helloConstraint %@:newView1.baseline == %@:newView2.top * 2 + 300>", MAS_VIEW.class, MAS_VIEW.class];
expect([layoutConstraint description]).to.equal(description);
});
it(@"should print constraint key", ^{
MAS_VIEW *superview = MAS_VIEW.new;
MAS_VIEW *newView1 = MAS_VIEW.new;
newView1.mas_key = @"newView1";
MAS_VIEW *newView2 = MAS_VIEW.new;
newView2.mas_key = @"newView2";
[superview addSubview:newView1];
[superview addSubview:newView2];
[newView1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.greaterThanOrEqualTo(@[newView2, @10]).key(@"left");
}];
NSString *description = [NSString stringWithFormat:@"<MASLayoutConstraint:left[0] %@:newView1.left == %@:newView2.left>", MAS_VIEW.class, MAS_VIEW.class];
expect([superview.constraints[0] description]).to.equal(description);
});
SpecEnd