@Test public void testWillRenderTwiceDoesNotReCreateLayout() { ComponentContext c = new ComponentContext(application); final Component component = TestLayoutComponent.create(c, 0, 0, true, true, true, false).build(); Component.willRender(c, component); final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); assertThat(Component.willRender(c, component)).isTrue(); assertThat(component.getLayoutCreatedInWillRenderForTesting()).isEqualTo(cachedLayout); }
@Test public void testNewLayoutBuilderUsesWillRenderResult() { ComponentContext c = new ComponentContext(application); final Component component = TestLayoutComponent.create(c, 0, 0, true, true, true, false).build(); Component.willRender(c, component); final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); InternalNode result = c.newLayoutBuilder(component, 0, 0); assertThat(result).isEqualTo(cachedLayout); assertThat(component.getLayoutCreatedInWillRenderForTesting()).isNull(); }
@Test public void testResolveLayoutUsesWillRenderResult() { ComponentContext c = new ComponentContext(application); final Component component = TestLayoutComponent.create(c, 0, 0, true, true, true, false).build(); Component.willRender(c, component); final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); InternalNode result = c.resolveLayout(component); assertThat(result).isEqualTo(cachedLayout); assertThat(component.getLayoutCreatedInWillRenderForTesting()).isNull(); }
@Test public void testCreateLayoutUsesWillRenderResult() { ComponentContext c = new ComponentContext(application); final Component component = TestLayoutComponent.create(c, 0, 0, true, true, true, false).build(); Component.willRender(c, component); final InternalNode cachedLayout = component.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); InternalNode result = component.createLayout(c, false); assertThat(result).isEqualTo(cachedLayout); assertThat(component.getLayoutCreatedInWillRenderForTesting()).isNull(); }
@Test public void testWillRenderLayoutsOnce() { ComponentContext c = new ComponentContext(application); final Component componentSpy = spy(TestLayoutComponent.create(c, 0, 0, true, true, true, false).build()); Component.willRender(c, componentSpy); final InternalNode cachedLayout = componentSpy.getLayoutCreatedInWillRenderForTesting(); assertThat(cachedLayout).isNotNull(); calculateLayoutState( c.getAndroidContext(), componentSpy, -1, makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY)); assertThat(componentSpy.getLayoutCreatedInWillRenderForTesting()).isNull(); verify(componentSpy, times(1)).updateInternalChildState(any(ComponentContext.class)); }