Skip to content

Commit

Permalink
Merge branch 'release/0.6.3' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed Sep 19, 2024
2 parents cfc0fc9 + 7eac45e commit cec945c
Show file tree
Hide file tree
Showing 96 changed files with 2,597 additions and 369 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Changes in Element X v0.6.2 (2024-09-17)
========================================

### ✨ Features
* Account deactivation. by @bmarty in https://github.com/element-hq/element-x-android/pull/3479

Changes in Element X v0.6.1 (2024-09-17)
========================================

Expand Down
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/40006030.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Element X is the new generation of Element for professional and personal use on mobile. It’s the fastest Matrix client with a seamless & intuitive user interface.
Full changelog: https://github.com/element-hq/element-x-android/releases
1 change: 1 addition & 0 deletions features/deactivation/impl/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ dependencies {
implementation(projects.libraries.architecture)
implementation(projects.libraries.matrix.api)
implementation(projects.libraries.designsystem)
implementation(projects.libraries.testtags)
implementation(projects.libraries.uiStrings)
api(projects.features.deactivation.api)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ import io.element.android.libraries.designsystem.theme.components.Text
import io.element.android.libraries.designsystem.theme.components.TopAppBar
import io.element.android.libraries.designsystem.theme.components.autofill
import io.element.android.libraries.designsystem.theme.components.onTabOrEnterKeyFocusNext
import io.element.android.libraries.testtags.TestTags
import io.element.android.libraries.testtags.testTag
import io.element.android.libraries.ui.strings.CommonStrings
import kotlinx.collections.immutable.persistentListOf

Expand Down Expand Up @@ -277,6 +279,7 @@ private fun Content(
.padding(top = 8.dp)
.fillMaxWidth()
.onTabOrEnterKeyFocusNext(focusManager)
.testTag(TestTags.loginPassword)
.autofill(
autofillTypes = listOf(AutofillType.Password),
onFill = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,26 @@ package io.element.android.features.logout.impl
import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import io.element.android.features.deactivation.impl.R
import io.element.android.libraries.architecture.AsyncAction
import io.element.android.libraries.matrix.test.AN_EXCEPTION
import io.element.android.libraries.matrix.test.A_PASSWORD
import io.element.android.libraries.testtags.TestTags
import io.element.android.libraries.ui.strings.CommonStrings
import io.element.android.tests.testutils.EnsureNeverCalled
import io.element.android.tests.testutils.EventsRecorder
import io.element.android.tests.testutils.clickOn
import io.element.android.tests.testutils.ensureCalledOnce
import io.element.android.tests.testutils.pressBack
import io.element.android.tests.testutils.pressTag
import org.junit.Rule
import org.junit.Test
import org.junit.rules.TestRule
import org.junit.runner.RunWith
import org.robolectric.annotation.Config

@RunWith(AndroidJUnit4::class)
class AccountDeactivationViewTest {
Expand All @@ -36,7 +47,96 @@ class AccountDeactivationViewTest {
}
}

// TODO Add more tests
@Config(qualifiers = "h1024dp")
@Test
fun `clicking on Deactivate emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
deactivateFormState = aDeactivateFormState(
password = A_PASSWORD,
),
eventSink = eventsRecorder,
),
)
rule.clickOn(CommonStrings.action_deactivate)
eventsRecorder.assertSingle(AccountDeactivationEvents.DeactivateAccount(false))
}

@Test
fun `clicking on Deactivate on the confirmation dialog emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
deactivateFormState = aDeactivateFormState(
password = A_PASSWORD,
),
accountDeactivationAction = AsyncAction.Confirming,
eventSink = eventsRecorder,
),
)
rule.pressTag(TestTags.dialogPositive.value)
eventsRecorder.assertSingle(AccountDeactivationEvents.DeactivateAccount(false))
}

@Test
fun `clicking on retry on the confirmation dialog emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
deactivateFormState = aDeactivateFormState(
password = A_PASSWORD,
),
accountDeactivationAction = AsyncAction.Failure(AN_EXCEPTION),
eventSink = eventsRecorder,
),
)
rule.clickOn(CommonStrings.action_retry)
eventsRecorder.assertSingle(AccountDeactivationEvents.DeactivateAccount(true))
}

@Test
fun `switching on the erase all switch emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
eventSink = eventsRecorder,
),
)
rule.clickOn(R.string.screen_deactivate_account_delete_all_messages)
eventsRecorder.assertSingle(AccountDeactivationEvents.SetEraseData(true))
}

@Test
fun `switching off the erase all switch emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
deactivateFormState = aDeactivateFormState(
eraseData = true,
),
eventSink = eventsRecorder,
),
)
rule.clickOn(R.string.screen_deactivate_account_delete_all_messages)
eventsRecorder.assertSingle(AccountDeactivationEvents.SetEraseData(false))
}

@Config(qualifiers = "h1024dp")
@Test
fun `typing text in the password field emits the expected Event`() {
val eventsRecorder = EventsRecorder<AccountDeactivationEvents>()
rule.setAccountDeactivationView(
state = anAccountDeactivationState(
deactivateFormState = aDeactivateFormState(
password = A_PASSWORD,
),
eventSink = eventsRecorder,
),
)
rule.onNodeWithTag(TestTags.loginPassword.value).performTextInput("A")
eventsRecorder.assertSingle(AccountDeactivationEvents.SetPassword("A$A_PASSWORD"))
}
}

private fun <R : TestRule> AndroidComposeTestRule<R, ComponentActivity>.setAccountDeactivationView(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,8 @@ private fun VerifiedUserSendFailureView(
fun VerifiedUserSendFailure.headline(): String {
return when (this) {
is None -> ""
is UnsignedDevice -> stringResource(CommonStrings.screen_timeline_item_menu_send_failure_unsigned_device, userDisplayName)
is UnsignedDevice.FromOther -> stringResource(CommonStrings.screen_timeline_item_menu_send_failure_unsigned_device, userDisplayName)
is UnsignedDevice.FromYou -> stringResource(CommonStrings.screen_timeline_item_menu_send_failure_you_unsigned_device)
is ChangedIdentity -> stringResource(CommonStrings.screen_timeline_item_menu_send_failure_changed_identity, userDisplayName)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import androidx.compose.runtime.Immutable
sealed interface VerifiedUserSendFailure {
data object None : VerifiedUserSendFailure

data class UnsignedDevice(
val userDisplayName: String,
) : VerifiedUserSendFailure
sealed interface UnsignedDevice : VerifiedUserSendFailure {
data object FromYou : UnsignedDevice
data class FromOther(val userDisplayName: String) : UnsignedDevice
}

data class ChangedIdentity(
val userDisplayName: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ class VerifiedUserSendFailureFactory @Inject constructor(
if (userId == null) {
VerifiedUserSendFailure.None
} else {
val displayName = room.userDisplayName(userId).getOrNull() ?: userId.value
VerifiedUserSendFailure.UnsignedDevice(displayName)
if (userId == room.sessionId) {
VerifiedUserSendFailure.UnsignedDevice.FromYou
} else {
val displayName = room.userDisplayName(userId).getOrNull() ?: userId.value
VerifiedUserSendFailure.UnsignedDevice.FromOther(displayName)
}
}
}
is LocalEventSendState.Failed.VerifiedUserChangedIdentity -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun aResolveVerifiedUserSendFailureState(
eventSink = eventSink
)

fun anUnsignedDeviceSendFailure(userDisplayName: String = "Alice") = VerifiedUserSendFailure.UnsignedDevice(
fun anUnsignedDeviceSendFailure(userDisplayName: String = "Alice") = VerifiedUserSendFailure.UnsignedDevice.FromOther(
userDisplayName = userDisplayName,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,28 +113,33 @@ fun ResolveVerifiedUserSendFailureView(
@Composable
private fun VerifiedUserSendFailure.title(): String {
return when (this) {
is VerifiedUserSendFailure.UnsignedDevice -> stringResource(id = CommonStrings.screen_resolve_send_failure_unsigned_device_title, userDisplayName)
is VerifiedUserSendFailure.UnsignedDevice.FromOther -> stringResource(
id = CommonStrings.screen_resolve_send_failure_unsigned_device_title,
userDisplayName
)
VerifiedUserSendFailure.UnsignedDevice.FromYou -> stringResource(id = CommonStrings.screen_resolve_send_failure_you_unsigned_device_title)
is VerifiedUserSendFailure.ChangedIdentity -> stringResource(
id = CommonStrings.screen_resolve_send_failure_changed_identity_title,
userDisplayName
)
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
VerifiedUserSendFailure.None -> ""
}
}

@Composable
private fun VerifiedUserSendFailure.subtitle(): String {
return when (this) {
is VerifiedUserSendFailure.UnsignedDevice -> stringResource(
is VerifiedUserSendFailure.UnsignedDevice.FromOther -> stringResource(
id = CommonStrings.screen_resolve_send_failure_unsigned_device_subtitle,
userDisplayName,
userDisplayName,
)
VerifiedUserSendFailure.UnsignedDevice.FromYou -> stringResource(id = CommonStrings.screen_resolve_send_failure_you_unsigned_device_subtitle)
is VerifiedUserSendFailure.ChangedIdentity -> stringResource(
id = CommonStrings.screen_resolve_send_failure_changed_identity_subtitle,
userDisplayName
)
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
VerifiedUserSendFailure.None -> ""
}
}

Expand All @@ -143,7 +148,7 @@ private fun VerifiedUserSendFailure.resolveAction(): String {
return when (this) {
is VerifiedUserSendFailure.UnsignedDevice -> stringResource(id = CommonStrings.screen_resolve_send_failure_unsigned_device_primary_button_title)
is VerifiedUserSendFailure.ChangedIdentity -> stringResource(id = CommonStrings.screen_resolve_send_failure_changed_identity_primary_button_title)
VerifiedUserSendFailure.None -> error("This method should never be called for this state")
VerifiedUserSendFailure.None -> ""
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.toImmutableList
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import javax.inject.Inject
import kotlin.time.Duration.Companion.milliseconds

class PinnedMessagesBannerPresenter @Inject constructor(
private val room: MatrixRoom,
Expand Down Expand Up @@ -123,7 +121,6 @@ class PinnedMessagesBannerPresenter @Inject constructor(
is AsyncData.Loading -> flowOf(AsyncData.Loading())
is AsyncData.Success -> {
asyncTimeline.data.timelineItems
.debounce(300.milliseconds)
.map { timelineItems ->
val pinnedItems = timelineItems.mapNotNull { timelineItem ->
itemFactory.create(timelineItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ import kotlinx.collections.immutable.ImmutableList
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.FlowPreview
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import timber.log.Timber
import kotlin.time.Duration.Companion.milliseconds

class PinnedMessagesListPresenter @AssistedInject constructor(
@Assisted private val navigator: PinnedMessagesListNavigator,
Expand Down Expand Up @@ -174,7 +172,7 @@ class PinnedMessagesListPresenter @AssistedInject constructor(
is AsyncData.Failure -> flowOf(AsyncData.Failure(asyncTimeline.error))
is AsyncData.Loading -> flowOf(AsyncData.Loading())
is AsyncData.Success -> {
val timelineItemsFlow = asyncTimeline.data.timelineItems.debounce(300.milliseconds)
val timelineItemsFlow = asyncTimeline.data.timelineItems
combine(timelineItemsFlow, room.membersStateFlow) { items, membersState ->
timelineItemsFactory.replaceWith(
timelineItems = items,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject
Expand Down Expand Up @@ -81,6 +82,7 @@ class TimelinePresenter @AssistedInject constructor(
computeReactions = true,
)
)
private var timelineItems by mutableStateOf<ImmutableList<TimelineItem>>(persistentListOf())

@Composable
override fun present(): TimelineState {
Expand All @@ -89,9 +91,12 @@ class TimelinePresenter @AssistedInject constructor(
mutableStateOf(FocusRequestState.None)
}

LaunchedEffect(Unit) {
timelineItemsFactory.timelineItems.collect { timelineItems = it }
}

val lastReadReceiptId = rememberSaveable { mutableStateOf<EventId?>(null) }

val timelineItems by timelineItemsFactory.timelineItems.collectAsState(initial = persistentListOf())
val roomInfo by room.roomInfoFlow.collectAsState(initial = null)

val syncUpdateFlow = room.syncUpdateFlow.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ResolveVerifiedUserSendFailurePresenterTest {
initialState.eventSink(ResolveVerifiedUserSendFailureEvents.ComputeForMessage(failedMessage))
skipItems(1)
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromYou)
state.eventSink(ResolveVerifiedUserSendFailureEvents.Dismiss)
}
skipItems(1)
Expand Down Expand Up @@ -124,7 +124,7 @@ class ResolveVerifiedUserSendFailurePresenterTest {

skipItems(1)
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromYou)
state.eventSink(ResolveVerifiedUserSendFailureEvents.Retry)
}
awaitItem().also { state ->
Expand Down Expand Up @@ -158,7 +158,7 @@ class ResolveVerifiedUserSendFailurePresenterTest {

skipItems(1)
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromYou)
state.eventSink(ResolveVerifiedUserSendFailureEvents.ResolveAndResend)
}
awaitItem().also { state ->
Expand All @@ -167,7 +167,7 @@ class ResolveVerifiedUserSendFailurePresenterTest {
// This should move to the next user
skipItems(2)
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID_2.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromOther(A_USER_ID_2.value))
assertThat(state.resolveAction).isEqualTo(AsyncAction.Success(Unit))
state.eventSink(ResolveVerifiedUserSendFailureEvents.ResolveAndResend)
}
Expand Down Expand Up @@ -199,14 +199,14 @@ class ResolveVerifiedUserSendFailurePresenterTest {

skipItems(1)
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromYou)
state.eventSink(ResolveVerifiedUserSendFailureEvents.ResolveAndResend)
}
awaitItem().also { state ->
assertThat(state.resolveAction).isEqualTo(AsyncAction.Loading)
}
awaitItem().also { state ->
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice(A_USER_ID.value))
assertThat(state.verifiedUserSendFailure).isEqualTo(VerifiedUserSendFailure.UnsignedDevice.FromYou)
assertThat(state.resolveAction).isInstanceOf(AsyncAction.Failure::class.java)
}
ensureAllEventsConsumed()
Expand Down
Loading

0 comments on commit cec945c

Please sign in to comment.