use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.
the class NlModelTest method testMoveInHierarchy.
public void testMoveInHierarchy() 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()));
// Move button to be child of the text view instead
ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
assertThat(parent).isNotNull();
ComponentDescriptor textView = modelBuilder.findByPath(LINEAR_LAYOUT, TEXT_VIEW);
assertThat(textView).isNotNull();
ComponentDescriptor button = modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON);
assertThat(button).isNotNull();
parent.removeChild(button);
textView.addChild(button, null);
modelBuilder.updateModel(model, false);
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()));
}
use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.
the class NlModelTest method testAddRemove.
public void testAddRemove() throws Exception {
// Test removing one child and adding another one. Check that we don't
// preserve component identity across two separate tag names.
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()));
// Add child
ComponentDescriptor parent = modelBuilder.findByPath(LINEAR_LAYOUT);
assertThat(parent).isNotNull();
ComponentDescriptor button = modelBuilder.findByPath(LINEAR_LAYOUT, BUTTON);
assertThat(button).isNotNull();
ComponentDescriptor textView = modelBuilder.findByPath(LINEAR_LAYOUT, TEXT_VIEW);
assertThat(textView).isNotNull();
parent.addChild(component(EDIT_TEXT).withBounds(100, 100, 100, 100).width("100dp").height("100dp"), textView);
parent.removeChild(button);
modelBuilder.updateModel(model, false);
assertEquals("NlComponent{tag=<LinearLayout>, bounds=[0,0:1000x1000, instance=0}\n" + " NlComponent{tag=<EditText>, bounds=[100,100:100x100, instance=3}\n" + " NlComponent{tag=<TextView>, bounds=[100,100:100x100, instance=1}", myTreeDumper.toTree(model.getComponents()));
}
use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.
the class GroupDragHandlerLayoutTest method testCommitNonconsecutiveOrders.
public void testCommitNonconsecutiveOrders() {
ComponentDescriptor menuDescriptor = component(TAG_MENU).withBounds(480, 58, 288, 96).children(item(30, 672), item(20, 576), item(10, 480));
NlComponent menuComponent = model("menu.xml", menuDescriptor).build().getComponents().get(0);
NlComponent item = Mockito.mock(NlComponent.class);
DragHandler handler = newGroupDragHandler(menuComponent, item);
handler.update(600, 100, 0);
WriteCommandAction.runWriteCommandAction(getProject(), () -> handler.commit(600, 100, 0, InsertType.MOVE_INTO));
Iterator<NlComponent> i = menuComponent.getChildren().iterator();
assertEquals("30", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
assertEquals("21", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
assertEquals("10", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
Mockito.verify(item).setAndroidAttribute(ATTR_ORDER_IN_CATEGORY, "20");
}
use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.
the class GroupDragHandlerLayoutTest method testCommitActiveItemIsSameAsDraggedItem.
public void testCommitActiveItemIsSameAsDraggedItem() {
ComponentDescriptor menuDescriptor = component(TAG_MENU).withBounds(480, 58, 288, 96).children(item(3, 672), item(2, 576), item(1, 480));
NlComponent menuComponent = model("menu.xml", menuDescriptor).build().getComponents().get(0);
NlComponent item = menuComponent.getChild(0);
assert item != null;
DragHandler handler = newGroupDragHandler(menuComponent, item);
handler.update(740, 100, 16);
WriteCommandAction.runWriteCommandAction(getProject(), () -> handler.commit(740, 100, 16, InsertType.MOVE_INTO));
Iterator<NlComponent> i = menuComponent.getChildren().iterator();
assertEquals("3", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
assertEquals("2", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
assertEquals("1", i.next().getAndroidAttribute(ATTR_ORDER_IN_CATEGORY));
}
use of com.android.tools.idea.uibuilder.fixtures.ComponentDescriptor in project android by JetBrains.
the class MockupTestCase method createModel1Mockup.
protected NlModel createModel1Mockup(@NotNull String mockupFile, @Nullable String mockupPosition, @Nullable String opacity) {
final ComponentDescriptor root = component(RELATIVE_LAYOUT).withBounds(0, 0, 1000, 1000).matchParentWidth().matchParentHeight().withAttribute(TOOLS_URI, ATTR_MOCKUP, mockupFile);
if (mockupPosition != null) {
root.withAttribute(TOOLS_URI, ATTR_MOCKUP_CROP, mockupPosition);
}
if (opacity != null) {
root.withAttribute(TOOLS_URI, ATTR_MOCKUP_OPACITY, opacity);
}
ModelBuilder builder = model("relative.xml", root);
final NlModel model = builder.build();
assertEquals(1, model.getComponents().size());
return model;
}
Aggregations