mirror of
https://github.com/element-hq/element-android
synced 2024-11-23 18:05:36 +03:00
Renaming and creating a fixture method for DeviceFullInfo mocks
This commit is contained in:
parent
db17d02f36
commit
e765575cf6
2 changed files with 49 additions and 29 deletions
|
@ -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<DeviceFullInfo> = 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<DeviceFullInfo> = 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<DeviceFullInfo> = 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<DeviceFullInfo> = 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<DeviceFullInfo> = 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,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
40
vector/src/test/java/im/vector/app/test/fixtures/DeviceFullInfoFixture.kt
vendored
Normal file
40
vector/src/test/java/im/vector/app/test/fixtures/DeviceFullInfoFixture.kt
vendored
Normal 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,
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue