mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 21:25:35 +03:00
Screenshot tests ManageAccountsActivity
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
53024d1cd1
commit
0569b0de65
7 changed files with 100 additions and 12 deletions
Binary file not shown.
After Width: | Height: | Size: 42 KiB |
Binary file not shown.
After Width: | Height: | Size: 38 KiB |
|
@ -30,11 +30,14 @@ import java.io.File;
|
|||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Collection;
|
||||
|
||||
import androidx.test.espresso.contrib.DrawerActions;
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
import androidx.test.platform.app.InstrumentationRegistry;
|
||||
import androidx.test.runner.lifecycle.ActivityLifecycleMonitorRegistry;
|
||||
import androidx.test.runner.lifecycle.Stage;
|
||||
|
||||
import static androidx.test.InstrumentationRegistry.getInstrumentation;
|
||||
import static androidx.test.espresso.Espresso.onView;
|
||||
|
@ -52,6 +55,8 @@ public abstract class AbstractIT {
|
|||
protected static Account account;
|
||||
protected static Context targetContext;
|
||||
|
||||
private Activity currentActivity;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeAll() {
|
||||
try {
|
||||
|
@ -167,4 +172,18 @@ public abstract class AbstractIT {
|
|||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
protected Activity getCurrentActivity() {
|
||||
InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
|
||||
Collection<Activity> resumedActivities = ActivityLifecycleMonitorRegistry
|
||||
.getInstance()
|
||||
.getActivitiesInStage(Stage.RESUMED);
|
||||
|
||||
if (resumedActivities.iterator().hasNext()) {
|
||||
currentActivity = resumedActivities.iterator().next();
|
||||
}
|
||||
});
|
||||
|
||||
return currentActivity;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
*
|
||||
* 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.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
|
||||
import com.facebook.testing.screenshot.Screenshot;
|
||||
import com.nextcloud.client.account.User;
|
||||
import com.owncloud.android.AbstractIT;
|
||||
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule;
|
||||
|
||||
public class ManageAccountsActivityIT extends AbstractIT {
|
||||
@Rule
|
||||
public IntentsTestRule<ManageAccountsActivity> activityRule = new IntentsTestRule<>(ManageAccountsActivity.class,
|
||||
true,
|
||||
false);
|
||||
|
||||
@Test
|
||||
public void open() throws InterruptedException {
|
||||
Activity sut = activityRule.launchActivity(null);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snapActivity(sut).record();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void userInfoDetail() throws InterruptedException {
|
||||
ManageAccountsActivity sut = activityRule.launchActivity(null);
|
||||
|
||||
User user = sut.accountManager.getUser();
|
||||
sut.onClick(user);
|
||||
|
||||
Thread.sleep(2000);
|
||||
|
||||
Screenshot.snapActivity(getCurrentActivity()).record();
|
||||
}
|
||||
}
|
|
@ -824,9 +824,14 @@ public final class ThumbnailsCacheManager {
|
|||
private Context mContext;
|
||||
|
||||
|
||||
public AvatarGenerationTask(AvatarGenerationListener avatarGenerationListener, Object callContext,
|
||||
Account account, Resources resources, float avatarRadius, String userId,
|
||||
String serverName, Context context) {
|
||||
public AvatarGenerationTask(AvatarGenerationListener avatarGenerationListener,
|
||||
Object callContext,
|
||||
Account account,
|
||||
Resources resources,
|
||||
float avatarRadius,
|
||||
String userId,
|
||||
String serverName,
|
||||
Context context) {
|
||||
mAvatarGenerationListener = new WeakReference<>(avatarGenerationListener);
|
||||
mCallContext = callContext;
|
||||
mAccount = account;
|
||||
|
@ -865,7 +870,8 @@ public final class ThumbnailsCacheManager {
|
|||
AvatarGenerationListener listener = mAvatarGenerationListener.get();
|
||||
if (listener != null) {
|
||||
AvatarGenerationTask avatarWorkerTask = getAvatarWorkerTask(mCallContext);
|
||||
if (this == avatarWorkerTask && listener.shouldCallGeneratedCallback(mUserId, mCallContext)) {
|
||||
String accountName = mUserId + "@" + mServerName;
|
||||
if (this == avatarWorkerTask && listener.shouldCallGeneratedCallback(accountName, mCallContext)) {
|
||||
listener.avatarGenerated(drawable, mCallContext);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -460,7 +460,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
|
|||
@Override
|
||||
public void onClick(User user) {
|
||||
final Intent intent = new Intent(this, UserInfoActivity.class);
|
||||
intent.putExtra(UserInfoActivity.KEY_ACCOUNT, Parcels.wrap(user));
|
||||
intent.putExtra(UserInfoActivity.KEY_ACCOUNT, user);
|
||||
OwnCloudAccount oca = user.toOwnCloudAccount();
|
||||
intent.putExtra(KEY_DISPLAY_NAME, oca.getDisplayName());
|
||||
startActivityForResult(intent, KEY_USER_INFO_REQUEST_CODE);
|
||||
|
|
|
@ -53,7 +53,6 @@ import com.evernote.android.job.util.support.PersistableBundleCompat;
|
|||
import com.nextcloud.client.account.User;
|
||||
import com.nextcloud.client.di.Injectable;
|
||||
import com.nextcloud.client.preferences.AppPreferences;
|
||||
import com.nextcloud.java.util.Optional;
|
||||
import com.owncloud.android.R;
|
||||
import com.owncloud.android.jobs.AccountRemovalJob;
|
||||
import com.owncloud.android.lib.common.UserInfo;
|
||||
|
@ -126,13 +125,15 @@ public class UserInfoActivity extends FileActivity implements Injectable {
|
|||
super.onCreate(savedInstanceState);
|
||||
Bundle bundle = getIntent().getExtras();
|
||||
|
||||
final Account account = Parcels.unwrap(bundle.getParcelable(KEY_ACCOUNT));
|
||||
Optional<User> optionalUser = accountManager.getUser(account != null ? account.name : "");
|
||||
if(!optionalUser.isPresent()) {
|
||||
if (bundle == null) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
user = bundle.getParcelable(KEY_ACCOUNT);
|
||||
if(user == null) {
|
||||
finish();
|
||||
return;
|
||||
} else {
|
||||
user = optionalUser.get();
|
||||
}
|
||||
|
||||
if (savedInstanceState != null && savedInstanceState.containsKey(KEY_USER_DATA)) {
|
||||
|
@ -145,7 +146,7 @@ public class UserInfoActivity extends FileActivity implements Injectable {
|
|||
unbinder = ButterKnife.bind(this);
|
||||
|
||||
boolean useBackgroundImage = URLUtil.isValidUrl(
|
||||
getStorageManager().getCapability(account.name).getServerBackground());
|
||||
getStorageManager().getCapability(user.getAccountName()).getServerBackground());
|
||||
|
||||
setupToolbar(useBackgroundImage);
|
||||
updateActionBarTitleAndHomeButtonByString("");
|
||||
|
|
Loading…
Reference in a new issue