Search in sources :

Example 6 with WXDomObject

use of com.taobao.weex.dom.WXDomObject in project weex-example by KalicyZhou.

the class WXDivTest method testAddChild.

@Test
public void testAddChild() {
    WXSDKInstance instance = Mockito.mock(WXSDKInstance.class);
    Mockito.when(instance.getContext()).thenReturn(RuntimeEnvironment.application);
    WXDomObject testDom = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom.clone()).thenReturn(testDom);
    TestDomObject.setRef(testDom, "2");
    WXText child1 = new WXText(instance, testDom, mWXDiv);
    child1.initView();
    mWXDiv.addChild(child1, 0);
    assertEquals(1, mWXDiv.childCount());
    WXDomObject testDom2 = Mockito.spy(new WXDomObject());
    Mockito.when(testDom2.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom2.clone()).thenReturn(testDom2);
    TestDomObject.setRef(testDom2, "3");
    child2 = new WXText(instance, testDom2, mWXDiv);
    child2.initView();
    mWXDiv.addChild(child2, -1);
    assertEquals(2, mWXDiv.childCount());
    assertEquals(child2, mWXDiv.getChild(1));
    WXDomObject testDom3 = Mockito.mock(WXDomObject.class);
    Mockito.when(testDom3.getPadding()).thenReturn(new Spacing());
    Mockito.when(testDom3.clone()).thenReturn(testDom3);
    TestDomObject.setRef(testDom3, "4");
    WXText child3 = new WXText(instance, testDom3, mWXDiv);
    child3.initView();
    mWXDiv.addChild(child3, 1);
    assertEquals(3, mWXDiv.childCount());
    assertEquals(child3, mWXDiv.getChild(1));
}
Also used : WXSDKInstance(com.taobao.weex.WXSDKInstance) WXDomObject(com.taobao.weex.dom.WXDomObject) Spacing(com.taobao.weex.dom.flex.Spacing) Test(org.junit.Test) WXSDKInstanceTest(com.taobao.weex.WXSDKInstanceTest)

Aggregations

WXDomObject (com.taobao.weex.dom.WXDomObject)6 WXSDKInstance (com.taobao.weex.WXSDKInstance)3 Spacing (com.taobao.weex.dom.flex.Spacing)3 WXSDKInstanceTest (com.taobao.weex.WXSDKInstanceTest)2 Before (org.junit.Before)2 Test (org.junit.Test)2 WXEvent (com.taobao.weex.dom.WXEvent)1 WXListDomObject (com.taobao.weex.dom.WXListDomObject)1 WXTextDomObject (com.taobao.weex.dom.WXTextDomObject)1 SimpleComponentHolder (com.taobao.weex.ui.SimpleComponentHolder)1 ComponentTest (com.taobao.weex.ui.component.ComponentTest)1 WXComponent (com.taobao.weex.ui.component.WXComponent)1 WXDiv (com.taobao.weex.ui.component.WXDiv)1 WXDivTest (com.taobao.weex.ui.component.WXDivTest)1 WXHeaderTest (com.taobao.weex.ui.component.WXHeaderTest)1 WXVContainer (com.taobao.weex.ui.component.WXVContainer)1