Skip to content

Commit

Permalink
fix: first Screenshot taken in the app is sometimes black (#2244)
Browse files Browse the repository at this point in the history
* fix: first Screenshot taken in the app is sometimes black

* edit tests

---------

Co-authored-by: Oussama Hassine <[email protected]>
  • Loading branch information
2 people authored and augustocdias committed Dec 5, 2023
1 parent db9b91a commit 03fa181
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ internal class ObserveScreenshotCensoringConfigUseCaseImpl(
override suspend fun invoke(): Flow<ObserveScreenshotCensoringConfigResult> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -56,7 +57,7 @@ class ObserveScreenshotCensoringConfigUseCaseTest {

result.test {
val item = awaitItem()
assertTrue { item == expectedResult }
assertEquals(expectedResult, item)

verify(arrangement.userConfigRepository)
.function(arrangement.userConfigRepository::observeScreenshotCensoringConfig)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 03fa181

Please sign in to comment.