Cleanup testImplementation dependencies (#4790)

This commit is contained in:
Benoit Marty
2025-06-02 10:51:02 +02:00
committed by GitHub
parent 9d4602dae7
commit 0b5e816f0d
25 changed files with 409 additions and 93 deletions

View File

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

View File

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

View 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)
}

View File

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