Browse Source

Merge pull request #5378 from nextcloud/dependabot/gradle/markwonVersion-4.2.1

dependabot-preview[bot] 5 năm trước cách đây
mục cha
commit
f7d7a0c7a2

+ 1 - 1
build.gradle

@@ -61,7 +61,7 @@ configurations {
 ext {
     jacocoVersion = "0.8.2"
     daggerVersion = "2.26"
-    markwonVersion =  "4.2.0"
+    markwonVersion =  "4.2.1"
     prismVersion = "2.0.0"
     androidLibraryVersion = "master-SNAPSHOT"
 

BIN
screenshots/com.owncloud.android.ui.preview.PreviewTextFileFragmentTest_displayJavaSnippetFile.png


BIN
screenshots/com.owncloud.android.ui.preview.PreviewTextFileFragmentTest_displaySimpleTextFile.png


+ 23 - 0
src/androidTest/assets/java.md

@@ -0,0 +1,23 @@
+Java:
+
+```java
+private String getAppProcessName() {
+        String processName = "";
+        if(Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
+            ActivityManager manager = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
+            final int ownPid = android.os.Process.myPid();
+            final List<ActivityManager.RunningAppProcessInfo> processes = manager.getRunningAppProcesses();
+            if (processes != null) {
+                for (ActivityManager.RunningAppProcessInfo info : processes) {
+                    if (info.pid == ownPid) {
+                        processName = info.processName;
+                        break;
+                    }
+                }
+            }
+        } else {
+            processName = Application.getProcessName();
+        }
+        return processName;
+    }
+```

+ 17 - 1
src/androidTest/java/com/owncloud/android/AbstractIT.java

@@ -19,6 +19,7 @@ import com.owncloud.android.utils.FileStorageUtils;
 
 import org.apache.commons.httpclient.HttpStatus;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.io.FileUtils;
 import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
@@ -26,10 +27,13 @@ import org.junit.runner.RunWith;
 import java.io.File;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 
 import androidx.test.ext.junit.runners.AndroidJUnit4;
 import androidx.test.platform.app.InstrumentationRegistry;
 
+import static androidx.test.InstrumentationRegistry.getInstrumentation;
+
 
 /**
  * Common base for all integration tests
@@ -39,7 +43,7 @@ import androidx.test.platform.app.InstrumentationRegistry;
 public abstract class AbstractIT {
 
     protected static OwnCloudClient client;
-    static Account account;
+    protected static Account account;
     protected static Context targetContext;
 
     @BeforeClass
@@ -133,4 +137,16 @@ public abstract class AbstractIT {
             e.printStackTrace();
         }
     }
+
+    protected File getFile(String filename) throws IOException {
+        InputStream inputStream = getInstrumentation().getContext().getAssets().open(filename);
+        File temp = File.createTempFile("file", "file");
+        FileUtils.copyInputStreamToFile(inputStream, temp);
+
+        return temp;
+    }
+
+    protected void waitForIdleSync() {
+        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
+    }
 }

+ 85 - 0
src/androidTest/java/com/owncloud/android/ui/preview/PreviewTextFileFragmentTest.java

@@ -0,0 +1,85 @@
+/*
+ *
+ * Nextcloud Android client application
+ *
+ * @author Tobias Kaminsky
+ * Copyright (C) 2020 Tobias Kaminsky
+ * Copyright (C) 2020 Nextcloud GmbH
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package com.owncloud.android.ui.preview;
+
+import android.Manifest;
+
+import com.facebook.testing.screenshot.Screenshot;
+import com.owncloud.android.AbstractIT;
+import com.owncloud.android.datamodel.OCFile;
+import com.owncloud.android.ui.activity.FileDisplayActivity;
+import com.owncloud.android.utils.FileStorageUtils;
+import com.owncloud.android.utils.MimeTypeUtil;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.IOException;
+
+import androidx.test.espresso.intent.rule.IntentsTestRule;
+import androidx.test.rule.GrantPermissionRule;
+
+public class PreviewTextFileFragmentTest extends AbstractIT {
+    @Rule public IntentsTestRule<FileDisplayActivity> activityRule = new IntentsTestRule<>(FileDisplayActivity.class,
+                                                                                           true,
+                                                                                           false);
+
+    @Rule
+    public final GrantPermissionRule permissionRule = GrantPermissionRule.grant(
+        Manifest.permission.WRITE_EXTERNAL_STORAGE);
+
+    @Test
+    public void displaySimpleTextFile() throws InterruptedException {
+        FileDisplayActivity sut = activityRule.launchActivity(null);
+
+        Thread.sleep(3000);
+
+        File file = new File(FileStorageUtils.getSavePath(account.name) + "/nonEmpty.txt");
+        OCFile test = new OCFile("/text.md");
+        test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
+        test.setStoragePath(file.getAbsolutePath());
+        sut.startTextPreview(test, false);
+
+        Thread.sleep(3000);
+
+        Screenshot.snapActivity(sut).record();
+    }
+
+    @Test
+    public void displayJavaSnippetFile() throws IOException, InterruptedException {
+        FileDisplayActivity sut = activityRule.launchActivity(null);
+
+        Thread.sleep(3000);
+
+        File file = getFile("java.md");
+        OCFile test = new OCFile("/java.md");
+        test.setMimeType(MimeTypeUtil.MIMETYPE_TEXT_MARKDOWN);
+        test.setStoragePath(file.getAbsolutePath());
+        sut.startTextPreview(test, false);
+
+        Thread.sleep(3000);
+
+        Screenshot.snapActivity(sut).record();
+    }
+}