|  | 
|  | 1 | +// | 
|  | 2 | +//  ASStaticLayoutSpecSnapshotTests.m | 
|  | 3 | +//  AsyncDisplayKit | 
|  | 4 | +// | 
|  | 5 | +//  Created by Huy Nguyen on 18/10/15. | 
|  | 6 | +//  Copyright (c) 2015 Facebook. All rights reserved. | 
|  | 7 | +// | 
|  | 8 | + | 
|  | 9 | +#import "ASLayoutSpecSnapshotTestsHelper.h" | 
|  | 10 | + | 
|  | 11 | +#import "ASStaticLayoutSpec.h" | 
|  | 12 | +#import "ASBackgroundLayoutSpec.h" | 
|  | 13 | + | 
|  | 14 | +@interface ASStaticLayoutSpecSnapshotTests : ASLayoutSpecSnapshotTestCase | 
|  | 15 | +@end | 
|  | 16 | + | 
|  | 17 | +@implementation ASStaticLayoutSpecSnapshotTests | 
|  | 18 | + | 
|  | 19 | +- (void)setUp | 
|  | 20 | +{ | 
|  | 21 | +  [super setUp]; | 
|  | 22 | +  self.recordMode = NO; | 
|  | 23 | +} | 
|  | 24 | + | 
|  | 25 | +- (void)testSizingBehaviour | 
|  | 26 | +{ | 
|  | 27 | +  [self testWithSizeRange:ASSizeRangeMake(CGSizeMake(150, 200), CGSizeMake(FLT_MAX, FLT_MAX)) | 
|  | 28 | +               identifier:@"underflowChildren"]; | 
|  | 29 | +  [self testWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(50, 100)) | 
|  | 30 | +               identifier:@"overflowChildren"]; | 
|  | 31 | +  // Expect the spec to wrap its content because children sizes are between constrained size | 
|  | 32 | +  [self testWithSizeRange:ASSizeRangeMake(CGSizeZero, CGSizeMake(FLT_MAX / 2, FLT_MAX / 2)) | 
|  | 33 | +               identifier:@"wrappedChildren"]; | 
|  | 34 | +} | 
|  | 35 | + | 
|  | 36 | +- (void)testChildrenMeasuredWithAutoMaxSize | 
|  | 37 | +{ | 
|  | 38 | +  ASStaticSizeDisplayNode *firstChild = ASDisplayNodeWithBackgroundColor([UIColor redColor]); | 
|  | 39 | +  firstChild.layoutPosition = CGPointMake(0, 0); | 
|  | 40 | +  firstChild.staticSize = CGSizeMake(50, 50); | 
|  | 41 | +   | 
|  | 42 | +  ASStaticSizeDisplayNode *secondChild = ASDisplayNodeWithBackgroundColor([UIColor blueColor]); | 
|  | 43 | +  secondChild.layoutPosition = CGPointMake(10, 60); | 
|  | 44 | +  secondChild.staticSize = CGSizeMake(100, 100); | 
|  | 45 | + | 
|  | 46 | +  ASSizeRange sizeRange = ASSizeRangeMake(CGSizeMake(10, 10), CGSizeMake(110, 160)); | 
|  | 47 | +  [self testWithChildren:@[firstChild, secondChild] sizeRange:sizeRange identifier:nil]; | 
|  | 48 | +   | 
|  | 49 | +  XCTAssertTrue(ASSizeRangeEqualToSizeRange(firstChild.constrainedSizeForCalculatedLayout, | 
|  | 50 | +                                            ASSizeRangeMake(CGSizeZero, sizeRange.max))); | 
|  | 51 | +  CGSize secondChildMaxSize = CGSizeMake(sizeRange.max.width - secondChild.layoutPosition.x, | 
|  | 52 | +                                         sizeRange.max.height - secondChild.layoutPosition.y); | 
|  | 53 | +  XCTAssertTrue(ASSizeRangeEqualToSizeRange(secondChild.constrainedSizeForCalculatedLayout, | 
|  | 54 | +                                            ASSizeRangeMake(CGSizeZero, secondChildMaxSize))); | 
|  | 55 | +} | 
|  | 56 | + | 
|  | 57 | +- (void)testWithSizeRange:(ASSizeRange)sizeRange identifier:(NSString *)identifier | 
|  | 58 | +{ | 
|  | 59 | +  ASDisplayNode *firstChild = ASDisplayNodeWithBackgroundColor([UIColor redColor]); | 
|  | 60 | +  firstChild.layoutPosition = CGPointMake(0, 0); | 
|  | 61 | +  firstChild.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(CGSizeMake(50, 50)); | 
|  | 62 | +   | 
|  | 63 | +   | 
|  | 64 | +  ASDisplayNode *secondChild = ASDisplayNodeWithBackgroundColor([UIColor blueColor]); | 
|  | 65 | +  secondChild.layoutPosition = CGPointMake(0, 50); | 
|  | 66 | +  secondChild.sizeRange = ASRelativeSizeRangeMakeWithExactCGSize(CGSizeMake(100, 100)); | 
|  | 67 | +   | 
|  | 68 | +  [self testWithChildren:@[firstChild, secondChild] sizeRange:sizeRange identifier:identifier]; | 
|  | 69 | +} | 
|  | 70 | + | 
|  | 71 | +- (void)testWithChildren:(NSArray *)children sizeRange:(ASSizeRange)sizeRange identifier:(NSString *)identifier | 
|  | 72 | +{ | 
|  | 73 | +  ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor whiteColor]); | 
|  | 74 | + | 
|  | 75 | +  NSMutableArray *subnodes = [NSMutableArray arrayWithArray:children]; | 
|  | 76 | +  [subnodes insertObject:backgroundNode atIndex:0]; | 
|  | 77 | + | 
|  | 78 | +  ASStaticLayoutSpec *staticLayoutSpec = [ASStaticLayoutSpec staticLayoutSpecWithChildren:children]; | 
|  | 79 | +  ASLayoutSpec *layoutSpec = [ASBackgroundLayoutSpec backgroundLayoutSpecWithChild:staticLayoutSpec | 
|  | 80 | +                                                                        background:backgroundNode]; | 
|  | 81 | +   | 
|  | 82 | +  [self testLayoutSpec:layoutSpec sizeRange:sizeRange subnodes:subnodes identifier:identifier]; | 
|  | 83 | +} | 
|  | 84 | + | 
|  | 85 | +@end | 
0 commit comments