Search in sources :

Example 1 with NlPropertyInspectorFixture

use of com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture 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"));
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) NlPropertyInspectorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture) NlEditorFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) NlComponentFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture) NlPropertyFixture(com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyFixture) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)1 EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)1 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)1 NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)1 NlPropertyFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyFixture)1 NlPropertyInspectorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlPropertyInspectorFixture)1 BufferedImage (java.awt.image.BufferedImage)1 Test (org.junit.Test)1