Skip to content

Commit

Permalink
Merge branch 'release/candidate' into fix/shields_not_shown_in_group_…
Browse files Browse the repository at this point in the history
…participants_list-cherry-pick
  • Loading branch information
borichellow committed Aug 5, 2024
2 parents 7fee390 + d746711 commit 96a9bd8
Show file tree
Hide file tree
Showing 22 changed files with 338 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* 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.userprofile.other

import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithContentDescription
import com.wire.android.ui.WireTestTheme
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.userprofile.other.OtherUserStubs.provideState
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import org.junit.Rule
import org.junit.Test

class OtherUserProfileGroupTest {
@get:Rule
val composeTestRule by lazy { createComposeRule() }

@Test
fun givenARoleSelectionComponentIsShow_ShouldNotAllowModificationForTempUsers() = runTest {
composeTestRule.setContent {
WireTestTheme {
OtherUserProfileGroup(
provideState(withExpireAt = Instant.DISTANT_FUTURE.toEpochMilliseconds()),
onRemoveFromConversation = {},
openChangeRoleBottomSheet = {},
)
}
}

composeTestRule.onNodeWithContentDescription("Edit").assertDoesNotExist()
}

@Test
fun givenARoleSelectionComponentIsShow_ShouldNotAllowModificationForUsersWithoutMetadata() = runTest {
composeTestRule.setContent {
WireTestTheme {
OtherUserProfileGroup(
provideState(withUserName = "", withFullName = ""),
onRemoveFromConversation = {},
openChangeRoleBottomSheet = {},
)
}
}

composeTestRule.onNodeWithContentDescription("Edit").assertDoesNotExist()
}

@Test
fun givenARoleSelectionComponentIsShow_ShouldNotAllowModificationForFederatedUsers() = runTest {
composeTestRule.setContent {
WireTestTheme {
OtherUserProfileGroup(
provideState(withMembership = Membership.Federated),
onRemoveFromConversation = {},
openChangeRoleBottomSheet = {},
)
}
}

composeTestRule.onNodeWithContentDescription("Edit").assertDoesNotExist()
}

@Test
fun givenARoleSelectionComponentIsShow_ShouldNotAllowModificationForServices() = runTest {
composeTestRule.setContent {
WireTestTheme {
OtherUserProfileGroup(
provideState(withMembership = Membership.Service),
onRemoveFromConversation = {},
openChangeRoleBottomSheet = {},
)
}
}

composeTestRule.onNodeWithContentDescription("Edit").assertDoesNotExist()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* 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.userprofile.other

import androidx.compose.material3.MaterialTheme
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import com.wire.android.ui.WireTestTheme
import com.wire.android.ui.connection.CONNECTION_ACTION_BUTTONS_TEST_TAG
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.userprofile.other.OtherUserStubs.provideState
import kotlinx.coroutines.test.runTest
import kotlinx.datetime.Instant
import org.junit.Rule
import org.junit.Test

class OtherUserProfileScreenTest {
@get:Rule
val composeTestRule by lazy { createComposeRule() }

@Test
fun givenOtherUserProfileFooter_ShouldNotShowConnectButtonForTempUsers() = runTest {
composeTestRule.setContent {
WireTestTheme {
ContentFooter(
state = provideState(withExpireAt = Instant.DISTANT_FUTURE.toEpochMilliseconds()),
maxBarElevation = MaterialTheme.wireDimensions.topBarShadowElevation
)
}
}

composeTestRule.onNodeWithTag(CONNECTION_ACTION_BUTTONS_TEST_TAG).assertDoesNotExist()
}

@Test
fun givenOtherUserProfileFooter_ShouldNotShowConnectButtonForUsersWithoutMetadata() = runTest {
composeTestRule.setContent {
WireTestTheme {
ContentFooter(
state = provideState(withUserName = "", withFullName = ""),
maxBarElevation = MaterialTheme.wireDimensions.topBarShadowElevation
)
}
}

composeTestRule.onNodeWithTag(CONNECTION_ACTION_BUTTONS_TEST_TAG).assertDoesNotExist()
}

@Test
fun givenOtherUserProfileFooter_ShouldNotShowConnectButtonForServices() = runTest {
composeTestRule.setContent {
WireTestTheme {
ContentFooter(
state = provideState(withMembership = Membership.Service),
maxBarElevation = MaterialTheme.wireDimensions.topBarShadowElevation
)
}
}

composeTestRule.onNodeWithTag(CONNECTION_ACTION_BUTTONS_TEST_TAG).assertDoesNotExist()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.userprofile.other

import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.kalium.logic.data.conversation.Conversation.Member
import com.wire.kalium.logic.data.id.ConversationId
import com.wire.kalium.logic.data.user.UserId
import kotlinx.datetime.Instant

object OtherUserStubs {
private val baseState = OtherUserProfileState(
userId = UserId("some_user", "domain.com"),
fullName = "name",
userName = "username",
teamName = "team",
email = "email",
groupState = OtherUserProfileGroupState(
groupName = "group name",
role = Member.Role.Member,
isSelfAdmin = true,
conversationId = ConversationId("some_user", "domain.com")
)
)

fun provideState(
withFullName: String = "name",
withUserName: String = "username",
withExpireAt: Long? = null,
withMembership: Membership = Membership.Standard
): OtherUserProfileState {
return baseState.copy(
fullName = withFullName,
userName = withUserName,
expiresAt = withExpireAt?.let { Instant.fromEpochMilliseconds(it) },
membership = withMembership
)
}
}
4 changes: 2 additions & 2 deletions app/src/main/kotlin/com/wire/android/mapper/ContactMapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import com.wire.android.model.ImageAsset
import com.wire.android.model.UserAvatarData
import com.wire.android.ui.home.conversationslist.model.Membership
import com.wire.android.ui.home.newconversation.model.Contact
import com.wire.android.ui.userprofile.common.UsernameMapper.mapUserLabel
import com.wire.android.ui.userprofile.common.UsernameMapper
import com.wire.android.util.EMPTY
import com.wire.android.util.ui.WireSessionImageLoader
import com.wire.kalium.logic.data.publicuser.model.UserSearchDetails
Expand All @@ -44,7 +44,7 @@ class ContactMapper
id = id.value,
domain = id.domain,
name = name.orEmpty(),
label = mapUserLabel(otherUser),
label = UsernameMapper.fromOtherUser(otherUser),
avatarData = UserAvatarData(
asset = previewPicture?.let { ImageAsset.UserAvatarAsset(wireSessionImageLoader, it) },
connectionState = connectionStatus
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class UIParticipantMapper @Inject constructor(
isMLSVerified = isMLSVerified,
supportedProtocolList = supportedProtocols.orEmpty().toList(),
isUnderLegalHold = isUnderLegalHold,
expiresAt = user.expiresAt
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.wire.kalium.logic.data.call.CallStatus
import com.wire.kalium.logic.data.sync.SyncState
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import dagger.Lazy
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
Expand All @@ -48,8 +49,7 @@ import javax.inject.Inject
@HiltViewModel
class CommonTopAppBarViewModel @Inject constructor(
private val currentScreenManager: CurrentScreenManager,
@KaliumCoreLogic
private val coreLogic: CoreLogic,
@KaliumCoreLogic private val coreLogic: Lazy<CoreLogic>,
) : ViewModel() {

var state by mutableStateOf(CommonTopAppBarState())
Expand All @@ -59,7 +59,7 @@ class CommonTopAppBarViewModel @Inject constructor(
currentScreenManager.observeCurrentScreen(viewModelScope)

private fun connectivityFlow(userId: UserId): Flow<Connectivity> =
coreLogic.sessionScope(userId) {
coreLogic.get().sessionScope(userId) {
observeSyncState().map {
when (it) {
is SyncState.Failed, SyncState.Waiting -> Connectivity.WAITING_CONNECTION
Expand All @@ -71,7 +71,7 @@ class CommonTopAppBarViewModel @Inject constructor(

@VisibleForTesting
internal suspend fun activeCallFlow(userId: UserId): Flow<Call?> =
coreLogic.sessionScope(userId) {
coreLogic.get().sessionScope(userId) {
combine(
calls.establishedCall(),
calls.getIncomingCalls(),
Expand All @@ -85,7 +85,7 @@ class CommonTopAppBarViewModel @Inject constructor(

init {
viewModelScope.launch {
coreLogic.globalScope {
coreLogic.get().globalScope {
session.currentSessionFlow().flatMapLatest {
when (it) {
is CurrentSessionResult.Failure.Generic,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ fun WireTopAppBarTitle(
// This workaround is based on this: https://stackoverflow.com/a/69947555, but instead of using SubcomposeLayout, we just measure text.
BoxWithConstraints(
modifier = modifier
.padding(horizontal = dimensions().spacing6x)
) {
val textMeasurer = rememberTextMeasurer()
val textLayoutResult: TextLayoutResult = textMeasurer.measure(
Expand All @@ -148,7 +149,6 @@ fun WireTopAppBarTitle(
}
Text(
modifier = Modifier
.padding(horizontal = dimensions().spacing6x)
.width(width),
text = title,
style = style,
Expand All @@ -174,7 +174,7 @@ fun PreviewWireCenterAlignedTopAppBarWithDefaultTitle() = WireTheme {
fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTitle() = WireTheme {
Box(modifier = Modifier.width(400.dp)) {
WireCenterAlignedTopAppBar(
title = "This is title is very long this_is_a_very_long_word",
title = "This title is a quite long title another_line",
titleStyle = MaterialTheme.wireTypography.title01
)
}
Expand All @@ -185,7 +185,7 @@ fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTitle() = WireTheme {
fun PreviewWireCenterAlignedTopAppBarWithDefaultTwoLinesTooLongTitle() = WireTheme {
Box(modifier = Modifier.width(400.dp)) {
WireCenterAlignedTopAppBar(
title = "This is title is even longer than previous one this_is_a_very_long_word",
title = "This title is even longer than one before another_line",
titleStyle = MaterialTheme.wireTypography.title01
)
}
Expand Down
Loading

0 comments on commit 96a9bd8

Please sign in to comment.