mirror of
https://github.com/nextcloud/android.git
synced 2024-11-26 07:05:49 +03:00
add UI test for Markdown
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
987b728464
commit
eb903ab486
5 changed files with 125 additions and 1 deletions
Binary file not shown.
After Width: | Height: | Size: 34 KiB |
Binary file not shown.
After Width: | Height: | Size: 12 KiB |
23
src/androidTest/assets/java.md
Normal file
23
src/androidTest/assets/java.md
Normal file
|
@ -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;
|
||||
}
|
||||
```
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue