@Test public void testSetCompatibleSizeSpec() { ComponentTree componentTree = create(mContext, mComponent) .build(); Size size = new Size(); componentTree.setSizeSpec( makeSizeSpec(100, AT_MOST), makeSizeSpec(100, AT_MOST), size); assertEquals(100, size.width, 0.0); assertEquals(100, size.height, 0.0); LayoutState firstLayoutState = componentTree.getBackgroundLayoutState(); assertThat(firstLayoutState).isNotNull(); componentTree.setSizeSpec( makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), size); assertEquals(100, size.width, 0.0); assertEquals(100, size.height, 0.0); assertThat(componentTree.getBackgroundLayoutState()).isEqualTo(firstLayoutState); }
@Test public void testSetCompatibleSizeSpecWithDifferentRoot() { ComponentTree componentTree = create(mContext, mComponent) .build(); Size size = new Size(); componentTree.setSizeSpec( makeSizeSpec(100, AT_MOST), makeSizeSpec(100, AT_MOST), size); assertEquals(100, size.width, 0.0); assertEquals(100, size.height, 0.0); LayoutState firstLayoutState = componentTree.getBackgroundLayoutState(); assertThat(firstLayoutState).isNotNull(); componentTree.setRootAndSizeSpec( TestDrawableComponent.create(mContext).build(), makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), size); assertNotEquals(firstLayoutState, componentTree.getBackgroundLayoutState()); }
@Test public void testSetRootWithTreePropsThenMeasure() { ComponentTree componentTree = create(mContext, mComponent).build(); componentTree.setLithoView(new LithoView(mContext)); componentTree.attach(); final TreeProps treeProps = new TreeProps(); treeProps.put(Object.class, "hello world"); componentTree.setRootAndSizeSpecAsync( TestDrawableComponent.create(mContext).build(), makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), treeProps); assertThat(componentTree.getBackgroundLayoutState()).isNull(); componentTree.measure(makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), new int[2], true); final ComponentContext c = getInternalState(componentTree.getMainThreadLayoutState(), "mContext"); assertThat(c.getTreeProps()).isNotNull(); assertThat(c.getTreeProps().get(Object.class)).isEqualTo(treeProps.get(Object.class)); }
@Test public void testSetRootAndSizeSpecWithTreeProps() { ComponentTree componentTree = create(mContext, mComponent).build(); final Size size = new Size(); final TreeProps treeProps = new TreeProps(); treeProps.put(Object.class, "hello world"); componentTree.setRootAndSizeSpec( TestDrawableComponent.create(mContext).build(), makeSizeSpec(100, EXACTLY), makeSizeSpec(100, EXACTLY), size, treeProps); final ComponentContext c = getInternalState(componentTree.getBackgroundLayoutState(), "mContext"); assertThat(c.getTreeProps()).isSameAs(treeProps); }