Search in sources :

Example 36 with EditorFixture

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

the class ManifestEditorTest method testRemoveFromManifest.

@Test
public void testRemoveFromManifest() throws IOException {
    guiTest.importMultiModule();
    IdeFrameFixture projectFrame = guiTest.ideFrame();
    EditorFixture editor = projectFrame.getEditor();
    editor.open("app/src/main/AndroidManifest.xml");
    String addedText = "        <activity\n" + "            android:name=\"com.android.mylibrary.MainActivity\"\n" + "            tools:remove=\"android:label\" />\n";
    assertThat(editor.getCurrentFileContents()).doesNotContain(addedText);
    editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
    MergedManifestFixture mergedManifestFixture = editor.getMergedManifestEditor();
    JTreeFixture tree = mergedManifestFixture.getTree();
    // row 28 = "manifest/application/activity/android:name = com.android.mylibrary.MainActivity"
    JPopupMenuFixture popup = tree.showPopupMenuAt(22);
    popup.menuItemWithPath("Remove").click();
    editor.selectEditorTab(EditorFixture.Tab.EDITOR);
    assertThat(editor.getCurrentFileContents()).contains(addedText);
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) MergedManifestFixture(com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) JPopupMenuFixture(org.fest.swing.fixture.JPopupMenuFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) Test(org.junit.Test)

Example 37 with EditorFixture

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

the class ManifestEditorTest method testManifestGoToSource.

@Test
public void testManifestGoToSource() throws IOException {
    guiTest.importSimpleApplication();
    IdeFrameFixture projectFrame = guiTest.ideFrame();
    EditorFixture editor = projectFrame.getEditor();
    editor.open("app/src/main/AndroidManifest.xml");
    editor.selectEditorTab(EditorFixture.Tab.MERGED_MANIFEST);
    MergedManifestFixture mergedManifestFixture = editor.getMergedManifestEditor();
    JTreeFixture tree = mergedManifestFixture.getTree();
    tree.clickPath("manifest/application/android:allowBackup = true");
    mergedManifestFixture.checkAllRowsColored();
    Color defaultBackgroundColor = mergedManifestFixture.getDefaultBackgroundColor();
    assertEquals(defaultBackgroundColor, mergedManifestFixture.getSelectedNodeColor());
    mergedManifestFixture.clickLinkText("app main manifest (this file), line 5");
    assertThat(editor.getCurrentLine().trim()).isEqualTo("android:allowBackup=\"true\"");
}
Also used : JTreeFixture(org.fest.swing.fixture.JTreeFixture) MergedManifestFixture(com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) Test(org.junit.Test)

Example 38 with EditorFixture

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

Example 39 with EditorFixture

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

the class NlPreviewTest 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.EDITOR);
    NlPreviewFixture layout = editor.getLayoutPreview(true);
    layout.dragComponentToSurface("Widgets", "Button").dragComponentToSurface("Widgets", "CheckBox").waitForRenderToFinish();
    // Find and click the first text view
    NlComponentFixture checkBox = layout.findView("CheckBox", 0);
    checkBox.click();
    // It should be selected now
    layout.requireSelection(Collections.singletonList(checkBox));
    // 4 = root layout + 3 widgets
    assertEquals(4, layout.getAllComponents().size());
    ideFrame.invokeMenuPath("Edit", "Cut");
    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());
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) IdeFrameFixture(com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture) Test(org.junit.Test)

Example 40 with EditorFixture

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

the class NlPreviewTest method testEditCustomView.

@RunIn(TestGroup.UNRELIABLE)
@Test
public void testEditCustomView() throws Exception {
    // Opens the LayoutTest project, opens a layout with a custom view, checks
    // that it can't render yet (because the project hasn't been built),
    // builds the project, checks that the render works, edits the custom view
    // source code, ensures that the render lists the custom view as out of date,
    // applies the suggested fix to build the project, and finally asserts that the
    // build is now successful.
    EditorFixture editor = guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest").getEditor().open("app/src/main/res/layout/layout1.xml", EditorFixture.Tab.EDITOR);
    NlPreviewFixture preview = editor.getLayoutPreview(false);
    preview.waitForRenderToFinish();
    assertTrue(preview.hasRenderErrors());
    preview.waitForErrorPanelToContain("The following classes could not be found");
    preview.waitForErrorPanelToContain("com.android.tools.tests.layout.MyButton");
    preview.waitForErrorPanelToContain("Change to android.widget.Button");
    GradleInvocationResult result = guiTest.ideFrame().invokeProjectMake();
    assertTrue(result.isBuildSuccessful());
    // Build completion should trigger re-render
    preview.waitForRenderToFinish();
    assertFalse(preview.hasRenderErrors());
    editor.open("app/src/main/java/com/android/tools/tests/layout/MyButton.java", EditorFixture.Tab.EDITOR).moveBetween("extends Button {", "").enterText(// Next let's edit the custom view source file
    " // test").open("app/src/main/res/layout/layout1.xml", // Switch back; should trigger render
    EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    preview.waitForErrorPanelToContain("The MyButton custom view has been edited more recently than the last build");
    result = guiTest.ideFrame().invokeProjectMake();
    assertTrue(result.isBuildSuccessful());
    preview.waitForRenderToFinish();
    assertFalse(preview.hasRenderErrors());
    // Now make some changes to the file which updates the modification timestamp of the source. However,
    // also edit them back and save again (which still leaves a new modification timestamp). Gradle will
    // *not* rebuild if the file contents have not changed (it uses checksums rather than file timestamps).
    // Make sure that we don't get render errors in this scenario! (Regression test for http://b.android.com/76676)
    editor.open("app/src/main/java/com/android/tools/tests/layout/MyButton.java", EditorFixture.Tab.EDITOR).moveBetween("extends Button {", "").enterText(" ").invokeAction(EditorFixture.EditorAction.SAVE).invokeAction(EditorFixture.EditorAction.BACK_SPACE).invokeAction(EditorFixture.EditorAction.SAVE);
    waitForBackgroundTasks(guiTest.robot());
    editor.open("app/src/main/res/layout/layout1.xml", EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    preview.waitForErrorPanelToContain("The MyButton custom view has been edited more recently than the last build");
    // this build won't do anything this time, since Gradle notices checksum has not changed
    result = guiTest.ideFrame().invokeProjectMake();
    assertTrue(result.isBuildSuccessful());
    preview.waitForRenderToFinish();
    // but our build timestamp check this time will mask the out of date warning
    assertFalse(preview.hasRenderErrors());
}
Also used : GradleInvocationResult(com.android.tools.idea.gradle.project.build.invoker.GradleInvocationResult) EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) Test(org.junit.Test) RunIn(com.android.tools.idea.tests.gui.framework.RunIn)

Aggregations

EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)41 Test (org.junit.Test)37 IdeFrameFixture (com.android.tools.idea.tests.gui.framework.fixture.IdeFrameFixture)9 Ignore (org.junit.Ignore)7 GradleBuildModelFixture (com.android.tools.idea.tests.gui.framework.fixture.gradle.GradleBuildModelFixture)6 NlComponentFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlComponentFixture)6 NlEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.layout.NlEditorFixture)6 ArtifactDependencySpec (com.android.tools.idea.gradle.dsl.model.dependencies.ArtifactDependencySpec)4 MergedManifestFixture (com.android.tools.idea.tests.gui.framework.fixture.MergedManifestFixture)4 RunIn (com.android.tools.idea.tests.gui.framework.RunIn)3 RenameRefactoringDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 DialogFixture (org.fest.swing.fixture.DialogFixture)3 JButtonFixture (org.fest.swing.fixture.JButtonFixture)3 JTreeFixture (org.fest.swing.fixture.JTreeFixture)3 ExpectedModuleDependency (com.android.tools.idea.gradle.dsl.model.dependencies.ExpectedModuleDependency)2 ChooseResourceDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.ChooseResourceDialogFixture)2 ConflictsDialogFixture (com.android.tools.idea.tests.gui.framework.fixture.RenameRefactoringDialogFixture.ConflictsDialogFixture)2 ThemeEditorFixture (com.android.tools.idea.tests.gui.framework.fixture.theme.ThemeEditorFixture)2 Project (com.intellij.openapi.project.Project)2