diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt index fa61918689..e7b8eeee9b 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt @@ -22,11 +22,10 @@ import com.airbnb.mvrx.test.MavericksTestRule import im.vector.app.features.settings.devices.v2.DeviceFullInfo import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase -import im.vector.app.features.settings.devices.v2.details.extended.DeviceExtendedInfo import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType -import im.vector.app.features.settings.devices.v2.list.DeviceType import im.vector.app.test.fakes.FakeActiveSessionHolder import im.vector.app.test.fakes.FakeVerificationService +import im.vector.app.test.fixtures.aDeviceFullInfo import im.vector.app.test.test import im.vector.app.test.testDispatcher import io.mockk.every @@ -39,8 +38,6 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test -import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo -import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel private const val A_TITLE_RES_ID = 1 private const val A_DEVICE_ID = "device-id" @@ -146,7 +143,7 @@ class OtherSessionsViewModelTest { @Test fun `given enable select mode action when handling the action then viewState is updated with correct info`() { // Given - val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) + val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false) val devices: List = listOf(deviceFullInfo) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) val expectedState = OtherSessionsViewState( @@ -170,8 +167,8 @@ class OtherSessionsViewModelTest { @Test fun `given disable select mode action when handling the action then viewState is updated with correct info`() { // Given - val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) - val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) + val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true) + val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true) val devices: List = listOf(deviceFullInfo1, deviceFullInfo2) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) val expectedState = OtherSessionsViewState( @@ -195,7 +192,7 @@ class OtherSessionsViewModelTest { @Test fun `given toggle selection for device action when handling the action then viewState is updated with correct info`() { // Given - val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) + val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false) val devices: List = listOf(deviceFullInfo) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) val expectedState = OtherSessionsViewState( @@ -219,8 +216,8 @@ class OtherSessionsViewModelTest { @Test fun `given select all action when handling the action then viewState is updated with correct info`() { // Given - val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) - val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) + val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false) + val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true) val devices: List = listOf(deviceFullInfo1, deviceFullInfo2) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) val expectedState = OtherSessionsViewState( @@ -244,8 +241,8 @@ class OtherSessionsViewModelTest { @Test fun `given deselect all action when handling the action then viewState is updated with correct info`() { // Given - val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) - val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) + val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false) + val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true) val devices: List = listOf(deviceFullInfo1, deviceFullInfo2) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) val expectedState = OtherSessionsViewState( @@ -272,21 +269,4 @@ class OtherSessionsViewModelTest { ) { every { fakeGetDeviceFullInfoListUseCase.execute(filterType, any()) } returns flowOf(devices) } - - private fun givenDeviceFullInfo(deviceId: String, isSelected: Boolean): DeviceFullInfo { - return DeviceFullInfo( - deviceInfo = DeviceInfo( - deviceId = deviceId, - ), - cryptoDeviceInfo = null, - roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, - isInactive = true, - isCurrentDevice = true, - deviceExtendedInfo = DeviceExtendedInfo( - deviceType = DeviceType.MOBILE, - ), - matrixClientInfo = null, - isSelected = isSelected, - ) - } } diff --git a/vector/src/test/java/im/vector/app/test/fixtures/DeviceFullInfoFixture.kt b/vector/src/test/java/im/vector/app/test/fixtures/DeviceFullInfoFixture.kt new file mode 100644 index 0000000000..d5f987b5c6 --- /dev/null +++ b/vector/src/test/java/im/vector/app/test/fixtures/DeviceFullInfoFixture.kt @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.test.fixtures + +import im.vector.app.features.settings.devices.v2.DeviceFullInfo +import im.vector.app.features.settings.devices.v2.details.extended.DeviceExtendedInfo +import im.vector.app.features.settings.devices.v2.list.DeviceType +import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo +import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel + +fun aDeviceFullInfo(deviceId: String, isSelected: Boolean): DeviceFullInfo { + return DeviceFullInfo( + deviceInfo = DeviceInfo( + deviceId = deviceId, + ), + cryptoDeviceInfo = null, + roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted, + isInactive = true, + isCurrentDevice = true, + deviceExtendedInfo = DeviceExtendedInfo( + deviceType = DeviceType.MOBILE, + ), + matrixClientInfo = null, + isSelected = isSelected, + ) +}