private InternalNode createInternalNodeForMeasurableComponent(Component component) { InternalNode node = LayoutState.createTree( component, mContext); return node; }
@Test public void testCopyPropsOnlyCalledOnce() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(final ComponentContext c) { return Column.create(c).child(Column.create(c).flexGrow(1)).build(); } }; final InternalNode root = LayoutState.createTree(component, new MockInternalNodeComponentContext(application)); assertThat(root.getChildAt(0) instanceof TestInternalNode).isTrue(); assertThat(((TestInternalNode) root.getChildAt(0)).mFlexGrowCounter).isEqualTo(1); }
InternalNode node = LayoutState.createTree(component, mComponentContext); assertThat(node.getChildCount()).isEqualTo(0); assertThat(node.getRootComponent()).isInstanceOf(TestSizeDependentComponent.class);
InternalNode node = LayoutState.createTree(component, mComponentContext); assertThat(node.getChildCount()).isEqualTo(0); assertThat(node.getRootComponent()).isInstanceOf(TestDrawableComponent.class);
InternalNode node = LayoutState.createTree(component, mComponentContext); assertThat(node.getNodeInfo().getClickHandler()).isEqualTo(clickHandler3); assertThat(node.getNodeInfo().getLongClickHandler()).isEqualTo(longClickHandler3);
InternalNode node = LayoutState.createTree(component, mComponentContext);
InternalNode node = LayoutState.createTree(component, mComponentContext); assertThat(node.getNodeInfo().getClickHandler()).isEqualTo(clickHandler3); assertThat(node.getNodeInfo().getLongClickHandler()).isEqualTo(longClickHandler3);
@Test public void testSimpleLayoutCreatesExpectedInternalNodeTree() { final Component component = new InlineLayoutSpec() { @Override protected Component onCreateLayout(final ComponentContext c) { return Column.create(c) .child(Column.create(c).child(TestDrawableComponent.create(c))) .build(); } }; InternalNode node = LayoutState.createTree(component, mComponentContext); assertThat(node.getChildCount()).isEqualTo(1); assertThat(node.getRootComponent()).isEqualTo(component); node = node.getChildAt(0); assertThat(node.getChildCount()).isEqualTo(1); assertThat(node.getRootComponent()).isInstanceOf(Column.class); node = node.getChildAt(0); assertThat(node.getChildCount()).isEqualTo(0); assertThat(node.getRootComponent()).isInstanceOf(TestDrawableComponent.class); }
@Test public void testCachedMeasures() { final Component component1 = new TestLayoutSpec(false); final Component component2 = new TestLayoutSpec(false); LayoutState prevLayoutState = calculateLayoutStateWithDiffing( mContext, component1, SizeSpec.makeSizeSpec(350, SizeSpec.EXACTLY), SizeSpec.makeSizeSpec(200, SizeSpec.EXACTLY), null); // Check diff tree is consistent. DiffNode node = prevLayoutState.getDiffTree(); InternalNode layoutTreeRoot = LayoutState.createTree( component2, mContext); LayoutState.applyDiffNodeToUnchangedNodes(layoutTreeRoot, node); checkAllComponentsHaveMeasureCache(layoutTreeRoot); }
c.setHeightSpec(heightSpec); final InternalNode root = createTree( component, c);
@Test public void testPartiallyCachedMeasures() { final Component component1 = new TestLayoutSpec(false); final Component component2 = new TestLayoutSpec(true); LayoutState prevLayoutState = calculateLayoutStateWithDiffing( mContext, component1, SizeSpec.makeSizeSpec(350, SizeSpec.EXACTLY), SizeSpec.makeSizeSpec(200, SizeSpec.EXACTLY), null); // Check diff tree is consistent. DiffNode node = prevLayoutState.getDiffTree(); InternalNode layoutTreeRoot = LayoutState.createTree( component2, mContext); LayoutState.applyDiffNodeToUnchangedNodes(layoutTreeRoot, node); InternalNode child_1 = (InternalNode) layoutTreeRoot.getChildAt(0); assertCachedMeasurementsDefined(child_1); InternalNode child_2 = (InternalNode) layoutTreeRoot.getChildAt(1); assertCachedMeasurementsNotDefined(child_2); InternalNode child_3 = (InternalNode) child_2.getChildAt(0); assertCachedMeasurementsDefined(child_3); InternalNode child_4 = (InternalNode) layoutTreeRoot.getChildAt(2); assertCachedMeasurementsNotDefined(child_4); }