Search in sources :

Example 1 with FileFixture

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

the class NlPreviewTest method testRenderingDynamicResources.

@Test
public void testRenderingDynamicResources() throws Exception {
    // Opens a layout which contains dynamic resources (defined only in build.gradle)
    // and checks that the values have been resolved correctly (both that there are no
    // unresolved reference errors in the XML file, and that the rendered layout strings
    // matches the expected overlay semantics); also edits these in the Gradle file and
    // checks that the layout rendering is updated after a Gradle sync.
    guiTest.importProjectAndWaitForProjectSyncToFinish("LayoutTest");
    AndroidModuleModel androidModel = guiTest.ideFrame().getAndroidModel("app");
    String modelVersion = androidModel.getAndroidProject().getModelVersion();
    Revision version = Revision.parseRevision(modelVersion);
    assumeTrue("This test tests behavior that starts working in 0.14.+", version.getMajor() != 0 || version.getMinor() >= 14);
    EditorFixture editor = guiTest.ideFrame().getEditor();
    String layoutFilePath = "app/src/main/res/layout/dynamic_layout.xml";
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    NlPreviewFixture preview = editor.getLayoutPreview(true);
    preview.waitForRenderToFinish();
    assertFalse(preview.hasRenderErrors());
    NlComponentFixture string1 = preview.findView("TextView", 0);
    string1.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string1");
    string1.requireViewClass("android.support.v7.widget.AppCompatTextView");
    string1.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string2 = preview.findView("TextView", 1);
    string2.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string2");
    string2.requireActualText("String 1 defined only by defaultConfig");
    NlComponentFixture string3 = preview.findView("TextView", 2);
    string3.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string3");
    string3.requireActualText("String 3 defined by build type debug");
    NlComponentFixture string4 = preview.findView("TextView", 3);
    string4.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string4");
    string4.requireActualText("String 4 defined by flavor free");
    NlComponentFixture string5 = preview.findView("TextView", 4);
    string5.requireAttribute(ANDROID_URI, ATTR_TEXT, "@string/dynamic_string5");
    string5.requireActualText("String 5 defined by build type debug");
    // Ensure that all the references are properly resolved
    FileFixture file = guiTest.ideFrame().findExistingFileByRelativePath(layoutFilePath);
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
    editor.open("app/build.gradle", EditorFixture.Tab.EDITOR).moveBetween("String 1 defined only by ", "defaultConfig").enterText("edited ").awaitNotification("Gradle files have changed since last project sync. A project sync may be necessary for the IDE to work properly.").performAction("Sync Now").waitForGradleProjectSyncToFinish();
    editor.open(layoutFilePath, EditorFixture.Tab.EDITOR);
    preview.waitForRenderToFinish();
    string1 = preview.findView("TextView", 0);
    string1.requireActualText("String 1 defined only by edited defaultConfig");
    file.waitForCodeAnalysisHighlightCount(ERROR, 0);
}
Also used : EditorFixture(com.android.tools.idea.tests.gui.framework.fixture.EditorFixture) Revision(com.android.repository.Revision) AndroidModuleModel(com.android.tools.idea.gradle.project.model.AndroidModuleModel) FileFixture(com.android.tools.idea.tests.gui.framework.fixture.FileFixture) Test(org.junit.Test)

Aggregations

Revision (com.android.repository.Revision)1 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 EditorFixture (com.android.tools.idea.tests.gui.framework.fixture.EditorFixture)1 FileFixture (com.android.tools.idea.tests.gui.framework.fixture.FileFixture)1 Test (org.junit.Test)1