Skip to content
Merged
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
38 changes: 28 additions & 10 deletions app/src/androidTest/java/com/nextcloud/talk/ui/LoginIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,33 @@
*/
package com.nextcloud.talk.ui;

import android.content.Context;
import android.os.Bundle;

import com.nextcloud.talk.R;
import com.nextcloud.talk.conversationlist.ConversationsListActivity;
import com.nextcloud.talk.utils.AppTasks;

import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;

import java.util.Objects;

import kotlin.coroutines.EmptyCoroutineContext;

import androidx.compose.ui.test.junit4.ComposeTestRule;
import androidx.test.core.app.ActivityScenario;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.espresso.NoMatchingViewException;
import androidx.test.espresso.web.webdriver.DriverAtoms;
import androidx.test.espresso.web.webdriver.Locator;

import static androidx.compose.ui.test.ActionsKt.performClick;
import static androidx.compose.ui.test.AssertionsKt.assertIsDisplayed;
import static androidx.compose.ui.test.FindersKt.onNodeWithContentDescription;
import static androidx.compose.ui.test.FindersKt.onNodeWithText;
import static androidx.compose.ui.test.junit4.AndroidComposeTestRule_androidKt.createEmptyComposeRule;
import static androidx.test.espresso.Espresso.onView;
import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.action.ViewActions.typeText;
Expand All @@ -43,13 +53,17 @@
@Ignore("This test is ignored because it constantly fails on CI")
public class LoginIT {

@Rule
public final ComposeTestRule composeRule = createEmptyComposeRule(EmptyCoroutineContext.INSTANCE);

@Test
public void login() throws InterruptedException {

// started like by the launcher, without an account
ActivityScenario<ConversationsListActivity> activityScenario = ActivityScenario.launch(
AppTasks.INSTANCE.createLauncherIntent(ApplicationProvider.getApplicationContext()));

Context context = ApplicationProvider.getApplicationContext();
Bundle arguments = androidx.test.platform.app.InstrumentationRegistry.getArguments();

String baseUrl = arguments.getString("TEST_SERVER_URL");
Expand All @@ -71,14 +85,10 @@ public void login() throws InterruptedException {

try {
// Delete account if exists
onView(withContentDescription(R.string.nc_settings)).perform(click());
onView(withId(R.id.settings_remove_account)).perform(click());
onView(withText(R.string.nc_settings_remove)).perform(click());
// The remove button must be clicked two times
onView(withId(R.id.settings_remove_account)).perform(click());
// And yes: The button must be clicked two times
onView(withText(R.string.nc_settings_remove)).perform(click());
onView(withText(R.string.nc_settings_remove)).perform(click());
clickNodeWithContentDescription(context.getString(R.string.nc_settings));
clickNodeWithText(context.getString(R.string.nc_settings));
clickNodeWithText(context.getString(R.string.nc_settings_remove_account));
clickNodeWithText(context.getString(R.string.nc_settings_remove));
} catch (Exception ie2) {
// ignore
} finally {
Expand Down Expand Up @@ -124,12 +134,20 @@ public void login() throws InterruptedException {

Thread.sleep(5 * 1000);

onView(withContentDescription(R.string.nc_settings)).perform(click());
onView(withId(R.id.user_name)).check(matches(withText("User One")));
clickNodeWithContentDescription(context.getString(R.string.nc_settings));
assertIsDisplayed(onNodeWithText(composeRule, "User One", false, false, false));

activityScenario.onActivity(activity -> {
assertEquals(loginName,
Objects.requireNonNull(activity.defaultAccountProvider.getDefaultUserBlocking()).getUserId());
});
}

private void clickNodeWithText(String text) {
performClick(onNodeWithText(composeRule, text, false, false, false));
}

private void clickNodeWithContentDescription(String label) {
performClick(onNodeWithContentDescription(composeRule, label, false, false, false));
}
}
Loading