From 6ca579ba38570896e1e1697d462fd20e85fb70d1 Mon Sep 17 00:00:00 2001 From: Mohamad Jaara Date: Thu, 23 Nov 2023 01:51:35 +0100 Subject: [PATCH] fix: first Screenshot taken in the app is sometimes black (#2244) * fix: first Screenshot taken in the app is sometimes black * edit tests --------- Co-authored-by: Oussama Hassine --- ...ObserveScreenshotCensoringConfigUseCase.kt | 4 ++-- ...rveScreenshotCensoringConfigUseCaseTest.kt | 19 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/screenshotCensoring/ObserveScreenshotCensoringConfigUseCase.kt b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/screenshotCensoring/ObserveScreenshotCensoringConfigUseCase.kt index d305617e0e4..7ae1fe9a6dc 100644 --- a/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/screenshotCensoring/ObserveScreenshotCensoringConfigUseCase.kt +++ b/logic/src/commonMain/kotlin/com/wire/kalium/logic/feature/user/screenshotCensoring/ObserveScreenshotCensoringConfigUseCase.kt @@ -39,10 +39,10 @@ internal class ObserveScreenshotCensoringConfigUseCaseImpl( override suspend fun invoke(): Flow { return combine( userConfigRepository.observeScreenshotCensoringConfig() - .mapToRightOr(true), // for safety it's set to true if we can't determine it + .mapToRightOr(false), userConfigRepository.observeTeamSettingsSelfDeletingStatus() .mapRight { it.enforcedSelfDeletionTimer is TeamSelfDeleteTimer.Enforced } - .mapToRightOr(true), // for safety it's set to true if we can't determine it + .mapToRightOr(false) ) { screenshotCensoringEnabled, teamSelfDeletingEnforced -> when { teamSelfDeletingEnforced -> ObserveScreenshotCensoringConfigResult.Enabled.EnforcedByTeamSelfDeletingSettings diff --git a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/screeenshotCensoring/ObserveScreenshotCensoringConfigUseCaseTest.kt b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/screeenshotCensoring/ObserveScreenshotCensoringConfigUseCaseTest.kt index eaa3f9ff87f..cd29bf30cbc 100644 --- a/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/screeenshotCensoring/ObserveScreenshotCensoringConfigUseCaseTest.kt +++ b/logic/src/commonTest/kotlin/com/wire/kalium/logic/feature/user/screeenshotCensoring/ObserveScreenshotCensoringConfigUseCaseTest.kt @@ -36,6 +36,7 @@ import io.mockative.verify import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertTrue import kotlin.time.DurationUnit import kotlin.time.toDuration @@ -56,7 +57,7 @@ class ObserveScreenshotCensoringConfigUseCaseTest { result.test { val item = awaitItem() - assertTrue { item == expectedResult } + assertEquals(expectedResult, item) verify(arrangement.userConfigRepository) .function(arrangement.userConfigRepository::observeScreenshotCensoringConfig) @@ -89,11 +90,11 @@ class ObserveScreenshotCensoringConfigUseCaseTest { ) @Test - fun givenSSCensoringDisabledAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnEnabledEnforcedByTeamSelfDeletingSettings() = + fun givenSSCensoringDisabledAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnDisabled() = runTestWithParametersAndExpectedResult( observeScreenshotCensoringConfigResult = Either.Right(false), observeTeamSelfDeletingStatusResult = Either.Left(StorageFailure.DataNotFound), - expectedResult = ObserveScreenshotCensoringConfigResult.Enabled.EnforcedByTeamSelfDeletingSettings + expectedResult = ObserveScreenshotCensoringConfigResult.Disabled ) @Test @@ -113,19 +114,19 @@ class ObserveScreenshotCensoringConfigUseCaseTest { ) @Test - fun givenSSCensoringEnabledAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnEnabledEnforcedByTeamSelfDeletingSettings() = + fun givenSSCensoringEnabledAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnEnabledChosenByUser() = runTestWithParametersAndExpectedResult( observeScreenshotCensoringConfigResult = Either.Right(true), observeTeamSelfDeletingStatusResult = Either.Left(StorageFailure.DataNotFound), - expectedResult = ObserveScreenshotCensoringConfigResult.Enabled.EnforcedByTeamSelfDeletingSettings + expectedResult = ObserveScreenshotCensoringConfigResult.Enabled.ChosenByUser ) @Test - fun givenSSCensoringFailureAndTeamSelfDeletingNotEnforced_whenInvoking_thenShouldReturnEnabledChosenByUser() = + fun givenSSCensoringFailureAndTeamSelfDeletingNotEnforced_whenInvoking_thenShouldReturnDisabled() = runTestWithParametersAndExpectedResult( observeScreenshotCensoringConfigResult = Either.Left(StorageFailure.DataNotFound), observeTeamSelfDeletingStatusResult = Either.Right(TeamSelfDeleteTimer.Enabled), - expectedResult = ObserveScreenshotCensoringConfigResult.Enabled.ChosenByUser + expectedResult = ObserveScreenshotCensoringConfigResult.Disabled ) @Test @@ -137,11 +138,11 @@ class ObserveScreenshotCensoringConfigUseCaseTest { ) @Test - fun givenSSCensoringFailureAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnEnabledEnforcedByTeamSelfDeletingSettings() = + fun givenSSCensoringFailureAndTeamSelfDeletingFailure_whenInvoking_thenShouldReturnDisabled() = runTestWithParametersAndExpectedResult( observeScreenshotCensoringConfigResult = Either.Left(StorageFailure.DataNotFound), observeTeamSelfDeletingStatusResult = Either.Left(StorageFailure.DataNotFound), - expectedResult = ObserveScreenshotCensoringConfigResult.Enabled.EnforcedByTeamSelfDeletingSettings + expectedResult = ObserveScreenshotCensoringConfigResult.Disabled ) private class Arrangement {