use of com.android.tools.idea.uibuilder.fixtures.ModelBuilder in project android by JetBrains.
the class NlModelTest method testChangeSingleProperty.
@SuppressWarnings("ConstantConditions")
public void testChangeSingleProperty() throws Exception {
boolean preserveXmlTags = false;
boolean includeIds = false;
ModelBuilder modelBuilder = createDefaultModelBuilder(includeIds);
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()));
// Change a single attribute in an element without id's.
ComponentDescriptor layout = modelBuilder.findByPath(LINEAR_LAYOUT);
assertThat(layout).isNotNull();
layout.withAttribute("style", "@style/Foo");
modelBuilder.updateModel(model, preserveXmlTags);
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.ModelBuilder 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.ModelBuilder 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.ModelBuilder in project android by JetBrains.
the class NlModelTest method testSync.
@SuppressWarnings("ConstantConditions")
public void testSync() throws Exception {
// Whether we include id's in the components or not. Id's help
// associate id's with before/after versions; they're conditionally
// added such that we can test the model handler with and without this
// aid.
boolean includeIds = false;
ModelBuilder modelBuilder = createDefaultModelBuilder(includeIds);
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()));
// Same hierarchy; preserveXmlTags means that all the XmlTags in the view hiearchy
// will be different than in the existing model (simulating a completely separate
// PSI parse)
boolean preserveXmlTags = false;
modelBuilder.updateModel(model, preserveXmlTags);
// Everything should be identical
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()));
}
Aggregations