From 0d301eab255fb020c4cd0942815499a775946628 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 27 Aug 2021 10:02:44 +0200 Subject: [PATCH] =?UTF-8?q?a=20bit=20more=20testing=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: tobiasKaminsky --- .../talk/ExampleInstrumentedTest.java | 49 ------ .../talk/activities/MainActivityIT.kt | 70 +++++++++ .../nextcloud/talk/activities/NoServerIT.kt | 144 ++++++++++++++++++ .../nextcloud/talk/activities/MainActivity.kt | 3 +- .../ConversationsListController.kt | 5 +- 5 files changed, 219 insertions(+), 52 deletions(-) delete mode 100644 app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java create mode 100644 app/src/androidTest/java/com/nextcloud/talk/activities/MainActivityIT.kt create mode 100644 app/src/androidTest/java/com/nextcloud/talk/activities/NoServerIT.kt diff --git a/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java deleted file mode 100644 index a55790b95..000000000 --- a/app/src/androidTest/java/com/nextcloud/talk/ExampleInstrumentedTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Nextcloud Talk application - * - * @author Mario Danic - * Copyright (C) 2017-2019 Mario Danic - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU 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 General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package com.nextcloud.talk; - -import android.content.Context; - -import org.junit.Test; -import org.junit.runner.RunWith; - -import androidx.test.InstrumentationRegistry; -import androidx.test.runner.AndroidJUnit4; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * Instrumented test, which will execute on an Android device. - * - * @see Testing documentation - */ -@RunWith(AndroidJUnit4.class) -public class ExampleInstrumentedTest { - @Test - public void useAppContext() throws Exception { - // Context of the app under test. - Context appContext = InstrumentationRegistry.getTargetContext(); - - assertNotNull(appContext.getPackageName()); - assertTrue("The package name must start with 'com.nextcloud.talk2'", appContext.getPackageName().startsWith("com.nextcloud.talk2")); - } -} diff --git a/app/src/androidTest/java/com/nextcloud/talk/activities/MainActivityIT.kt b/app/src/androidTest/java/com/nextcloud/talk/activities/MainActivityIT.kt new file mode 100644 index 000000000..ec49d4264 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/talk/activities/MainActivityIT.kt @@ -0,0 +1,70 @@ +package com.nextcloud.talk.activities + +import android.util.Log +import androidx.test.espresso.intent.rule.IntentsTestRule +import com.bluelinelabs.logansquare.LoganSquare +import com.nextcloud.talk.models.database.UserEntity +import com.nextcloud.talk.models.json.capabilities.Capabilities +import com.nextcloud.talk.models.json.capabilities.CapabilitiesOverall +import com.nextcloud.talk.utils.ApiUtils +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers +import org.junit.Rule +import org.junit.Test + +class MainActivityIT { + @get:Rule + val activityRule: IntentsTestRule = IntentsTestRule( + MainActivity::class.java, + true, + false + ) + + @Test + fun login() { + val sut = activityRule.launchActivity(null) + + val baseUrl = "http://10.0.2.2/nc" + val userId = "test" + val token = "test" + val credentials = ApiUtils.getCredentials(userId, token) + var capabilities: Capabilities? + + sut.ncApi.getCapabilities(credentials, ApiUtils.getUrlForCapabilities(baseUrl)) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { capabilitiesOverall: CapabilitiesOverall? -> + capabilities = capabilitiesOverall?.ocs?.data?.capabilities + + sut.userUtils.createOrUpdateUser( + userId, + token, + baseUrl, + "test", + null, + true, + userId, + null, + LoganSquare.serialize(capabilities), + null, + null + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { userEntity: UserEntity? -> Log.i("test", "stored: " + userEntity.toString()) } + try { + Thread.sleep(2000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + + sut.runOnUiThread { sut.resetConversationsList() } + } + + try { + Thread.sleep(20000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + } +} diff --git a/app/src/androidTest/java/com/nextcloud/talk/activities/NoServerIT.kt b/app/src/androidTest/java/com/nextcloud/talk/activities/NoServerIT.kt new file mode 100644 index 000000000..b75d61341 --- /dev/null +++ b/app/src/androidTest/java/com/nextcloud/talk/activities/NoServerIT.kt @@ -0,0 +1,144 @@ +package com.nextcloud.talk.activities + +import android.util.Log +import android.view.View +import androidx.test.espresso.intent.rule.IntentsTestRule +import com.bluelinelabs.logansquare.LoganSquare +import com.nextcloud.talk.adapters.items.ConversationItem +import com.nextcloud.talk.controllers.ConversationsListController +import com.nextcloud.talk.models.database.UserEntity +import com.nextcloud.talk.models.json.capabilities.Capabilities +import com.nextcloud.talk.models.json.capabilities.SpreedCapability +import com.nextcloud.talk.models.json.conversations.Conversation +import io.reactivex.android.schedulers.AndroidSchedulers +import io.reactivex.schedulers.Schedulers +import org.junit.Rule +import org.junit.Test + +class NoServerIT { + @get:Rule + val activityRule: IntentsTestRule = IntentsTestRule( + MainActivity::class.java, + true, + false + ) + + @Test + fun showConversationList() { + val sut = activityRule.launchActivity(null) + + val baseUrl = "http://server.com" + val userId = "test" + val token = "test" + val capabilities = Capabilities().apply { + spreedCapability = SpreedCapability() + spreedCapability.features = arrayListOf() + spreedCapability.features.add(0, "no-ping") + spreedCapability.features.add(1, "conversation-v4") + } + + sut.userUtils.createOrUpdateUser( + userId, + token, + baseUrl, + "test", + null, + true, + userId, + null, + LoganSquare.serialize(capabilities), + null, + null + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { userEntity: UserEntity? -> Log.i("test", "stored: " + userEntity.toString()) } + + sut.runOnUiThread { + sut.resetConversationsList() + } + + try { + Thread.sleep(1000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + val controller = + sut.router?.getControllerWithTag("ConversationListController") as ConversationsListController + + val conversation = Conversation().apply { + displayName = "Test Conversation" + this.token = "1" + type = Conversation.ConversationType.ROOM_TYPE_ONE_TO_ONE_CALL + } + + sut.runOnUiThread { + controller.loadingContent.visibility = View.GONE + controller.emptyLayoutView.visibility = View.GONE + controller.swipeRefreshLayout.visibility = View.VISIBLE + controller.recyclerView.visibility = View.VISIBLE + controller.callItems.add(ConversationItem(conversation, sut.userUtils.currentUser, sut)) + controller.adapter.updateDataSet(controller.callItems, false) + } + + try { + Thread.sleep(5000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + } + + @Test + fun showSettings() { + val sut = activityRule.launchActivity(null) + + val baseUrl = "http://10.0.2.2/nc" + val userId = "test" + val token = "test" + val capabilities = Capabilities().apply { + spreedCapability = SpreedCapability() + spreedCapability.features = arrayListOf() + spreedCapability.features.add(0, "no-ping") + spreedCapability.features.add(1, "conversation-v4") + } + + sut.userUtils.createOrUpdateUser( + userId, + token, + baseUrl, + "test", + null, + true, + userId, + null, + LoganSquare.serialize(capabilities), + null, + null + ) + .subscribeOn(Schedulers.io()) + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { userEntity: UserEntity? -> Log.i("test", "stored: " + userEntity.toString()) } + + try { + Thread.sleep(2000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + + sut.runOnUiThread { sut.openSettings() } + + try { + Thread.sleep(20000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + } + + fun shortWait() { + try { + Thread.sleep(20000) + } catch (e: InterruptedException) { + e.printStackTrace() + } + } +} diff --git a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt index f0dcf32cb..95f40cb51 100644 --- a/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt +++ b/app/src/main/java/com/nextcloud/talk/activities/MainActivity.kt @@ -75,7 +75,7 @@ class MainActivity : BaseActivity(), ActionBarProvider { @Inject lateinit var userManager: UserManager - private var router: Router? = null + public var router: Router? = null @Suppress("Detekt.TooGenericExceptionCaught") override fun onCreate(savedInstanceState: Bundle?) { @@ -169,6 +169,7 @@ class MainActivity : BaseActivity(), ActionBarProvider { RouterTransaction.with(ConversationsListController(Bundle())) .pushChangeHandler(HorizontalChangeHandler()) .popChangeHandler(HorizontalChangeHandler()) + .tag("ConversationListController") ) } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt index 3674200d9..e75e043bb 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt +++ b/app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.kt @@ -47,6 +47,7 @@ import android.view.View import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager import android.widget.Toast +import androidx.annotation.VisibleForTesting import androidx.appcompat.app.AlertDialog import androidx.appcompat.widget.SearchView import androidx.core.view.MenuItemCompat @@ -168,8 +169,8 @@ class ConversationsListController(bundle: Bundle) : private var currentUser: User? = null private var roomsQueryDisposable: Disposable? = null private var openConversationsQueryDisposable: Disposable? = null - private var adapter: FlexibleAdapter>? = null - private var conversationItems: MutableList> = ArrayList() + @VisibleForTesting var adapter: FlexibleAdapter>? = null + @VisibleForTesting var conversationItems: MutableList> = ArrayList() private var conversationItemsWithHeader: MutableList> = ArrayList() private val searchableConversationItems: MutableList> = ArrayList() private var searchItem: MenuItem? = null