Renaming and creating a fixture method for DeviceFullInfo mocks

This commit is contained in:
Maxime NATUREL 2022-10-25 17:31:46 +02:00
parent db17d02f36
commit e765575cf6
2 changed files with 49 additions and 29 deletions

View file

@ -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.DeviceFullInfo
import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase 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.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.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.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakeVerificationService 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.test
import im.vector.app.test.testDispatcher import im.vector.app.test.testDispatcher
import io.mockk.every import io.mockk.every
@ -39,8 +38,6 @@ import org.junit.After
import org.junit.Before import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test 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_TITLE_RES_ID = 1
private const val A_DEVICE_ID = "device-id" private const val A_DEVICE_ID = "device-id"
@ -146,7 +143,7 @@ class OtherSessionsViewModelTest {
@Test @Test
fun `given enable select mode action when handling the action then viewState is updated with correct info`() { fun `given enable select mode action when handling the action then viewState is updated with correct info`() {
// Given // Given
val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo) val devices: List<DeviceFullInfo> = listOf(deviceFullInfo)
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
val expectedState = OtherSessionsViewState( val expectedState = OtherSessionsViewState(
@ -170,8 +167,8 @@ class OtherSessionsViewModelTest {
@Test @Test
fun `given disable select mode action when handling the action then viewState is updated with correct info`() { fun `given disable select mode action when handling the action then viewState is updated with correct info`() {
// Given // Given
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2) val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
val expectedState = OtherSessionsViewState( val expectedState = OtherSessionsViewState(
@ -195,7 +192,7 @@ class OtherSessionsViewModelTest {
@Test @Test
fun `given toggle selection for device action when handling the action then viewState is updated with correct info`() { fun `given toggle selection for device action when handling the action then viewState is updated with correct info`() {
// Given // Given
val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo) val devices: List<DeviceFullInfo> = listOf(deviceFullInfo)
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
val expectedState = OtherSessionsViewState( val expectedState = OtherSessionsViewState(
@ -219,8 +216,8 @@ class OtherSessionsViewModelTest {
@Test @Test
fun `given select all action when handling the action then viewState is updated with correct info`() { fun `given select all action when handling the action then viewState is updated with correct info`() {
// Given // Given
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2) val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
val expectedState = OtherSessionsViewState( val expectedState = OtherSessionsViewState(
@ -244,8 +241,8 @@ class OtherSessionsViewModelTest {
@Test @Test
fun `given deselect all action when handling the action then viewState is updated with correct info`() { fun `given deselect all action when handling the action then viewState is updated with correct info`() {
// Given // Given
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false) val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true) val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2) val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices) givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
val expectedState = OtherSessionsViewState( val expectedState = OtherSessionsViewState(
@ -272,21 +269,4 @@ class OtherSessionsViewModelTest {
) { ) {
every { fakeGetDeviceFullInfoListUseCase.execute(filterType, any()) } returns flowOf(devices) 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,
)
}
} }

View file

@ -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,
)
}