use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class NlModelTest method testRemoveLastChild.
public void testRemoveLastChild() throws Exception {
ModelBuilder modelBuilder = createDefaultModelBuilder(false);
NlModel model = modelBuilder.build();
assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + " NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}\n" + " NlComponent{tag=<Button>, bounds=[100,200:100x100, instance=2}", myTreeDumper.toTree(model.getComponents()));
// Remove last child
ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
assertThat(parent).isNotNull();
parent.removeChild(modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON));
modelBuilder.updateModel(model, false);
assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + " NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}", myTreeDumper.toTree(model.getComponents()));
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class RelativeLayoutHandlerTest method createModel.
@NotNull
private NlModel createModel() {
ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(BUTTON).withBounds(100, 100, 100, 100).id("@id/button").width("100dp").height("100dp").withAttribute("android:layout_alignParentTop", "true").withAttribute("android:layout_alignParentLeft", "true").withAttribute("android:layout_alignParentStart", "true").withAttribute("android:layout_marginTop", "100dp").withAttribute("android:layout_marginLeft", "100dp").withAttribute("android:layout_marginStart", "100dp"), component(CHECK_BOX).withBounds(300, 300, 20, 20).viewObject(mockViewWithBaseline(17)).id("@id/checkbox").width("20dp").height("20dp").withAttribute("android:layout_below", "@id/button").withAttribute("android:layout_toRightOf", "@id/button").withAttribute("android:layout_marginLeft", "100dp").withAttribute("android:layout_marginTop", "100dp"), component(TEXT_VIEW).withBounds(400, 400, 100, 100).viewObject(mockViewWithBaseline(70)).id("@id/textView").width("100dp").height("100dp").withAttribute("android:layout_below", "@id/checkbox").withAttribute("android:layout_toRightOf", "@id/checkbox").withAttribute("android:layout_marginLeft", "80dp").withAttribute("android:layout_marginTop", "80dp")));
NlModel model = builder.build();
assertEquals(1, model.getComponents().size());
assertEquals("NlComponent{tag=<RelativeLayout>, bounds=[0,0:1000x1000}\n" + " NlComponent{tag=<Button>, bounds=[100,100:100x100}\n" + " NlComponent{tag=<CheckBox>, bounds=[300,300:20x20}\n" + " NlComponent{tag=<TextView>, bounds=[400,400:100x100}", NlTreeDumper.dumpTree(model.getComponents()));
format(model.getFile());
assertEquals("<RelativeLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\">\n" + "\n" + " <Button\n" + " android:id=\"@id/button\"\n" + " android:layout_width=\"100dp\"\n" + " android:layout_height=\"100dp\"\n" + " android:layout_alignParentTop=\"true\"\n" + " android:layout_alignParentLeft=\"true\"\n" + " android:layout_alignParentStart=\"true\"\n" + " android:layout_marginTop=\"100dp\"\n" + " android:layout_marginLeft=\"100dp\"\n" + " android:layout_marginStart=\"100dp\" />\n" + "\n" + " <CheckBox\n" + " android:id=\"@id/checkbox\"\n" + " android:layout_width=\"20dp\"\n" + " android:layout_height=\"20dp\"\n" + " android:layout_below=\"@id/button\"\n" + " android:layout_toRightOf=\"@id/button\"\n" + " android:layout_marginLeft=\"100dp\"\n" + " android:layout_marginTop=\"100dp\" />\n" + "\n" + " <TextView\n" + " android:id=\"@id/textView\"\n" + " android:layout_width=\"100dp\"\n" + " android:layout_height=\"100dp\"\n" + " android:layout_below=\"@id/checkbox\"\n" + " android:layout_toRightOf=\"@id/checkbox\"\n" + " android:layout_marginLeft=\"80dp\"\n" + " android:layout_marginTop=\"80dp\" />\n" + "\n" + "</RelativeLayout>\n", model.getFile().getText());
return model;
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class LinearLayoutHandlerTest method createModel.
@NotNull
private NlModel createModel() {
ModelBuilder builder = model("linear.xml", component(LINEAR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().children(component(TEXT_VIEW).withBounds(100, 100, 100, 100).id("@id/myText1").width("100dp").height("100dp"), component(BUTTON).withBounds(100, 200, 100, 100).id("@id/myText2").width("100dp").height("100dp").withAttribute("android:layout_weight", "1.0")));
final NlModel model = builder.build();
assertEquals(1, model.getComponents().size());
assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000}\n" + " NlComponent{tag=<TextView>, bounds=[100,100:100x100}\n" + " NlComponent{tag=<Button>, bounds=[100,200:100x100}", NlTreeDumper.dumpTree(model.getComponents()));
format(model.getFile());
return model;
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class MockupTestCase method createModel0Mockup.
protected NlModel createModel0Mockup() {
ModelBuilder builder = model("relative.xml", component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight());
final NlModel model = builder.build();
assertEquals(1, model.getComponents().size());
return model;
}
use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class AbsoluteLayoutHandlerTest method testDragToLayout.
public void testDragToLayout() throws Exception {
// Drag from one layout to another
ModelBuilder builder = model("absolute2.xml", component(LINEAR_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(ANDROID_URI, ATTR_ORIENTATION, VALUE_VERTICAL).children(component(TEXT_VIEW).withBounds(0, 0, 1000, 150).id("@id/myText").width("100dp").height("100dp").withAttribute("android:layout_x", "100dp").withAttribute("android:layout_y", "100dp"), component(ABSOLUTE_LAYOUT).withBounds(0, 150, 1000, 850).id("myAbsLayout").matchParentWidth().matchParentHeight()));
final NlModel model = builder.build();
assertEquals(1, model.getComponents().size());
assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000}\n" + " NlComponent{tag=<TextView>, bounds=[0,0:1000x150}\n" + " NlComponent{tag=<AbsoluteLayout>, bounds=[0,150:1000x850}", NlTreeDumper.dumpTree(model.getComponents()));
surface().screen(createModel()).get("@id/myText").drag().drag(50, // into AbsoluteLayout child
300).release().primary().parent().expectXml("<AbsoluteLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\">\n" + "\n" + " <TextView\n" + " android:id=\"@id/myText\"\n" + " android:layout_width=\"100dp\"\n" + " android:layout_height=\"100dp\"\n" + " android:layout_x=\"150dp\"\n" + " android:layout_y=\"400dp\" />\n" + "\n" + "</AbsoluteLayout>");
}
Aggregations