mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-10 06:14:10 +01:00
Add sample unit and connected test for shared items activity
Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
83871ae434
commit
11030e27f4
@ -152,6 +152,7 @@ ext {
|
||||
workVersion = "2.7.1"
|
||||
markwonVersion = "4.6.2"
|
||||
espressoVersion = "3.4.0"
|
||||
mockkVersion = "1.13.2"
|
||||
}
|
||||
|
||||
def webRtcVersion = "96.4664.0"
|
||||
@ -294,8 +295,12 @@ dependencies {
|
||||
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
testImplementation 'org.mockito:mockito-core:4.8.1'
|
||||
testImplementation "io.mockk:mockk:$mockkVersion"
|
||||
testImplementation "io.mockk:mockk-android:$mockkVersion"
|
||||
|
||||
|
||||
androidTestImplementation "androidx.test:core:1.4.0"
|
||||
androidTestImplementation "androidx.test:core-ktx:1.4.0"
|
||||
|
||||
// Espresso core
|
||||
androidTestImplementation ("androidx.test.espresso:espresso-core:$espressoVersion", {
|
||||
|
@ -0,0 +1,33 @@
|
||||
package com.nextcloud.talk.shareditems.activities
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import androidx.test.core.app.launchActivity
|
||||
import androidx.test.espresso.Espresso
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import com.nextcloud.talk.data.user.model.User
|
||||
import com.nextcloud.talk.utils.bundle.BundleKeys
|
||||
import org.junit.Test
|
||||
|
||||
import com.nextcloud.talk.R
|
||||
|
||||
class SharedItemsActivityTest {
|
||||
|
||||
@Test
|
||||
fun launch() {
|
||||
val intent = Intent(ApplicationProvider.getApplicationContext(), SharedItemsActivity::class.java).apply {
|
||||
putExtras(
|
||||
bundleOf(
|
||||
BundleKeys.KEY_ROOM_TOKEN to "",
|
||||
BundleKeys.KEY_CONVERSATION_NAME to "",
|
||||
BundleKeys.KEY_USER_ENTITY to User(1L, ", ", ", ", "", token = "")
|
||||
)
|
||||
)
|
||||
}
|
||||
launchActivity<SharedItemsActivity>(intent).use { scenario ->
|
||||
Espresso.onView(withId(R.id.emptyContainer)).check { view, _ -> view.isVisible }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package com.nextcloud.talk.shareditems.repositories
|
||||
|
||||
import android.text.TextUtils
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
import com.nextcloud.talk.models.json.chat.ChatShareOCS
|
||||
import com.nextcloud.talk.models.json.chat.ChatShareOverall
|
||||
import com.nextcloud.talk.shareditems.model.SharedItemType
|
||||
import com.nextcloud.talk.shareditems.model.SharedItems
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.mockkStatic
|
||||
import io.mockk.unmockkStatic
|
||||
import io.reactivex.Observable
|
||||
import org.junit.After
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import retrofit2.Response
|
||||
|
||||
class SharedItemsRepositoryImplTest {
|
||||
|
||||
@Before
|
||||
fun setup() {
|
||||
mockkStatic(TextUtils::class)
|
||||
every { TextUtils.isEmpty(any()) } returns false
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
unmockkStatic(TextUtils::class)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testMedia_empty() {
|
||||
// arrange
|
||||
val ncApi: NcApi = mockk()
|
||||
val sut: SharedItemsRepository = SharedItemsRepositoryImpl(ncApi)
|
||||
|
||||
val result = ChatShareOverall(ChatShareOCS(HashMap()))
|
||||
|
||||
every { ncApi.getSharedItems(any(), any(), any(), any(), any()) } returns Observable.just(
|
||||
Response.success(
|
||||
result
|
||||
)
|
||||
)
|
||||
|
||||
// act
|
||||
val observable: Observable<SharedItems>? =
|
||||
sut.media(SharedItemsRepository.Parameters("", "", "", ""), SharedItemType.MEDIA)
|
||||
|
||||
// assert
|
||||
Assert.assertNotNull("Shared items result is null", observable)
|
||||
|
||||
val sharedItems = observable!!.blockingFirst()
|
||||
Assert.assertTrue("Shared items not empty", sharedItems.items.isEmpty())
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user