Cleanup testImplementation dependencies (#4790)
This commit is contained in:
@@ -31,6 +31,7 @@ dependencies {
|
||||
testImplementation(projects.libraries.matrix.test)
|
||||
testImplementation(libs.test.junit)
|
||||
testImplementation(libs.coroutines.test)
|
||||
testImplementation(libs.molecule.runtime)
|
||||
testImplementation(libs.test.turbine)
|
||||
testImplementation(libs.test.truth)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.indicator.impl
|
||||
|
||||
import app.cash.molecule.RecompositionMode
|
||||
import app.cash.molecule.moleculeFlow
|
||||
import app.cash.turbine.test
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.matrix.api.encryption.BackupState
|
||||
import io.element.android.libraries.matrix.api.encryption.RecoveryState
|
||||
import io.element.android.libraries.matrix.test.encryption.FakeEncryptionService
|
||||
import io.element.android.libraries.matrix.test.verification.FakeSessionVerificationService
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Test
|
||||
|
||||
class DefaultIndicatorServiceTest {
|
||||
@Test
|
||||
fun `test - showRoomListTopBarIndicator`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val sessionVerificationService = FakeSessionVerificationService()
|
||||
val sut = DefaultIndicatorService(
|
||||
sessionVerificationService = sessionVerificationService,
|
||||
encryptionService = encryptionService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
sut.showRoomListTopBarIndicator().value
|
||||
}.test {
|
||||
assertThat(awaitItem()).isTrue()
|
||||
sessionVerificationService.emitNeedsSessionVerification(false)
|
||||
encryptionService.emitBackupState(BackupState.ENABLED)
|
||||
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
|
||||
assertThat(awaitItem()).isFalse()
|
||||
sessionVerificationService.emitNeedsSessionVerification(true)
|
||||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - showSettingChatBackupIndicator is true when BackupState is UNKNOWN`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val sessionVerificationService = FakeSessionVerificationService()
|
||||
val sut = DefaultIndicatorService(
|
||||
sessionVerificationService = sessionVerificationService,
|
||||
encryptionService = encryptionService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
sut.showSettingChatBackupIndicator().value
|
||||
}.test {
|
||||
assertThat(awaitItem()).isTrue()
|
||||
encryptionService.emitBackupState(BackupState.ENABLED)
|
||||
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
|
||||
assertThat(awaitItem()).isFalse()
|
||||
encryptionService.emitBackupState(BackupState.UNKNOWN)
|
||||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - showSettingChatBackupIndicator is true when recoveryState is DISABLED`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val sessionVerificationService = FakeSessionVerificationService()
|
||||
val sut = DefaultIndicatorService(
|
||||
sessionVerificationService = sessionVerificationService,
|
||||
encryptionService = encryptionService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
sut.showSettingChatBackupIndicator().value
|
||||
}.test {
|
||||
assertThat(awaitItem()).isTrue()
|
||||
encryptionService.emitBackupState(BackupState.ENABLED)
|
||||
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
|
||||
assertThat(awaitItem()).isFalse()
|
||||
encryptionService.emitRecoveryState(RecoveryState.DISABLED)
|
||||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test - showSettingChatBackupIndicator is true when recoveryState is INCOMPLETE`() = runTest {
|
||||
val encryptionService = FakeEncryptionService()
|
||||
val sessionVerificationService = FakeSessionVerificationService()
|
||||
val sut = DefaultIndicatorService(
|
||||
sessionVerificationService = sessionVerificationService,
|
||||
encryptionService = encryptionService,
|
||||
)
|
||||
moleculeFlow(RecompositionMode.Immediate) {
|
||||
sut.showSettingChatBackupIndicator().value
|
||||
}.test {
|
||||
assertThat(awaitItem()).isTrue()
|
||||
encryptionService.emitBackupState(BackupState.ENABLED)
|
||||
encryptionService.emitRecoveryState(RecoveryState.ENABLED)
|
||||
assertThat(awaitItem()).isFalse()
|
||||
encryptionService.emitRecoveryState(RecoveryState.INCOMPLETE)
|
||||
assertThat(awaitItem()).isTrue()
|
||||
}
|
||||
}
|
||||
}
|
||||
19
libraries/indicator/test/build.gradle.kts
Normal file
19
libraries/indicator/test/build.gradle.kts
Normal file
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("io.element.android-compose-library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.libraries.indicator.test"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(projects.libraries.matrix.api)
|
||||
api(projects.libraries.indicator.api)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.indicator.test
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.MutableState
|
||||
import androidx.compose.runtime.State
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import io.element.android.libraries.indicator.api.IndicatorService
|
||||
|
||||
class FakeIndicatorService : IndicatorService {
|
||||
private val showRoomListTopBarIndicatorResult: MutableState<Boolean> = mutableStateOf(false)
|
||||
private val showSettingChatBackupIndicatorResult: MutableState<Boolean> = mutableStateOf(false)
|
||||
|
||||
fun setShowRoomListTopBarIndicator(value: Boolean) {
|
||||
showRoomListTopBarIndicatorResult.value = value
|
||||
}
|
||||
|
||||
fun setShowSettingChatBackupIndicator(value: Boolean) {
|
||||
showSettingChatBackupIndicatorResult.value = value
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun showRoomListTopBarIndicator(): State<Boolean> {
|
||||
return showRoomListTopBarIndicatorResult
|
||||
}
|
||||
|
||||
@Composable
|
||||
override fun showSettingChatBackupIndicator(): State<Boolean> {
|
||||
return showSettingChatBackupIndicatorResult
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user