Compare commits

...
Author SHA1 Message Date
tobiasKaminsky 79151cad6f Screenshot tests without server
ActivityIT first one
separate annotations to keep track and easier create screenshots

Signed-off-by: tobiasKaminsky <[email protected]>
2020-06-16 16:02:06 +02:00
37 changed files with 529 additions and 50 deletions

No files matched your search

+2
View File
@@ -368,6 +368,8 @@ dependencies {
testImplementation 'org.json:json:20200518'
testImplementation "com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0"
testImplementation "androidx.arch.core:core-testing:2.1.0"
kaptAndroidTest "com.google.dagger:dagger-compiler:$daggerVersion"
kaptTest "com.google.dagger:dagger-compiler:$daggerVersion"
// dependencies for instrumented tests
// JUnit4 Rules
Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 24 KiB

+2 -2
View File
@@ -74,7 +74,7 @@ sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g
## update/create all screenshots
#./gradlew gplayDebugExecuteScreenshotTests -Precord \
#-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest
#-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotOnServerTest
## update screenshots in a class
#./gradlew gplayDebugExecuteScreenshotTests \
@@ -94,7 +94,7 @@ until [ $resultCode -eq 0 ] || [ $retryCount -gt 2 ]
do
# test all screenshots
./gradlew gplayDebugExecuteScreenshotTests \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotTest
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotOnServerTest
resultCode=$?
((retryCount++))
+57
View File
@@ -0,0 +1,57 @@
#!/usr/bin/env bash
## emulator
if [[ ! $(emulator -list-avds | grep uiComparison -c) -eq 0 ]]; then
avdmanager delete avd -n uiComparison
(sleep 5; echo "no") | avdmanager create avd -n uiComparison -c 100M -k "system-images;android-27;google_apis;x86" --abi "google_apis/x86"
fi
if [ "$1" == "debug" ]; then
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-audio -skin 500x833 1>/dev/null &
else
emulator -writable-system -avd uiComparison -no-snapshot -gpu swiftshader_indirect -no-window -no-audio -skin 500x833 1>/dev/null &
fi
PID=$!
scripts/wait_for_emulator.sh
sed -i s'#<bool name="is_beta">false</bool>#<bool name="is_beta">true</bool>#'g src/main/res/values/setup.xml
## update/create all screenshots
#./gradlew gplayDebugExecuteScreenshotTests -Precord \
#-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotWithoutServerTest
## update screenshots in a class
#./gradlew gplayDebugExecuteScreenshotTests \
#-Precord \
#-Pandroid.testInstrumentationRunnerArguments.class=\
#com.owncloud.android.ui.dialog.SyncFileNotEnoughSpaceDialogFragmentTest
## update single screenshot within a class
#./gradlew gplayDebugExecuteScreenshotTests \
#-Precord \
#-Pandroid.testInstrumentationRunnerArguments.class=\
#com.nextcloud.client.FileDisplayActivityIT#showShares
resultCode=-1
retryCount=0
until [ $resultCode -eq 0 ] || [ $retryCount -gt 2 ]
do
# test all screenshots
./gradlew gplayDebugRemoveScreenshots
./gradlew gplayDebugExecuteScreenshotTests \
-Precord \
-Pandroid.testInstrumentationRunnerArguments.annotation=com.owncloud.android.utils.ScreenshotWithoutServerTest
resultCode=$?
((retryCount++))
done
sed -i s'#<bool name="is_beta">true</bool>#<bool name="is_beta">false</bool>#'g src/main/res/values/setup.xml
if [ "$1" == "debug" ]; then
exit
fi
# tidy up
kill "$PID"
+2
View File
@@ -31,4 +31,6 @@
android:sharedUserId="${applicationId}.uid">
<uses-sdk tools:overrideLibrary="android_libs.ub_uiautomator, tools.fastlane.screengrab" />
<application android:name="com.owncloud.android.TestApp"></application>
</manifest>
@@ -23,13 +23,13 @@
package com.nextcloud.client;
import android.Manifest;
import android.view.View;
import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.R;
import com.owncloud.android.ui.activities.ActivitiesActivity;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithoutServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -52,6 +52,18 @@ public class ActivitiesActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithoutServerTest
@ScreenshotTest
public void open() {
ActivitiesActivity sut = activityRule.launchActivity(null);
shortSleep();
Screenshot.snapActivity(sut).record();
}
@Test
@ScreenshotWithoutServerTest
@ScreenshotTest
public void openDrawer() {
ActivitiesActivity sut = activityRule.launchActivity(null);
@@ -60,15 +72,7 @@ public class ActivitiesActivityIT extends AbstractIT {
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open());
sut.runOnUiThread(new Runnable() {
@Override
public void run() {
sut.emptyContentContainer.setVisibility(View.VISIBLE);
sut.recyclerView.setVisibility(View.INVISIBLE);
}
});
waitForIdleSync();
shortSleep();
Screenshot.snapActivity(sut).record();
}
@@ -39,6 +39,7 @@ import com.owncloud.android.operations.CreateFolderOperation;
import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.ui.events.SearchEvent;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.greenrobot.eventbus.EventBus;
import org.junit.Assert;
@@ -66,6 +67,7 @@ public class FileDisplayActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void open() {
Activity sut = activityRule.launchActivity(null);
@@ -76,6 +78,7 @@ public class FileDisplayActivityIT extends AbstractIT {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void drawer() {
FileDisplayActivity sut = activityRule.launchActivity(null);
@@ -90,6 +93,7 @@ public class FileDisplayActivityIT extends AbstractIT {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void showShares() {
assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
@@ -29,6 +29,7 @@ import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.onboarding.FirstRunActivity;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -47,6 +48,7 @@ public class FirstRunActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void open() {
Activity sut = activityRule.launchActivity(null);
@@ -27,6 +27,7 @@ import android.Manifest;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.NotificationsActivity;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -45,6 +46,7 @@ public class NotificationsActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
@@ -22,14 +22,25 @@
package com.nextcloud.client;
import android.app.Application;
import android.content.Context;
import android.os.Bundle;
import com.facebook.testing.screenshot.ScreenshotRunner;
import com.owncloud.android.TestApp;
import androidx.test.runner.AndroidJUnitRunner;
public class ScreenshotTestRunner extends AndroidJUnitRunner {
@Override
public Application newApplication(ClassLoader cl, String className, Context context)
throws ClassNotFoundException,
IllegalAccessException,
InstantiationException {
return super.newApplication(cl, TestApp.class.getName(), context);
}
@Override
public void onCreate(Bundle args) {
super.onCreate(args);
@@ -29,6 +29,7 @@ import com.facebook.testing.screenshot.Screenshot;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.SettingsActivity;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithoutServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -47,6 +48,7 @@ public class SettingsActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithoutServerTest
@ScreenshotTest
public void open() {
Activity test = activityRule.launchActivity(null);
@@ -26,7 +26,7 @@ import android.Manifest;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.SyncedFoldersActivity;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -45,6 +45,7 @@ public class SyncedFoldersActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
@@ -27,6 +27,7 @@ import android.Manifest;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.ui.activity.UploadListActivity;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -45,6 +46,7 @@ public class UploadListActivityActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
@@ -29,6 +29,7 @@ import com.facebook.testing.screenshot.Screenshot
import com.owncloud.android.AbstractIT
import com.owncloud.android.lib.resources.status.OwnCloudVersion
import com.owncloud.android.utils.ScreenshotTest
import com.owncloud.android.utils.ScreenshotWithServerTest
import org.junit.Assume
import org.junit.Before
import org.junit.Rule
@@ -47,6 +48,7 @@ class EtmActivityTest : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun overview() {
val sut: Activity = activityRule.launchActivity(null)
@@ -57,6 +59,7 @@ class EtmActivityTest : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun preferences() {
val sut: EtmActivity = activityRule.launchActivity(null)
@@ -67,6 +70,7 @@ class EtmActivityTest : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun accounts() {
val sut: EtmActivity = activityRule.launchActivity(null)
@@ -0,0 +1,37 @@
/*
*
* 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;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApi;
import dagger.Module;
import dagger.Provides;
@Module
public class ActivitiesModuleMock {
@Provides
ActivitiesRepository activitiesRepository(ActivitiesServiceApi api) {
return new LocalActivitiesRepository();
}
}
@@ -0,0 +1,133 @@
/*
*
* 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;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.google.gson.JsonSyntaxException;
import com.google.gson.reflect.TypeToken;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.lib.resources.activities.model.Activity;
import com.owncloud.android.lib.resources.activities.model.RichElement;
import com.owncloud.android.lib.resources.activities.model.RichElementTypeAdapter;
import com.owncloud.android.lib.resources.activities.models.PreviewObject;
import com.owncloud.android.lib.resources.activities.models.PreviewObjectAdapter;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import static com.owncloud.android.ui.activity.ContactsPreferenceActivity.TAG;
public class LocalActivitiesRepository implements ActivitiesRepository {
String json = "{\n" +
" \"ocs\": {\n" +
" \"meta\": {\n" +
" \"status\": \"ok\",\n" +
" \"statuscode\": 200,\n" +
" \"message\": \"OK\"\n" +
" },\n" +
" \"data\": [\n" +
" {\n" +
" \"activity_id\": 1114442,\n" +
" \"app\": \"files\",\n" +
" \"type\": \"file_created\",\n" +
" \"user\": \"test\",\n" +
" \"subject\": \"You created IMG_0255.JPG\",\n" +
" \"subject_rich\": [\n" +
" \"You created {file}\",\n" +
" {\n" +
" \"file\": {\n" +
" \"type\": \"file\",\n" +
" \"id\": \"3523820\",\n" +
" \"name\": \"IMG_0255.JPG\",\n" +
" \"path\": \"IMG_0255.JPG\",\n" +
" \"link\": \"https:\\/\\/cloud.server.com\\/f\\/3523820\"\n" +
" }\n" +
" }\n" +
" ],\n" +
" \"message\": \"\",\n" +
" \"message_rich\": [\n" +
" \"\",\n" +
" []\n" +
" ],\n" +
" \"object_type\": \"files\",\n" +
" \"object_id\": 3523820,\n" +
" \"object_name\": \"\\/IMG_0255.JPG\",\n" +
" \"objects\": {\n" +
" \"3523820\": \"\\/IMG_0255.JPG\"\n" +
" },\n" +
" \"link\": \"https:\\/\\/cloud.server.com\\/apps\\/files\\/?dir=\\/\",\n" +
" \"icon\": \"https:\\/\\/cloud.server.com\\/apps\\/files\\/img\\/add-color.svg\",\n" +
" \"datetime\": \"2020-03-19T12:18:25+00:00\",\n" +
" \"previews\": [\n" +
" {\n" +
" \"link\": \"https:\\/\\/cloud.server.com\\/apps\\/files\\/?dir=\\/&scrollto=IMG_0255.JPG\",\n" +
" \"source\": \"https:\\/\\/cloud.server.com\\/core\\/preview.png?file=\\/IMG_0255.JPG&c=b68e0f2668cc89eec0d17e6125ff8ae7&x=150&y=150\",\n" +
" \"mimeType\": \"image\\/jpeg\",\n" +
" \"isMimeTypeIcon\": false,\n" +
" \"fileId\": 3523820,\n" +
" \"view\": \"files\"\n" +
" }\n" +
" ]\n" +
" }]}}";
@Override
public void getActivities(int lastGiven, @NonNull LoadActivitiesCallback callback) {
ArrayList activities = parseResult(json);
callback.onActivitiesLoaded(activities, 1);
}
protected ArrayList<Activity> parseResult(String response) {
if (response == null || response.isEmpty()) {
return new ArrayList<>();
}
try {
JsonParser jsonParser = new JsonParser();
JsonObject jo = (JsonObject) jsonParser.parse(response);
JsonArray jsonDataArray = jo.getAsJsonObject("ocs").getAsJsonArray("data");
Gson gson = new GsonBuilder()
.registerTypeAdapter(RichElement.class, new RichElementTypeAdapter())
.registerTypeAdapter(PreviewObject.class, new PreviewObjectAdapter())
.create();
Type listType = new TypeToken<List<Activity>>() {
}.getType();
return gson.fromJson(jsonDataArray, listType);
} catch (JsonSyntaxException e) {
Log_OC.e(TAG, "Not a valid json: " + response, e);
return new ArrayList<>();
}
}
}
@@ -0,0 +1,33 @@
/*
*
* 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
class TestApp : MainApp() {
override fun setupDagger() {
DaggerTestAppComponent.builder()
.application(this)
.build()
.inject(this);
}
}
@@ -0,0 +1,67 @@
/*
*
* 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;
import android.app.Application;
import com.nextcloud.client.appinfo.AppInfoModule;
import com.nextcloud.client.device.DeviceModule;
import com.nextcloud.client.di.AppModule;
import com.nextcloud.client.di.ViewModelModule;
import com.nextcloud.client.jobs.JobsModule;
import com.nextcloud.client.network.NetworkModule;
import com.nextcloud.client.onboarding.OnboardingModule;
import com.nextcloud.client.preferences.PreferencesModule;
import javax.inject.Singleton;
import dagger.BindsInstance;
import dagger.Component;
import dagger.android.support.AndroidSupportInjectionModule;
@Singleton
@Component(modules = {
AndroidSupportInjectionModule.class,
AppModule.class,
PreferencesModule.class,
AppInfoModule.class,
NetworkModule.class,
DeviceModule.class,
OnboardingModule.class,
ViewModelModule.class,
JobsModule.class,
ActivitiesModuleMock.class
})
public interface TestAppComponent {
void inject(TestApp app);
@Component.Builder
interface Builder {
@BindsInstance
Builder application(Application application);
TestAppComponent build();
}
}
@@ -28,6 +28,7 @@ import com.facebook.testing.screenshot.Screenshot;
import com.nextcloud.client.account.User;
import com.owncloud.android.AbstractIT;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -41,6 +42,7 @@ public class ManageAccountsActivityIT extends AbstractIT {
false);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void open() {
Activity sut = activityRule.launchActivity(null);
@@ -51,6 +53,7 @@ public class ManageAccountsActivityIT extends AbstractIT {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void userInfoDetail() {
ManageAccountsActivity sut = activityRule.launchActivity(null);
@@ -50,6 +50,7 @@ import com.owncloud.android.operations.UploadFileOperation
import com.owncloud.android.ui.activity.FileDisplayActivity
import com.owncloud.android.utils.FileStorageUtils
import com.owncloud.android.utils.ScreenshotTest
import com.owncloud.android.utils.ScreenshotWithServerTest
import junit.framework.TestCase
import org.junit.Assert.assertTrue
import org.junit.Rule
@@ -89,6 +90,7 @@ class OCFileListFragmentIT : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun showRichWorkspace() {
assertTrue(CreateFolderOperation("/test/", account, targetContext).execute(client, storageManager).isSuccess)
@@ -167,6 +169,7 @@ class OCFileListFragmentIT : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun createAndShowShareToUser() {
val path = "/shareToAdmin/"
@@ -192,6 +195,7 @@ class OCFileListFragmentIT : AbstractIT() {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun createAndShowShareToGroup() {
val path = "/shareToGroup/"
@@ -249,6 +253,7 @@ class OCFileListFragmentIT : AbstractIT() {
// }
@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun createAndShowShareViaLink() {
val path = "/shareViaLink/"
@@ -31,6 +31,7 @@ import com.owncloud.android.ui.activity.FileDisplayActivity;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import com.owncloud.android.utils.ScreenshotTest;
import com.owncloud.android.utils.ScreenshotWithServerTest;
import org.junit.Rule;
import org.junit.Test;
@@ -51,6 +52,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void displaySimpleTextFile() {
FileDisplayActivity sut = activityRule.launchActivity(null);
@@ -69,6 +71,7 @@ public class PreviewTextFileFragmentTest extends AbstractIT {
}
@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void displayJavaSnippetFile() throws IOException {
FileDisplayActivity sut = activityRule.launchActivity(null);
@@ -0,0 +1,38 @@
/*
*
* 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.nextcloud.client.di;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApi;
import com.owncloud.android.ui.activities.data.activities.RemoteActivitiesRepository;
import dagger.Module;
import dagger.Provides;
@Module
public class ActivitiesModule {
@Provides
ActivitiesRepository activitiesRepository(ActivitiesServiceApi api) {
return new RemoteActivitiesRepository(api);
}
}
@@ -45,7 +45,8 @@ import dagger.android.support.AndroidSupportInjectionModule;
DeviceModule.class,
OnboardingModule.class,
ViewModelModule.class,
JobsModule.class
JobsModule.class,
ActivitiesModule.class
})
@Singleton
public interface AppComponent {
@@ -50,10 +50,8 @@ import com.nextcloud.client.migrations.MigrationsManagerImpl;
import com.nextcloud.client.network.ClientFactory;
import com.owncloud.android.datamodel.ArbitraryDataProvider;
import com.owncloud.android.datamodel.UploadsStorageManager;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApi;
import com.owncloud.android.ui.activities.data.activities.ActivitiesServiceApiImpl;
import com.owncloud.android.ui.activities.data.activities.RemoteActivitiesRepository;
import com.owncloud.android.ui.activities.data.files.FilesRepository;
import com.owncloud.android.ui.activities.data.files.FilesServiceApiImpl;
import com.owncloud.android.ui.activities.data.files.RemoteFilesRepository;
@@ -68,7 +66,7 @@ import dagger.Module;
import dagger.Provides;
@Module(includes = {ComponentsModule.class, VariantComponentsModule.class})
class AppModule {
public class AppModule {
@Provides
AccountManager accountManager(Application application) {
@@ -109,10 +107,6 @@ class AppModule {
return new ActivitiesServiceApiImpl(accountManager);
}
@Provides
ActivitiesRepository activitiesRepository(ActivitiesServiceApi api) {
return new RemoteActivitiesRepository(api);
}
@Provides
FilesRepository filesRepository(UserAccountManager accountManager, ClientFactory clientFactory) {
@@ -98,6 +98,7 @@ import javax.net.ssl.SSLEngine;
import androidx.annotation.RequiresApi;
import androidx.annotation.StringRes;
import androidx.annotation.VisibleForTesting;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.core.util.Pair;
@@ -222,10 +223,7 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
super.attachBaseContext(base);
initGlobalContext(this);
DaggerAppComponent.builder()
.application(this)
.build()
.inject(this);
setupDagger();
// we don't want to handle crashes occurring inside crash reporter activity/process;
// let the platform deal with those
@@ -240,6 +238,14 @@ public class MainApp extends MultiDexApplication implements HasAndroidInjector {
}
}
@VisibleForTesting
public void setupDagger() {
DaggerAppComponent.builder()
.application(this)
.build()
.inject(this);
}
@SuppressFBWarnings("ST")
@Override
public void onCreate() {
@@ -29,7 +29,6 @@ import android.widget.ProgressBar;
import android.widget.TextView;
import com.nextcloud.client.network.ClientFactory;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.R;
import com.owncloud.android.datamodel.FileDataStorageManager;
import com.owncloud.android.datamodel.OCFile;
@@ -52,7 +51,6 @@ import java.util.List;
import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@@ -233,12 +231,12 @@ public class ActivitiesActivity extends FileActivity implements ActivityListInte
}
@Override
public void showActivities(List<Object> activities, NextcloudClient client, int lastGiven) {
public void showActivities(List<Object> activities, int lastGiven) {
boolean clear = false;
if (this.lastGiven == UNDEFINED) {
clear = true;
}
adapter.setActivityItems(activities, client, clear);
adapter.setActivityItems(activities, clear);
this.lastGiven = lastGiven;
// Hide the recyclerView if list is empty
@@ -18,7 +18,6 @@
*/
package com.owncloud.android.ui.activities;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activity.BaseActivity;
@@ -27,7 +26,7 @@ import java.util.List;
public interface ActivitiesContract {
interface View {
void showActivities(List<Object> activities, NextcloudClient client, int lastGiven);
void showActivities(List<Object> activities, int lastGiven);
void showActivitiesLoadError(String error);
void showActivityDetailUI(OCFile ocFile);
void showActivityDetailUIIsNull();
@@ -19,7 +19,6 @@
package com.owncloud.android.ui.activities;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.datamodel.OCFile;
import com.owncloud.android.ui.activities.data.activities.ActivitiesRepository;
import com.owncloud.android.ui.activities.data.files.FilesRepository;
@@ -51,11 +50,11 @@ public class ActivitiesPresenter implements ActivitiesContract.ActionListener {
activitiesView.setProgressIndicatorState(true);
activitiesRepository.getActivities(lastGiven, new ActivitiesRepository.LoadActivitiesCallback() {
@Override
public void onActivitiesLoaded(List<Object> activities, NextcloudClient client, int lastGiven) {
public void onActivitiesLoaded(List<Object> activities, int lastGiven) {
if (!activityStopped) {
activitiesView.setProgressIndicatorState(false);
activitiesView.showActivities(activities, client, lastGiven);
activitiesView.showActivities(activities, lastGiven);
}
}
@@ -18,8 +18,6 @@
*/
package com.owncloud.android.ui.activities.data.activities;
import com.nextcloud.common.NextcloudClient;
import java.util.List;
import androidx.annotation.NonNull;
@@ -29,7 +27,7 @@ import androidx.annotation.NonNull;
*/
public interface ActivitiesRepository {
interface LoadActivitiesCallback {
void onActivitiesLoaded(List<Object> activities, NextcloudClient client, int lastGiven);
void onActivitiesLoaded(List<Object> activities, int lastGiven);
void onActivitiesLoadedError(String error);
}
@@ -18,7 +18,6 @@
*/
package com.owncloud.android.ui.activities.data.activities;
import com.nextcloud.common.NextcloudClient;
import com.owncloud.android.lib.resources.activities.model.Activity;
import java.util.List;
@@ -31,10 +30,9 @@ import java.util.List;
public interface ActivitiesServiceApi {
interface ActivitiesServiceCallback<T> {
void onLoaded(T activities, NextcloudClient client, int lastGiven);
void onLoaded(T activities, int lastGiven);
void onError (String error);
}
void getAllActivities(int lastGiven, ActivitiesServiceApi.ActivitiesServiceCallback<List<Object>> callback);
}
@@ -71,7 +71,6 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
private Account account;
private int lastGiven;
private String errorMessage;
private NextcloudClient client;
private GetActivityListTask(Account account,
int lastGiven,
@@ -89,7 +88,7 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
OwnCloudAccount ocAccount;
try {
ocAccount = new OwnCloudAccount(account, context);
client = OwnCloudClientManagerFactory.getDefaultSingleton().
NextcloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton().
getNextcloudClientFor(ocAccount, MainApp.getAppContext());
GetActivitiesRemoteOperation getRemoteActivitiesOperation;
@@ -138,7 +137,7 @@ public class ActivitiesServiceApiImpl implements ActivitiesServiceApi {
protected void onPostExecute(Boolean success) {
super.onPostExecute(success);
if (success) {
callback.onLoaded(activities, client, lastGiven);
callback.onLoaded(activities, lastGiven);
} else {
callback.onError(errorMessage);
}
@@ -18,8 +18,6 @@
*/
package com.owncloud.android.ui.activities.data.activities;
import com.nextcloud.common.NextcloudClient;
import java.util.List;
import androidx.annotation.NonNull;
@@ -38,8 +36,8 @@ public class RemoteActivitiesRepository implements ActivitiesRepository {
activitiesServiceApi.getAllActivities(lastGiven,
new ActivitiesServiceApi.ActivitiesServiceCallback<List<Object>>() {
@Override
public void onLoaded(List<Object> activities, NextcloudClient client, int lastGiven) {
callback.onActivitiesLoaded(activities, client, lastGiven);
public void onLoaded(List<Object> activities, int lastGiven) {
callback.onActivitiesLoaded(activities, lastGiven);
}
@Override
@@ -119,12 +119,16 @@ public class ActivityListAdapter extends RecyclerView.Adapter<RecyclerView.ViewH
this.storageManager = storageManager;
this.capability = capability;
this.clientFactory = clientFactory;
try {
this.client = clientFactory.createNextcloudClient(currentAccountProvider.getUser());
} catch (ClientFactory.CreationException e) {
Log_OC.e(this, "Failed to create client", e);
}
px = getThumbnailDimension();
this.isDetailView = isDetailView;
}
public void setActivityItems(List<Object> activityItems, NextcloudClient client, boolean clear) {
this.client = client;
public void setActivityItems(List<Object> activityItems, boolean clear) {
String sTime = "";
if (clear) {
@@ -20,7 +20,6 @@
package com.owncloud.android.ui.adapter;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.Typeface;
import android.graphics.drawable.PictureDrawable;
@@ -0,0 +1,37 @@
/*
*
* 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.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotate any screenshot test with this so it is run only when updating/testing screenshots
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ScreenshotWithServerTest {
}
@@ -0,0 +1,37 @@
/*
*
* 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.utils;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Annotate any screenshot test with this so it is run only when updating/testing screenshots
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface ScreenshotWithoutServerTest {
}