use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.
the class NlEditorTest method testCopyAndPaste.
@Test
public void testCopyAndPaste() throws Exception {
guiTest.importSimpleApplication();
IdeFrameFixture ideFrame = guiTest.ideFrame();
EditorFixture editor = ideFrame.getEditor().open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.DESIGN);
NlEditorFixture layout = editor.getLayoutEditor(true).dragComponentToSurface("Widgets", "Button").dragComponentToSurface("Widgets", "CheckBox").waitForRenderToFinish();
// Find and click the first text view
NlComponentFixture textView = layout.findView("CheckBox", 0);
textView.click();
// It should be selected now
layout.requireSelection(Collections.singletonList(textView));
// 4 = root layout + 3 widgets
assertEquals(4, layout.getAllComponents().size());
ideFrame.invokeMenuPath("Edit", "Cut");
layout.requireSelection(Collections.emptyList());
assertEquals(3, layout.getAllComponents().size());
layout.findView("Button", 0).click();
ideFrame.invokeMenuPath("Edit", "Paste");
layout.findView("CheckBox", 0).click();
ideFrame.invokeMenuPath("Edit", "Copy");
ideFrame.invokeMenuPath("Edit", "Paste");
assertEquals(5, layout.getAllComponents().size());
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.
the class NlPropertyTableTest method testScrollInViewDuringKeyboardNavigation.
@Test
public void testScrollInViewDuringKeyboardNavigation() throws Exception {
NlEditorFixture layout = guiTest.importSimpleApplication().getEditor().open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.EDITOR).getLayoutEditor(true).waitForRenderToFinish();
layout.findView("TextView", 0).click();
layout.getPropertyInspector().adjustIdeFrameHeightFor(4, "ID").focusAndWaitForFocusGainInProperty("ID", null).assertPropertyShowing("text", null).assertPropertyShowing("ID", null).assertPropertyNotShowing("visibility", null).tab().tab().tab().tab().tab().tab().assertFocusInProperty("text", null).tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().assertFocusInProperty("textColor", null).tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().tab().assertPropertyNotShowing("text", null).assertPropertyNotShowing("ID", null).assertPropertyShowing("visibility", null).tab().assertFocusInProperty("ID", null).assertPropertyShowing("ID", null).assertPropertyShowing("text", null).assertPropertyNotShowing("visibility", null).tabBack().assertPropertyNotShowing("ID", null).assertPropertyNotShowing("text", null).assertPropertyShowing("visibility", null);
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.
the class EditorFixture method getLayoutEditor.
/**
* Returns a fixture around the layout editor, <b>if</b> the currently edited file
* is a layout file and it is currently showing the layout editor tab or the parameter
* requests that it be opened if necessary
*
* @param switchToTabIfNecessary if true, switch to the design tab if it is not already showing
* @throws IllegalStateException if there is no selected editor or it is not a {@link NlEditor}
*/
@NotNull
public NlEditorFixture getLayoutEditor(boolean switchToTabIfNecessary) {
if (switchToTabIfNecessary) {
selectEditorTab(Tab.DESIGN);
}
return GuiQuery.getNonNull(() -> {
FileEditor[] editors = FileEditorManager.getInstance(myFrame.getProject()).getSelectedEditors();
checkState(editors.length > 0, "no selected editors");
FileEditor selected = editors[0];
checkState(selected instanceof NlEditor, "not a %s: %s", NlEditor.class.getSimpleName(), selected);
return new NlEditorFixture(myFrame.robot(), myFrame, (NlEditor) selected);
});
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.
the class NlEditorTest method testSelectComponent.
@Test
public void testSelectComponent() throws Exception {
guiTest.importSimpleApplication();
// Open file as XML and switch to design tab, wait for successful render
EditorFixture editor = guiTest.ideFrame().getEditor();
editor.open("app/src/main/res/layout/activity_my.xml", EditorFixture.Tab.DESIGN);
NlEditorFixture layout = editor.getLayoutEditor(false);
layout.waitForRenderToFinish();
// Find and click the first text view
NlComponentFixture textView = layout.findView("TextView", 0);
textView.click();
// It should be selected now
layout.requireSelection(Collections.singletonList(textView));
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture in project android by JetBrains.
the class ConvertToConstraintLayoutTest method testConvert.
@Ignore("http://b.android.com/211200")
@Test
public void testConvert() throws Exception {
guiTest.importSimpleApplication();
EditorFixture editor = guiTest.ideFrame().getEditor();
editor.open("app/src/main/res/layout/absolute.xml", EditorFixture.Tab.DESIGN);
NlEditorFixture layout = editor.getLayoutEditor(false);
layout.waitForRenderToFinish();
// Find and click the first button
NlComponentFixture button = layout.findView("Button", 0);
button.invokeContextMenuAction("Convert AbsoluteLayout to ConstraintLayout");
// Confirm dialog
DialogFixture quickFixDialog = WindowFinder.findDialog(Matchers.byTitle(Dialog.class, "Convert to ConstraintLayout")).withTimeout(TimeUnit.MINUTES.toMillis(2)).using(guiTest.robot());
// Press OK
JButtonFixture finish = quickFixDialog.button(withText("OK"));
finish.click();
// Check that we've converted to what we expected
layout.waitForRenderToFinish();
editor.selectEditorTab(EditorFixture.Tab.EDITOR);
waitForScout();
editor.invokeAction(EditorFixture.EditorAction.FORMAT);
@Language("XML") String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<android.support.constraint.ConstraintLayout xmlns:android=\"http://schemas.android.com/apk/res/android\"\n" + " xmlns:app=\"http://schemas.android.com/apk/res-auto\"\n" + " xmlns:tools=\"http://schemas.android.com/tools\"\n" + " android:id=\"@+id/constraintLayout\"\n" + " android:layout_width=\"match_parent\"\n" + " android:layout_height=\"match_parent\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\">\n" + "\n" + " <Button\n" + " android:id=\"@+id/button\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginStart=\"<test>\"\n" + " android:layout_marginTop=\"<test>\"\n" + " android:text=\"Button\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toTopOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_constraintTop_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <Button\n" + " android:id=\"@+id/button2\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginStart=\"<test>\"\n" + " android:text=\"Button\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/button\"\n" + " app:layout_constraintTop_toBottomOf=\"@+id/button\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_constraintTop_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <EditText\n" + " android:id=\"@+id/editText\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginBottom=\"<test>\"\n" + " android:layout_marginEnd=\"<test>\"\n" + " android:layout_marginTop=\"<test>\"\n" + " android:ems=\"10\"\n" + " android:inputType=\"textPersonName\"\n" + " android:text=\"Name\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/button6\"\n" + " app:layout_constraintRight_toRightOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toTopOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintRight_creator=\"1\"\n" + " tools:layout_constraintTop_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "\n" + " <Button\n" + " android:id=\"@+id/button3\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginStart=\"<test>\"\n" + " android:text=\"Button\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/button5\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toTopOf=\"@+id/button5\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_constraintTop_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <Button\n" + " android:id=\"@+id/button5\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginBottom=\"<test>\"\n" + " android:text=\"Button\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintRight_toRightOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_constraintRight_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <Button\n" + " android:id=\"@+id/button6\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_marginEnd=\"<test>\"\n" + " android:text=\"Button\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/button5\"\n" + " app:layout_constraintRight_toRightOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toTopOf=\"@+id/button5\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintRight_creator=\"1\"\n" + " tools:layout_constraintTop_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + "</android.support.constraint.ConstraintLayout>\n" + "\n";
assertThat(wipeDimensions(editor.getCurrentFileContents())).isEqualTo(wipeDimensions(xml));
}
Aggregations