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"));
}
Aggregations