Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Activity mock #6301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions scripts/updateScreenshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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++))
Expand Down
57 changes: 57 additions & 0 deletions scripts/updateScreenshotsWithoutServer.sh
Original file line number Diff line number Diff line change
@@ -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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


## 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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if [ "$1" == "debug" ]; then
exit
fi

# tidy up
kill "$PID"
2 changes: 2 additions & 0 deletions src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
24 changes: 14 additions & 10 deletions src/androidTest/java/com/nextcloud/client/ActivitiesActivityIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -60,15 +72,7 @@ public void openDrawer() {

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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
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;
Expand Down Expand Up @@ -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);
Expand All @@ -76,6 +78,7 @@ public void open() {
}

@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void drawer() {
FileDisplayActivity sut = activityRule.launchActivity(null);
Expand All @@ -90,6 +93,7 @@ public void drawer() {
}

@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void showShares() {
assertTrue(new ExistenceCheckRemoteOperation("/shareToAdmin/", true).execute(client).isSuccess());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -45,6 +46,7 @@ public class NotificationsActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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;
Expand All @@ -45,6 +45,7 @@ public class SyncedFoldersActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
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;
Expand All @@ -45,6 +46,7 @@ public class UploadListActivityActivityIT extends AbstractIT {
Manifest.permission.WRITE_EXTERNAL_STORAGE);

@Test
@ScreenshotWithServerTest
@ScreenshotTest
public void openDrawer() {
super.openDrawer(activityRule);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -47,6 +48,7 @@ class EtmActivityTest : AbstractIT() {
}

@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun overview() {
val sut: Activity = activityRule.launchActivity(null)
Expand All @@ -57,6 +59,7 @@ class EtmActivityTest : AbstractIT() {
}

@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun preferences() {
val sut: EtmActivity = activityRule.launchActivity(null)
Expand All @@ -67,6 +70,7 @@ class EtmActivityTest : AbstractIT() {
}

@Test
@ScreenshotWithServerTest
@ScreenshotTest
fun accounts() {
val sut: EtmActivity = activityRule.launchActivity(null)
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
}
}
Loading