From 411d97c235a35ec116c0d77e53812934e0aeb63a Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 29 Jul 2024 14:37:23 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20sharing=20button=20is=20disabled=20[WPB-?= =?UTF-8?q?9947]=20=F0=9F=8D=92=20(#3234)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Mohamad Jaara --- .../IsFileSharingEnabledViewModel.kt | 10 +- .../IsFileSharingEnabledViewModelTest.kt | 96 +++++++++++++++++++ 2 files changed, 102 insertions(+), 4 deletions(-) create mode 100644 app/src/test/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModelTest.kt diff --git a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModel.kt index 5c8d8a441fe..83094ccc0fa 100644 --- a/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModel.kt @@ -49,10 +49,12 @@ class IsFileSharingEnabledViewModelImpl @Inject constructor( } private fun getIsFileSharingEnabled() = viewModelScope.launch { - state = when (isFileSharingEnabledUseCase().state) { - FileSharingStatus.Value.Disabled -> false - FileSharingStatus.Value.EnabledAll, - is FileSharingStatus.Value.EnabledSome -> true + isFileSharingEnabledUseCase().state.let { + state = when (it) { + FileSharingStatus.Value.EnabledAll, + is FileSharingStatus.Value.EnabledSome -> true + FileSharingStatus.Value.Disabled -> false + } } } } diff --git a/app/src/test/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModelTest.kt new file mode 100644 index 00000000000..eb21f7612f5 --- /dev/null +++ b/app/src/test/kotlin/com/wire/android/ui/home/messagecomposer/attachments/IsFileSharingEnabledViewModelTest.kt @@ -0,0 +1,96 @@ +/* + * Wire + * Copyright (C) 2024 Wire Swiss GmbH + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ +package com.wire.android.ui.home.messagecomposer.attachments + +import com.wire.android.config.CoroutineTestExtension +import com.wire.kalium.logic.configuration.FileSharingStatus +import com.wire.kalium.logic.feature.user.IsFileSharingEnabledUseCase +import io.mockk.MockKAnnotations +import io.mockk.coVerify +import io.mockk.every +import io.mockk.impl.annotations.MockK +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.extension.ExtendWith + +@ExtendWith(CoroutineTestExtension::class) +class IsFileSharingEnabledViewModelTest { + + @Test + fun `given fileSharing is allowed, then state should be true`() { + val (arrangement, viewModel) = Arrangement().arrange { + withFileSharingStatus(FileSharingStatus.Value.EnabledAll) + } + + assertTrue(viewModel.isFileSharingEnabled()) + coVerify(exactly = 1) { + arrangement.isFileSharingEnabledUseCase() + } + } + + @Test + fun `given fileSharing is disabled, then state should be false`() { + val (arrangement, viewModel) = Arrangement().arrange { + withFileSharingStatus(FileSharingStatus.Value.Disabled) + } + + assertFalse(viewModel.isFileSharingEnabled()) + coVerify(exactly = 1) { + arrangement.isFileSharingEnabledUseCase() + } + } + + @Test + fun `given fileSharing is allowed for some, then state should be true`() { + val (arrangement, viewModel) = Arrangement().arrange { + withFileSharingStatus(FileSharingStatus.Value.EnabledSome(emptyList())) + } + + assertTrue(viewModel.isFileSharingEnabled()) + coVerify(exactly = 1) { + arrangement.isFileSharingEnabledUseCase() + } + } + + private class Arrangement { + + @MockK + lateinit var isFileSharingEnabledUseCase: IsFileSharingEnabledUseCase + + private lateinit var viewModel: IsFileSharingEnabledViewModel + + init { + MockKAnnotations.init(this, relaxUnitFun = true) + } + + fun withFileSharingStatus(result: FileSharingStatus.Value) = apply { + every { isFileSharingEnabledUseCase() } returns FileSharingStatus( + result, + true + ) + } + + fun arrange(block: Arrangement.() -> Unit) = apply(block).let { + viewModel = IsFileSharingEnabledViewModelImpl( + isFileSharingEnabledUseCase + ) + this to viewModel + } + } +}