From 540758d66b0730d408a9737142ecaa01b7ccfd93 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 5 Dec 2022 10:43:56 +0100 Subject: [PATCH] Navigate to rename session screen from current session menu --- .../v2/VectorSettingsDevicesFragment.kt | 14 ++++++++ .../v2/VectorSettingsDevicesViewNavigator.kt | 5 +++ .../VectorSettingsDevicesViewNavigatorTest.kt | 35 +++++++++++++++---- .../OtherSessionsViewNavigatorTest.kt | 8 ++--- .../SessionOverviewViewNavigatorTest.kt | 8 ++--- .../im/vector/app/test/fakes/FakeContext.kt | 10 ++++-- 6 files changed, 61 insertions(+), 19 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt index 64744f6eeb..c29655a0c7 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesFragment.kt @@ -145,6 +145,10 @@ class VectorSettingsDevicesFragment : private fun initCurrentSessionHeaderView() { views.deviceListHeaderCurrentSession.setOnMenuItemClickListener { menuItem -> when (menuItem.itemId) { + R.id.currentSessionHeaderRename -> { + navigateToRenameCurrentSession() + true + } R.id.currentSessionHeaderSignoutOtherSessions -> { confirmMultiSignoutOtherSessions() true @@ -154,6 +158,16 @@ class VectorSettingsDevicesFragment : } } + private fun navigateToRenameCurrentSession() = withState(viewModel) { state -> + val currentDeviceId = state.currentSessionCrossSigningInfo.deviceId + if (currentDeviceId.isNotEmpty()) { + viewNavigator.navigateToRenameSession( + context = requireActivity(), + deviceId = currentDeviceId, + ) + } + } + private fun initCurrentSessionListView() { views.deviceListCurrentSession.viewVerifyButton.debouncedClicks { viewModel.handle(DevicesAction.VerifyCurrentSession) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigator.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigator.kt index 47e697822b..d4b3345fea 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigator.kt @@ -20,6 +20,7 @@ import android.content.Context import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity +import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity import javax.inject.Inject class VectorSettingsDevicesViewNavigator @Inject constructor() { @@ -38,4 +39,8 @@ class VectorSettingsDevicesViewNavigator @Inject constructor() { OtherSessionsActivity.newIntent(context, titleResourceId, defaultFilter, excludeCurrentDevice) ) } + + fun navigateToRenameSession(context: Context, deviceId: String) { + context.startActivity(RenameSessionActivity.newIntent(context, deviceId)) + } } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigatorTest.kt index ec8019384a..37823f7d53 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/VectorSettingsDevicesViewNavigatorTest.kt @@ -20,6 +20,7 @@ import android.content.Intent import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType import im.vector.app.features.settings.devices.v2.othersessions.OtherSessionsActivity import im.vector.app.features.settings.devices.v2.overview.SessionOverviewActivity +import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity import im.vector.app.test.fakes.FakeContext import io.mockk.every import io.mockk.mockk @@ -43,6 +44,7 @@ class VectorSettingsDevicesViewNavigatorTest { fun setUp() { mockkObject(SessionOverviewActivity.Companion) mockkObject(OtherSessionsActivity.Companion) + mockkObject(RenameSessionActivity.Companion) } @After @@ -52,26 +54,41 @@ class VectorSettingsDevicesViewNavigatorTest { @Test fun `given a session id when navigating to overview then it starts the correct activity`() { + // Given val intent = givenIntentForSessionOverview(A_SESSION_ID) context.givenStartActivity(intent) + // When vectorSettingsDevicesViewNavigator.navigateToSessionOverview(context.instance, A_SESSION_ID) - verify { - context.instance.startActivity(intent) - } + // Then + context.verifyStartActivity(intent) } @Test fun `given an intent when navigating to other sessions list then it starts the correct activity`() { + // Given val intent = givenIntentForOtherSessions(A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true) context.givenStartActivity(intent) + // When vectorSettingsDevicesViewNavigator.navigateToOtherSessions(context.instance, A_TITLE_RESOURCE_ID, A_DEFAULT_FILTER, true) - verify { - context.instance.startActivity(intent) - } + // Then + context.verifyStartActivity(intent) + } + + @Test + fun `given an intent when navigating to rename session screen then it starts the correct activity`() { + // Given + val intent = givenIntentForRenameSession(A_SESSION_ID) + context.givenStartActivity(intent) + + // When + vectorSettingsDevicesViewNavigator.navigateToRenameSession(context.instance, A_SESSION_ID) + + // Then + context.verifyStartActivity(intent) } private fun givenIntentForSessionOverview(sessionId: String): Intent { @@ -85,4 +102,10 @@ class VectorSettingsDevicesViewNavigatorTest { every { OtherSessionsActivity.newIntent(context.instance, titleResourceId, defaultFilter, excludeCurrentDevice) } returns intent return intent } + + private fun givenIntentForRenameSession(sessionId: String): Intent { + val intent = mockk() + every { RenameSessionActivity.newIntent(context.instance, sessionId) } returns intent + return intent + } } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewNavigatorTest.kt index 3123572521..23fc1cbdce 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewNavigatorTest.kt @@ -23,7 +23,6 @@ import io.mockk.every import io.mockk.mockk import io.mockk.mockkObject import io.mockk.unmockkAll -import io.mockk.verify import org.junit.After import org.junit.Before import org.junit.Test @@ -47,14 +46,15 @@ class OtherSessionsViewNavigatorTest { @Test fun `given a device id when navigating to overview then it starts the correct activity`() { + // Given val intent = givenIntentForDeviceOverview(A_DEVICE_ID) context.givenStartActivity(intent) + // When otherSessionsViewNavigator.navigateToSessionOverview(context.instance, A_DEVICE_ID) - verify { - context.instance.startActivity(intent) - } + // Then + context.verifyStartActivity(intent) } private fun givenIntentForDeviceOverview(deviceId: String): Intent { diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt index e309c05042..99f3013697 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt @@ -60,9 +60,7 @@ class SessionOverviewViewNavigatorTest { sessionOverviewViewNavigator.goToSessionDetails(context.instance, A_SESSION_ID) // Then - verify { - context.instance.startActivity(intent) - } + context.verifyStartActivity(intent) } @Test @@ -75,9 +73,7 @@ class SessionOverviewViewNavigatorTest { sessionOverviewViewNavigator.goToRenameSession(context.instance, A_SESSION_ID) // Then - verify { - context.instance.startActivity(intent) - } + context.verifyStartActivity(intent) } @Test diff --git a/vector/src/test/java/im/vector/app/test/fakes/FakeContext.kt b/vector/src/test/java/im/vector/app/test/fakes/FakeContext.kt index 9a94313fec..22e191e29c 100644 --- a/vector/src/test/java/im/vector/app/test/fakes/FakeContext.kt +++ b/vector/src/test/java/im/vector/app/test/fakes/FakeContext.kt @@ -24,9 +24,9 @@ import android.net.ConnectivityManager import android.net.Uri import android.os.ParcelFileDescriptor import io.mockk.every -import io.mockk.just +import io.mockk.justRun import io.mockk.mockk -import io.mockk.runs +import io.mockk.verify import java.io.OutputStream class FakeContext( @@ -73,7 +73,11 @@ class FakeContext( } fun givenStartActivity(intent: Intent) { - every { instance.startActivity(intent) } just runs + justRun { instance.startActivity(intent) } + } + + fun verifyStartActivity(intent: Intent) { + verify { instance.startActivity(intent) } } fun givenClipboardManager(): FakeClipboardManager {