|  | 
| 2 | 2 | //  ASDisplayNodeImplicitHierarchyTests.m | 
| 3 | 3 | //  Texture | 
| 4 | 4 | // | 
| 5 |  | -//  Created by Levi McCallum on 2/1/16. | 
| 6 |  | -// | 
| 7 | 5 | //  Copyright (c) 2014-present, Facebook, Inc.  All rights reserved. | 
| 8 | 6 | //  This source code is licensed under the BSD-style license found in the | 
| 9 | 7 | //  LICENSE file in the /ASDK-Licenses directory of this source tree. An additional | 
|  | 
| 20 | 18 | #import <XCTest/XCTest.h> | 
| 21 | 19 | 
 | 
| 22 | 20 | #import <AsyncDisplayKit/AsyncDisplayKit.h> | 
|  | 21 | +#import <AsyncDisplayKit/ASDisplayNode+FrameworkPrivate.h> | 
| 23 | 22 | #import "ASDisplayNodeTestsHelper.h" | 
| 24 | 23 | 
 | 
| 25 | 24 | @interface ASSpecTestDisplayNode : ASDisplayNode | 
| @@ -101,6 +100,47 @@ - (void)testInitialNodeInsertionWithOrdering | 
| 101 | 100 |   XCTAssertEqual(node.subnodes[4], node5); | 
| 102 | 101 | } | 
| 103 | 102 | 
 | 
|  | 103 | +- (void)testInitialNodeInsertionWhenEnterPreloadState | 
|  | 104 | +{ | 
|  | 105 | +  static CGSize kSize = {100, 100}; | 
|  | 106 | + | 
|  | 107 | +  static NSInteger subnodeCount = 5; | 
|  | 108 | +  NSMutableArray<ASDisplayNode *> *subnodes = [NSMutableArray arrayWithCapacity:subnodeCount]; | 
|  | 109 | +  for (NSInteger i = 0; i < subnodeCount; i++) { | 
|  | 110 | +    ASDisplayNode *subnode = [[ASDisplayNode alloc] init]; | 
|  | 111 | +    // As we will involve a stack spec we have to give the nodes an intrinsic content size | 
|  | 112 | +    subnode.style.preferredSize = kSize; | 
|  | 113 | +    [subnodes addObject:subnode]; | 
|  | 114 | +  } | 
|  | 115 | + | 
|  | 116 | +  ASSpecTestDisplayNode *node = [[ASSpecTestDisplayNode alloc] init]; | 
|  | 117 | +  node.automaticallyManagesSubnodes = YES; | 
|  | 118 | +  node.layoutSpecBlock = ^(ASDisplayNode *weakNode, ASSizeRange constrainedSize) { | 
|  | 119 | +    ASAbsoluteLayoutSpec *absoluteLayout = [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[subnodes[3]]]; | 
|  | 120 | + | 
|  | 121 | +    ASStackLayoutSpec *stack1 = [[ASStackLayoutSpec alloc] init]; | 
|  | 122 | +    [stack1 setChildren:@[subnodes[0], subnodes[1]]]; | 
|  | 123 | + | 
|  | 124 | +    ASStackLayoutSpec *stack2 = [[ASStackLayoutSpec alloc] init]; | 
|  | 125 | +    [stack2 setChildren:@[subnodes[2], absoluteLayout]]; | 
|  | 126 | + | 
|  | 127 | +    return [ASAbsoluteLayoutSpec absoluteLayoutSpecWithChildren:@[stack1, stack2, subnodes[4]]]; | 
|  | 128 | +  }; | 
|  | 129 | + | 
|  | 130 | +  ASDisplayNodeSizeToFitSizeRange(node, ASSizeRangeMake(CGSizeZero, CGSizeMake(CGFLOAT_MAX, CGFLOAT_MAX))); | 
|  | 131 | +  [node recursivelySetInterfaceState:ASInterfaceStatePreload]; | 
|  | 132 | + | 
|  | 133 | +  // No premature view allocation | 
|  | 134 | +  XCTAssertFalse(node.isNodeLoaded); | 
|  | 135 | +  // Subnodes should be inserted, laid out and entered preload state | 
|  | 136 | +  XCTAssertTrue([subnodes isEqualToArray:node.subnodes]); | 
|  | 137 | +  for (NSInteger i = 0; i < subnodeCount; i++) { | 
|  | 138 | +    ASDisplayNode *subnode = subnodes[i]; | 
|  | 139 | +    XCTAssertTrue(CGSizeEqualToSize(kSize, subnode.bounds.size)); | 
|  | 140 | +    XCTAssertTrue(ASInterfaceStateIncludesPreload(subnode.interfaceState)); | 
|  | 141 | +  } | 
|  | 142 | +} | 
|  | 143 | + | 
| 104 | 144 | - (void)testCalculatedLayoutHierarchyTransitions | 
| 105 | 145 | { | 
| 106 | 146 |   static CGSize kSize = {100, 100}; | 
|  | 
0 commit comments