use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture in project android by JetBrains.
the class ChooseResourceDialogTest method testDrawable.
/**
* Test looking at the attributes for a drawable
*/
@Test
public void testDrawable() throws IOException {
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/frames.xml", EditorFixture.Tab.DESIGN);
NlEditorFixture layout = editor.getLayoutEditor(false);
layout.waitForRenderToFinish();
// Find and click the first text view
NlComponentFixture imageView = layout.findView("ImageView", 0);
imageView.click();
layout.requireSelection(Collections.singletonList(imageView));
// Get property sheet, find srcCompat property, open customizer
NlPropertyInspectorFixture fixture = layout.getPropertyInspector();
NlPropertyFixture property = fixture.findProperty("srcCompat");
property.clickCustomizer();
ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
JTabbedPaneFixture tabs = dialog.getTabs();
tabs.requireTabTitles("Drawable", "Color", "ID", "String", "Style");
dialog.getSearchField().enterText("che");
JListFixture projectList = dialog.getList("Project");
JListFixture frameworkList = dialog.getList("android");
assertEquals("ic_launcher \n", listToString(projectList));
assertEquals("checkbox_off_background \n" + "checkbox_on_background \n", listToString(frameworkList));
// This should jump to the project list and select the first one: ic_launcher
dialog.getSearchField().pressAndReleaseKeys(KeyEvent.VK_DOWN);
dialog.getDrawablePreviewName().requireText("ic_launcher");
assertThat(dialog.getDrawableResolutionChain()).isEqualTo("@drawable/ic_launcher\n" + " ⇒ ic_launcher.xml\n");
// Ensure that the pixel in the middle of the preview area is red
JLabelFixture previewLabel = dialog.getDrawablePreviewLabel();
Icon icon = previewLabel.target().getIcon();
//noinspection UndesirableClassUsage
BufferedImage img = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_ARGB);
Graphics graphics = img.getGraphics();
icon.paintIcon(previewLabel.target(), graphics, 0, 0);
graphics.dispose();
assertEquals(0xFFFF0000, img.getRGB(icon.getIconWidth() / 2, icon.getIconHeight() / 2));
dialog.clickOK();
Wait.seconds(2).expecting("property to have the new value").until(() -> property.getValue().equals("@drawable/ic_launcher"));
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture in project android by JetBrains.
the class ConvertToConstraintLayoutTest method testConvert2.
@Ignore("http://b.android.com/211200")
@Test
public void testConvert2() throws Exception {
guiTest.importSimpleApplication();
EditorFixture editor = guiTest.ideFrame().getEditor();
editor.open("app/src/main/res/layout/frames.xml", EditorFixture.Tab.DESIGN);
NlEditorFixture layout = editor.getLayoutEditor(false);
layout.waitForRenderToFinish();
// Find and click the first text View
NlComponentFixture button = layout.findView("TextView", 0);
button.invokeContextMenuAction("Convert LinearLayout 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=\"wrap_content\"\n" + " android:orientation=\"vertical\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\">\n" + "\n" + " <TextView\n" + " android:id=\"@+id/title\"\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:text=\"Welcome\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintLeft_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" + " <FrameLayout\n" + " android:id=\"@+id/attending_remotely\"\n" + " android:layout_width=\"0dp\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:foreground=\"?android:selectableItemBackground\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintLeft_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" + " <ImageView\n" + " android:layout_width=\"100dp\"\n" + " android:layout_height=\"100dp\"\n" + " android:adjustViewBounds=\"true\"\n" + " android:scaleType=\"centerInside\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/attending_remotely\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <TextView\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_gravity=\"bottom|end|right\"\n" + " android:text=\"Remotely\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " </FrameLayout>\n" + "\n" + " <FrameLayout\n" + " android:id=\"@+id/attending_in_person\"\n" + " android:layout_width=\"0dp\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:foreground=\"?android:selectableItemBackground\"\n" + " app:layout_constraintBottom_toBottomOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintRight_toLeftOf=\"@+id/constraintLayout\"\n" + " app:layout_constraintTop_toBottomOf=\"@+id/constraintLayout\"\n" + " tools:layout_constraintBottom_creator=\"1\"\n" + " tools:layout_constraintLeft_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" + " <ImageView\n" + " android:layout_width=\"100dp\"\n" + " android:layout_height=\"100dp\"\n" + " android:adjustViewBounds=\"true\"\n" + " android:scaleType=\"centerInside\"\n" + " app:layout_constraintLeft_toLeftOf=\"@+id/attending_in_person\"\n" + " tools:layout_constraintLeft_creator=\"1\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " <TextView\n" + " android:layout_width=\"wrap_content\"\n" + " android:layout_height=\"wrap_content\"\n" + " android:layout_gravity=\"bottom|end|right\"\n" + " android:text=\"In Person\"\n" + " tools:layout_editor_absoluteX=\"<test>\"\n" + " tools:layout_editor_absoluteY=\"<test>\" />\n" + "\n" + " </FrameLayout>\n" + "\n" + "</android.support.constraint.ConstraintLayout>\n";
assertThat(wipeDimensions(editor.getCurrentFileContents())).isEqualTo(wipeDimensions(xml));
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture in project android by JetBrains.
the class ChooseResourceDialogTest method testEditString.
/**
* Test the resource table editor, filtering and selection
*/
@Test
public void testEditString() throws IOException {
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));
// Get property sheet, find text property, open customizer
layout.getPropertyInspector().findProperty("text").clickCustomizer();
ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
JTableFixture nameTable = dialog.getResourceNameTable();
assertEquals("Project \n" + "action_settings Settings \n" + "app_name Simple Application \n" + "cancel 取消 \n" + "hello_world Hello world! \n" + "android \n", tableToString(nameTable, 0, 6, 0, 5, 30));
// Search for "app" and confirm that we only show the header nodes as well as resource names
// that match. We also used to check that we were highlighting the right portion of the
// string here, but after switching away from HTML labels to IntelliJ's ColoredTableCellRenderer,
// this is no longer visible from the table fixture.
dialog.getSearchField().enterText("app");
assertEquals("Project \n" + "app_name \n" + "android \n" + "Theme attributes \n", tableToString(nameTable, 0, 6, 0, 1, 80));
JTableFixture valueTable = dialog.getResourceValueTable();
assertEquals("Default Simple Application \n" + "English Simple Application \n" + "Hebrew \n" + "Tamil Simple Application \n" + "English, United Kingdom Simple Application \n" + "Chinese, China 谷歌 I/O \n", tableToString(valueTable));
dialog.clickOK();
}
use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture 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.NlComponentFixture 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));
}
Aggregations