Skip to content

Commit f2646b9

Browse files
authored
chore: Cell unit tests [WPB-15386] (#3979)
1 parent 798be72 commit f2646b9

File tree

6 files changed

+780
-2
lines changed

6 files changed

+780
-2
lines changed

features/cells/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ dependencies {
4545
testImplementation(libs.junit5.core)
4646
testImplementation(libs.coroutines.test)
4747
testImplementation(libs.mockk.core)
48+
testImplementation(libs.turbine)
4849
testRuntimeOnly(libs.junit5.engine)
4950
androidTestImplementation(libs.androidx.test.extJunit)
5051
androidTestImplementation(libs.androidx.espresso.core)

features/cells/src/main/java/com/wire/android/feature/cells/ui/CellViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ import com.wire.kalium.common.functional.onFailure
3636
import com.wire.kalium.common.functional.onSuccess
3737
import com.wire.kalium.logic.data.asset.KaliumFileSystem
3838
import dagger.hilt.android.lifecycle.HiltViewModel
39+
import kotlinx.coroutines.Dispatchers
3940
import kotlinx.coroutines.channels.BufferOverflow
4041
import kotlinx.coroutines.channels.Channel
4142
import kotlinx.coroutines.flow.MutableSharedFlow
4243
import kotlinx.coroutines.flow.MutableStateFlow
4344
import kotlinx.coroutines.flow.asSharedFlow
4445
import kotlinx.coroutines.flow.asStateFlow
46+
import kotlinx.coroutines.flow.flowOn
4547
import kotlinx.coroutines.flow.receiveAsFlow
4648
import kotlinx.coroutines.flow.update
4749
import kotlinx.coroutines.launch
@@ -77,7 +79,9 @@ class CellViewModel @Inject constructor(
7779
capacity = Channel.BUFFERED,
7880
onBufferOverflow = BufferOverflow.DROP_OLDEST
7981
)
80-
internal val actions = _actions.receiveAsFlow()
82+
internal val actions = _actions
83+
.receiveAsFlow()
84+
.flowOn(Dispatchers.Main.immediate)
8185

8286
// Download progress value for each file being downloaded.
8387
private val uploadProgress = mutableStateMapOf<String, Float>()

features/cells/src/main/java/com/wire/android/feature/cells/ui/publiclink/PublicLinkViewModel.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ import com.wire.kalium.cells.domain.usecase.publiclink.GetPublicLinkUseCase
3030
import com.wire.kalium.common.functional.onFailure
3131
import com.wire.kalium.common.functional.onSuccess
3232
import dagger.hilt.android.lifecycle.HiltViewModel
33+
import kotlinx.coroutines.Dispatchers
3334
import kotlinx.coroutines.channels.BufferOverflow
3435
import kotlinx.coroutines.channels.Channel
3536
import kotlinx.coroutines.flow.MutableStateFlow
3637
import kotlinx.coroutines.flow.asStateFlow
38+
import kotlinx.coroutines.flow.flowOn
3739
import kotlinx.coroutines.flow.receiveAsFlow
3840
import kotlinx.coroutines.flow.update
3941
import kotlinx.coroutines.launch
@@ -58,7 +60,9 @@ class PublicLinkViewModel @Inject constructor(
5860
onBufferOverflow = BufferOverflow.DROP_OLDEST
5961
)
6062

61-
internal val actions = _actions.receiveAsFlow()
63+
internal val actions = _actions
64+
.receiveAsFlow()
65+
.flowOn(Dispatchers.Main.immediate)
6266

6367
private var publicLink: PublicLink? = null
6468

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Wire
3+
* Copyright (C) 2025 Wire Swiss GmbH
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see http://www.gnu.org/licenses/.
17+
*/
18+
package com.wire.android.config
19+
20+
import io.mockk.mockkStatic
21+
import io.mockk.unmockkStatic
22+
import org.junit.jupiter.api.extension.AfterEachCallback
23+
import org.junit.jupiter.api.extension.BeforeEachCallback
24+
import org.junit.jupiter.api.extension.ExtensionContext
25+
26+
/**
27+
* This extension provides a way to mock navigation arguments getters.
28+
* It can be used to mock getting navigation arguments from savedStateHandle, like: savedStateHandle.navArgs()
29+
* or to get arguments from the specific Destination object, like: ExampleScreenDestination.argsFrom(savedStateHandle).
30+
*
31+
* Add this JUnit 5 extension to your test class using
32+
* @JvmField
33+
* @RegisterExtension
34+
* val navigationTestExtension = NavigationTestExtension()
35+
*
36+
* or:
37+
*
38+
* Annotating the class with
39+
* @ExtendWith(NavigationTestExtension::class)
40+
*/
41+
class NavigationTestExtension : BeforeEachCallback, AfterEachCallback {
42+
override fun beforeEach(context: ExtensionContext?) {
43+
mockkStatic("com.wire.android.feature.cells.ui.NavArgsGettersKt")
44+
}
45+
46+
override fun afterEach(context: ExtensionContext?) {
47+
unmockkStatic("com.wire.android.feature.cells.ui.NavArgsGettersKt")
48+
}
49+
}

0 commit comments

Comments
 (0)