Browse Source

initial idea to login in during tests

Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
tobiasKaminsky 4 năm trước cách đây
mục cha
commit
5ad48b3757

+ 8 - 0
app/build.gradle

@@ -159,6 +159,7 @@ ext {
     retrofit2Version = "2.9.0"
     workVersion = "2.6.0"
     markwonVersion =  "4.6.2"
+    espressoVersion = "3.4.0"
 }
 
 configurations.all {
@@ -296,6 +297,13 @@ dependencies {
     testImplementation "org.powermock:powermock-module-junit4:${powermockVersion}"
     testImplementation "org.powermock:powermock-api-mockito2:${powermockVersion}"
 
+    // Espresso core
+    androidTestImplementation "androidx.test.espresso:espresso-core:$espressoVersion"
+    androidTestImplementation "androidx.test.espresso:espresso-contrib:$espressoVersion"
+    androidTestImplementation "androidx.test.espresso:espresso-web:$espressoVersion"
+    androidTestImplementation "androidx.test.espresso:espresso-accessibility:$espressoVersion"
+    androidTestImplementation('com.android.support.test.espresso:espresso-intents:3.0.2')
+
     androidTestImplementation ('androidx.test.espresso:espresso-core:3.4.0', {
         exclude group: 'com.android.support', module: 'support-annotations'
     })

+ 59 - 0
app/src/androidTest/java/com/nextcloud/talk/activities/MainActivityTest.kt

@@ -0,0 +1,59 @@
+package com.nextcloud.talk.activities
+
+import android.util.Log
+import androidx.test.espresso.intent.rule.IntentsTestRule
+import com.nextcloud.talk.models.database.UserEntity
+import io.reactivex.android.schedulers.AndroidSchedulers
+import io.reactivex.schedulers.Schedulers
+import junit.framework.Assert.assertTrue
+import org.junit.Rule
+import org.junit.Test
+
+class MainActivityTest {
+    @get:Rule
+    val activityRule: IntentsTestRule<MainActivity> = IntentsTestRule(
+        MainActivity::class.java,
+        true,
+        false
+    )
+
+    @Test
+    fun login() {
+        val sut = activityRule.launchActivity(null)
+        sut.userUtils.createOrUpdateUser(
+            "test",
+            "test",
+            "http://10.0.2.2/nc",
+            "test",
+            null,
+            true,
+            "test",
+            null,
+            null,
+            null,
+            null
+        )
+            .subscribeOn(Schedulers.io())
+            .observeOn(AndroidSchedulers.mainThread())
+            .subscribe(
+                { userEntity: UserEntity? -> Log.i("test", "stored: " + userEntity.toString()) },
+                { throwable: Throwable? -> Log.e("test", "throwable") },
+                { Log.d("test", "complete") }
+            )
+
+        try {
+            Thread.sleep(2000)
+        } catch (e: InterruptedException) {
+            e.printStackTrace()
+        }
+
+        sut.runOnUiThread { sut.resetConversationsList() }
+
+        assertTrue(sut.userUtils.getIfUserWithUsernameAndServer("test", "http://10.0.2.2/nc"))
+
+        try {
+        } catch (e: InterruptedException) {
+            e.printStackTrace()
+        }
+    }
+}

+ 2 - 2
app/src/main/java/com/nextcloud/talk/utils/database/user/UserUtils.java

@@ -268,7 +268,7 @@ public class UserUtils {
         }
 
         return dataStore.upsert(user)
-                .toObservable()
-                .subscribeOn(Schedulers.io());
+            .toObservable()
+            .subscribeOn(Schedulers.io());
     }
 }