Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-zagorski committed Dec 3, 2024
1 parent 8470739 commit 44db85f
Showing 1 changed file with 138 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,47 +17,160 @@
*/
package com.wire.android.ui.common.bottomsheet.conversation

import com.wire.android.framework.TestUser
import com.wire.android.ui.home.conversations.details.GroupConversationDetailsViewModelTest.Companion.testGroup
import com.wire.android.ui.home.conversationslist.model.BlockingState
import com.wire.kalium.logic.data.conversation.Conversation
import com.wire.kalium.logic.data.id.TeamId
import kotlinx.coroutines.test.runTest
import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test

class ConversationSheetContentTest {

@Test
fun givenTitleIsEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsTrue() = runTest {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))

val givenConversationSheetContent = ConversationSheetContent(
title = "",
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, details.isSelfUserCreator),
selfRole = Conversation.Member.Role.Member,
isTeamConversation = details.conversation.isTeamGroup(),
isArchived = false,
protocol = Conversation.ProtocolInfo.Proteus,
mlsVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
proteusVerificationStatus = Conversation.VerificationStatus.NOT_VERIFIED,
isUnderLegalHold = false,
isFavorite = false
)
val givenConversationSheetContent = createGroupSheetContent("")
val givenParticipantsCount = 1

assertEquals(true, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsEmptyAndTheGroupSizeIsGtOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))
val givenConversationSheetContent = createGroupSheetContent("")
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsNotEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
val givenConversationSheetContent = createGroupSheetContent("notEmpty")
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenPrivateConversationWithoutBlockedAndNotDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = false)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertTrue(canBlockUser)
}

@Test
fun givenGroupConversation_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent = createGroupSheetContent("")

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithBlockedAndNotDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

val givenConversationSheetContent = ConversationSheetContent(
title = "",
// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithoutBlockedAndDeletedUser_whenCanDeleteUserIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = true)

// when
val canBlockUser = conversationSheetContent.canBlockUser()

// then
assertFalse(canBlockUser)
}

@Test
fun givenPrivateConversationWithoutBlockedAndNotDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.NOT_BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertTrue(canEditNotifications)
}

@Test
fun givenGroupConversation_whenCanEditNotificationsIsInvoked_thenReturnsTrue() = runTest {
// given
val conversationSheetContent = createGroupSheetContent("")

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertTrue(canEditNotifications)
}

@Test
fun givenPrivateConversationWithBlockedAndNotDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertFalse(canEditNotifications)
}

@Test
fun givenPrivateConversationWithoutBlockedAndDeletedUser_whenCanEditNotificationsIsInvoked_thenReturnsFalse() = runTest {
// given
val conversationSheetContent =
createPrivateSheetContent(blockingState = BlockingState.BLOCKED, isUserDeleted = false)

// when
val canEditNotifications = conversationSheetContent.canEditNotifications()

// then
assertFalse(canEditNotifications)
}

private fun createPrivateSheetContent(
blockingState: BlockingState,
isUserDeleted: Boolean
): ConversationSheetContent {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))
return ConversationSheetContent(
title = "notEmpty",
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, details.isSelfUserCreator),
conversationTypeDetail = ConversationTypeDetail.Private(
avatarAsset = null,
userId = TestUser.USER_ID,
blockingState = blockingState,
isUserDeleted = isUserDeleted
),
selfRole = Conversation.Member.Role.Member,
isTeamConversation = details.conversation.isTeamGroup(),
isArchived = false,
Expand All @@ -67,17 +180,15 @@ class ConversationSheetContentTest {
isUnderLegalHold = false,
isFavorite = false
)
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}

@Test
fun givenTitleIsNotEmptyAndTheGroupSizeIsOne_whenCallingIsTheGroupAbandoned_returnsFalse() = runTest {
private fun createGroupSheetContent(
title: String
): ConversationSheetContent {
val details = testGroup.copy(conversation = testGroup.conversation.copy(teamId = TeamId("team_id")))

val givenConversationSheetContent = ConversationSheetContent(
title = "notEmpty",
return ConversationSheetContent(
title = title,
conversationId = details.conversation.id,
mutingConversationState = details.conversation.mutedStatus,
conversationTypeDetail = ConversationTypeDetail.Group(details.conversation.id, details.isSelfUserCreator),
Expand All @@ -90,8 +201,5 @@ class ConversationSheetContentTest {
isUnderLegalHold = false,
isFavorite = false
)
val givenParticipantsCount = 3

assertEquals(false, givenConversationSheetContent.isAbandonedOneOnOneConversation(givenParticipantsCount))
}
}

0 comments on commit 44db85f

Please sign in to comment.