Skip to content

Commit

Permalink
fix: sharing button is disabled [WPB-9947] 🍒 (#3234)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohamad Jaara <[email protected]>
  • Loading branch information
github-actions[bot] and MohamadJaara authored Jul 29, 2024
1 parent c63fbc7 commit 411d97c
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}

0 comments on commit 411d97c

Please sign in to comment.