Search in sources :

Example 1 with ChooseResourceDialogFixture

use of com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture in project android by JetBrains.

the class ChooseResourceDialogTest method testColorPickerAlpha.

/**
   * Test that the alpha slider and the textfield are hidden when we are not in ARGB.
   */
@Test
public void testColorPickerAlpha() throws IOException {
    guiTest.importSimpleApplication();
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell cell = row(1).column(0);
    JTableCellFixture colorCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) colorCell.editor());
    colorCell.startEditing();
    resourceComponent.getSwatchButton().click();
    ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    ColorPickerFixture colorPicker = dialog.getColorPicker();
    Color color = new Color(200, 0, 0, 200);
    colorPicker.setFormat("ARGB");
    colorPicker.setColorWithIntegers(color);
    JTextComponentFixture alphaLabel = colorPicker.getLabel("A:");
    SlideFixture alphaSlide = colorPicker.getAlphaSlide();
    alphaLabel.requireVisible();
    alphaSlide.requireVisible();
    colorPicker.setFormat("RGB");
    alphaLabel.requireNotVisible();
    alphaSlide.requireNotVisible();
    colorPicker.setFormat("HSB");
    alphaLabel.requireNotVisible();
    alphaSlide.requireNotVisible();
    dialog.clickOK();
    colorCell.stopEditing();
}
Also used : SlideFixture(com.android.tools.idea.tests.gui.framework.fixture.SlideFixture) TableCell(org.fest.swing.data.TableCell) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) ColorPickerFixture(com.android.tools.idea.tests.gui.framework.fixture.ColorPickerFixture) Test(org.junit.Test)

Example 2 with ChooseResourceDialogFixture

use of com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture in project android by JetBrains.

the class ChooseResourceDialogTest method testColorStateList.

@Test
public void testColorStateList() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("StateListApplication");
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell cell = row(7).column(0);
    FontFixture cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireBold();
    assertEquals("android:textColorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@color/text_color", themeEditorTable.valueAt(cell));
    JTableCellFixture stateListCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) stateListCell.editor());
    stateListCell.startEditing();
    resourceComponent.getSwatchButton().click();
    final ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    StateListPickerFixture stateListPicker = dialog.getStateListPicker();
    java.util.List<StateListComponentFixture> states = stateListPicker.getStateComponents();
    assertThat(states).hasSize(4);
    final StateListComponentFixture state0 = states.get(0);
    assertEquals("Not enabled", state0.getStateName());
    assertEquals("?android:attr/colorForeground", state0.getValue());
    assertFalse(state0.getValueComponent().hasWarningIcon());
    assertTrue(state0.isAlphaVisible());
    assertEquals("@dimen/text_alpha", state0.getAlphaValue());
    assertFalse(state0.getAlphaComponent().hasWarningIcon());
    final StateListComponentFixture state1 = states.get(1);
    assertEquals("Checked", state1.getStateName());
    assertEquals("#5034FAB2", state1.getValue());
    assertFalse(state1.getValueComponent().hasWarningIcon());
    assertFalse(state1.isAlphaVisible());
    final StateListComponentFixture state2 = states.get(2);
    assertEquals("Pressed", state2.getStateName());
    assertEquals("@color/invalidColor", state2.getValue());
    assertTrue(state2.getValueComponent().hasWarningIcon());
    assertFalse(state2.isAlphaVisible());
    final StateListComponentFixture state3 = states.get(3);
    assertEquals("Default", state3.getStateName());
    assertEquals("?attr/myColorAttribute", state3.getValue());
    assertFalse(state3.getValueComponent().hasWarningIcon());
    assertFalse(state3.isAlphaVisible());
    dialog.waitForErrorLabel();
    dialog.clickCancel();
    stateListCell.stopEditing();
}
Also used : TableCell(org.fest.swing.data.TableCell) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) Test(org.junit.Test)

Example 3 with ChooseResourceDialogFixture

use of com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture 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)

Example 4 with ChooseResourceDialogFixture

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

Example 5 with ChooseResourceDialogFixture

use of com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture in project android by JetBrains.

the class ChooseResourceDialogTest method testEditColorReference.

@Test
public void testEditColorReference() throws IOException {
    guiTest.importProjectAndWaitForProjectSyncToFinish("StateListApplication");
    ThemeEditorFixture themeEditor = ThemeEditorGuiTestUtils.openThemeEditor(guiTest.ideFrame());
    ThemeEditorTableFixture themeEditorTable = themeEditor.getPropertiesTable();
    TableCell cell = row(1).column(0);
    FontFixture cellFont = themeEditorTable.fontAt(cell);
    cellFont.requireBold();
    assertEquals("android:colorPrimary", themeEditorTable.attributeNameAt(cell));
    assertEquals("@color/ref_color", themeEditorTable.valueAt(cell));
    JTableCellFixture stateListCell = themeEditorTable.cell(cell);
    ResourceComponentFixture resourceComponent = new ResourceComponentFixture(guiTest.robot(), (ResourceComponent) stateListCell.editor());
    stateListCell.startEditing();
    resourceComponent.getSwatchButton().click();
    ChooseResourceDialogFixture dialog = ChooseResourceDialogFixture.find(guiTest.robot());
    SwatchComponentFixture state1 = dialog.getEditReferencePanel().getSwatchComponent();
    assertEquals("@color/myColor", state1.getText());
    assertFalse(state1.hasWarningIcon());
    dialog.clickCancel();
    stateListCell.stopEditing();
}
Also used : TableCell(org.fest.swing.data.TableCell) ChooseResourceDialogFixture(com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture) Test(org.junit.Test)

Aggregations

ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)6 Test (org.junit.Test)6 TableCell (org.fest.swing.data.TableCell)3 EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)2 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)2 NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)2 GuiTests.listToString (com.android.tools.idea.tests.gui.framework.GuiTests.listToString)1 GuiTests.tableToString (com.android.tools.idea.tests.gui.framework.GuiTests.tableToString)1 ColorPickerFixture (com.android.tools.idea.tests.gui.framework.fixture.ColorPickerFixture)1 SlideFixture (com.android.tools.idea.tests.gui.framework.fixture.SlideFixture)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