a bit more testing…

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
tobiasKaminsky 2021-08-27 10:02:44 +02:00 committed by Andy Scherzinger
parent 1988bfe51b
commit 0d301eab25
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
5 changed files with 219 additions and 52 deletions

View file

@ -1,49 +0,0 @@
/*
* Nextcloud Talk application
*
* @author Mario Danic
* Copyright (C) 2017-2019 Mario Danic <mario@lovelyhq.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
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 <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
@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"));
}
}

View file

@ -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<MainActivity> = 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>(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()
}
}
}

View file

@ -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<MainActivity> = 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()
}
}
}

View file

@ -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")
)
}

View file

@ -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<AbstractFlexibleItem<*>>? = null
private var conversationItems: MutableList<AbstractFlexibleItem<*>> = ArrayList()
@VisibleForTesting var adapter: FlexibleAdapter<AbstractFlexibleItem<*>>? = null
@VisibleForTesting var conversationItems: MutableList<AbstractFlexibleItem<*>> = ArrayList()
private var conversationItemsWithHeader: MutableList<AbstractFlexibleItem<*>> = ArrayList()
private val searchableConversationItems: MutableList<AbstractFlexibleItem<*>> = ArrayList()
private var searchItem: MenuItem? = null