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