forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASAbsoluteLayoutSpecSnapshotTests.m
70 lines (54 loc) · 2.73 KB
/
ASAbsoluteLayoutSpecSnapshotTests.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
//
// ASAbsoluteLayoutSpecSnapshotTests.m
// Texture
//
// Copyright (c) Facebook, Inc. and its affiliates. All rights reserved.
// Changes after 4/13/2017 are: Copyright (c) Pinterest, Inc. All rights reserved.
// Licensed under Apache 2.0: http://www.apache.org/licenses/LICENSE-2.0
//
#import "ASLayoutSpecSnapshotTestsHelper.h"
#import <AsyncDisplayKit/ASAbsoluteLayoutSpec.h>
#import <AsyncDisplayKit/ASBackgroundLayoutSpec.h>
@interface ASAbsoluteLayoutSpecSnapshotTests : ASLayoutSpecSnapshotTestCase
@end
@implementation ASAbsoluteLayoutSpecSnapshotTests
- (void)testSizingBehaviour
{
[self testWithSizeRange:ASSizeRangeMake(CGSizeMake(150, 200), CGSizeMake(INFINITY, INFINITY))
identifier:@"underflowChildren"];
[self testWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(50, 100))
identifier:@"overflowChildren"];
// Expect the spec to wrap its content because children sizes are between constrained size
[self testWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(INFINITY / 2, INFINITY / 2))
identifier:@"wrappedChildren"];
}
- (void)testChildrenMeasuredWithAutoMaxSize
{
ASDisplayNode *firstChild = ASDisplayNodeWithBackgroundColor([UIColor redColor], (CGSize){50, 50});
firstChild.style.layoutPosition = CGPointMake(0, 0);
ASDisplayNode *secondChild = ASDisplayNodeWithBackgroundColor([UIColor blueColor], (CGSize){100, 100});
secondChild.style.layoutPosition = CGPointMake(10, 60);
ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(10, 10), CGSizeMake(110, 160));
[self testWithChildren:@[firstChild, secondChild] sizeRange:sizeRange identifier:nil];
}
- (void)testWithSizeRange:(ASSizeRange)sizeRange identifier:(NSString *)identifier
{
ASDisplayNode *firstChild = ASDisplayNodeWithBackgroundColor([UIColor redColor], (CGSize){50, 50});
firstChild.style.layoutPosition = CGPointMake(0, 0);
ASDisplayNode *secondChild = ASDisplayNodeWithBackgroundColor([UIColor blueColor], (CGSize){100, 100});
secondChild.style.layoutPosition = CGPointMake(0, 50);
[self testWithChildren:@[firstChild, secondChild] sizeRange:sizeRange identifier:identifier];
}
- (void)testWithChildren:(NSArray *)children sizeRange:(ASSizeRange)sizeRange identifier:(NSString *)identifier
{
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor whiteColor]);
NSMutableArray *subnodes = [NSMutableArray arrayWithArray:children];
[subnodes insertObject:backgroundNode atIndex:0];
ASLayoutSpec *layoutSpec =
[ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:
[ASAbsoluteLayoutSpec
absoluteLayoutSpecWithChildren:children]
background:backgroundNode];
[self testLayoutSpec:layoutSpec sizeRange:sizeRange subnodes:subnodes identifier:identifier];
}
@end