forked from TextureGroup/Texture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathASScrollNodeTests.m
139 lines (105 loc) · 4.62 KB
/
ASScrollNodeTests.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
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
//
// ASScrollNodeTests.m
// Texture
//
// Copyright (c) 2017-present, Pinterest, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
#import <UIKit/UIKit.h>
#import <XCTest/XCTest.h>
#import <AsyncDisplayKit/AsyncDisplayKit.h>
#import "ASXCTExtensions.h"
@interface ASScrollNodeTests : XCTestCase
@property (nonatomic) ASScrollNode *scrollNode;
@property (nonatomic) ASDisplayNode *subnode;
@end
@implementation ASScrollNodeTests
- (void)setUp
{
ASDisplayNode *subnode = [[ASDisplayNode alloc] init];
self.subnode = subnode;
self.scrollNode = [[ASScrollNode alloc] init];
self.scrollNode.scrollableDirections = ASScrollDirectionVerticalDirections;
self.scrollNode.automaticallyManagesContentSize = YES;
self.scrollNode.automaticallyManagesSubnodes = YES;
self.scrollNode.layoutSpecBlock = ^ASLayoutSpec * _Nonnull(__kindof ASDisplayNode * _Nonnull node, ASSizeRange constrainedSize) {
return [[ASWrapperLayoutSpec alloc] initWithLayoutElement:subnode];
};
[self.scrollNode view];
}
- (void)testSubnodeLayoutCalculatedWithUnconstrainedMaxSizeInScrollableDirection
{
CGSize parentSize = CGSizeMake(100, 100);
ASSizeRange sizeRange = ASSizeRangeMake(parentSize);
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
ASSizeRange subnodeSizeRange = sizeRange;
subnodeSizeRange.max.height = CGFLOAT_MAX;
XCTAssertEqual(self.scrollNode.scrollableDirections, ASScrollDirectionVerticalDirections);
ASXCTAssertEqualSizeRanges(self.subnode.constrainedSizeForCalculatedLayout, subnodeSizeRange);
// Same test for horizontal scrollable directions
self.scrollNode.scrollableDirections = ASScrollDirectionHorizontalDirections;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
subnodeSizeRange = sizeRange;
subnodeSizeRange.max.width = CGFLOAT_MAX;
ASXCTAssertEqualSizeRanges(self.subnode.constrainedSizeForCalculatedLayout, subnodeSizeRange);
}
- (void)testAutomaticallyManagesContentSizeUnderflow
{
CGSize subnodeSize = CGSizeMake(100, 100);
CGSize parentSize = CGSizeMake(100, 200);
ASSizeRange sizeRange = ASSizeRangeUnconstrained;
self.subnode.style.preferredSize = subnodeSize;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, parentSize);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}
- (void)testAutomaticallyManagesContentSizeOverflow
{
CGSize subnodeSize = CGSizeMake(100, 500);
CGSize parentSize = CGSizeMake(100, 200);
ASSizeRange sizeRange = ASSizeRangeUnconstrained;
self.subnode.style.preferredSize = subnodeSize;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, parentSize);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}
- (void)testAutomaticallyManagesContentSizeWithSizeRangeSmallerThanParentSize
{
CGSize subnodeSize = CGSizeMake(100, 100);
CGSize parentSize = CGSizeMake(100, 500);
ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(100, 100), CGSizeMake(100, 200));
self.subnode.style.preferredSize = subnodeSize;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, sizeRange.max);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}
- (void)testAutomaticallyManagesContentSizeWithSizeRangeBiggerThanParentSize
{
CGSize subnodeSize = CGSizeMake(100, 200);
CGSize parentSize = CGSizeMake(100, 100);
ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(100, 150));
self.subnode.style.preferredSize = subnodeSize;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, sizeRange.min);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}
- (void)testAutomaticallyManagesContentSizeWithInvalidCalculatedSizeForLayout
{
CGSize subnodeSize = CGSizeMake(100, 200);
CGSize parentSize = CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX);
ASSizeRange sizeRange = ASSizeRangeUnconstrained;
self.subnode.style.preferredSize = subnodeSize;
[self.scrollNode layoutThatFits:sizeRange parentSize:parentSize];
[self.scrollNode layout];
ASXCTAssertEqualSizes(self.scrollNode.calculatedSize, subnodeSize);
ASXCTAssertEqualSizes(self.scrollNode.view.contentSize, subnodeSize);
}
@end