From 3349df5a24084679af5dfd1a668675196011c1c2 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Tue, 28 May 2024 13:55:29 +0200 Subject: [PATCH] Set the value of `currentDistributorName` by reading again the value from the service. --- .../impl/notifications/NotificationSettingsPresenter.kt | 1 - .../notifications/NotificationSettingsPresenterTests.kt | 1 + .../android/libraries/push/test/FakePushService.kt | 9 ++++++++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt index 83253e17d2..24f988552e 100644 --- a/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt +++ b/features/preferences/impl/src/main/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenter.kt @@ -121,7 +121,6 @@ class NotificationSettingsPresenter @Inject constructor( ) .fold( { - currentDistributorName = AsyncAction.Success(distributor.name) refreshPushProvider++ }, { diff --git a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt index ea3f4657fe..ae5d571715 100644 --- a/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt +++ b/features/preferences/impl/src/test/kotlin/io/element/android/features/preferences/impl/notifications/NotificationSettingsPresenterTests.kt @@ -262,6 +262,7 @@ class NotificationSettingsPresenterTests { val withNewProvider = awaitItem() assertThat(withNewProvider.showChangePushProviderDialog).isFalse() assertThat(withNewProvider.currentPushDistributor).isEqualTo(AsyncAction.Loading) + skipItems(1) val lastItem = awaitItem() assertThat(lastItem.currentPushDistributor).isEqualTo(AsyncAction.Success("aDistributorName1")) cancelAndIgnoreRemainingEvents() diff --git a/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/FakePushService.kt b/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/FakePushService.kt index 584e93d8e1..5e7d9e7ff1 100644 --- a/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/FakePushService.kt +++ b/libraries/push/test/src/main/kotlin/io/element/android/libraries/push/test/FakePushService.kt @@ -30,19 +30,26 @@ class FakePushService( }, ) : PushService { override suspend fun getCurrentPushProvider(): PushProvider? { - return availablePushProviders.firstOrNull() + return registeredPushProvider ?: availablePushProviders.firstOrNull() } override fun getAvailablePushProviders(): List { return availablePushProviders } + private var registeredPushProvider: PushProvider? = null + override suspend fun registerWith( matrixClient: MatrixClient, pushProvider: PushProvider, distributor: Distributor, ): Result = simulateLongTask { return registerWithLambda(matrixClient, pushProvider, distributor) + .also { + if (it.isSuccess) { + registeredPushProvider = pushProvider + } + } } override suspend fun testPush(): Boolean = simulateLongTask {