Skip to content

Commit e765575

Browse files
author
Maxime NATUREL
committed
Renaming and creating a fixture method for DeviceFullInfo mocks
1 parent db17d02 commit e765575

File tree

2 files changed

+49
-29
lines changed

2 files changed

+49
-29
lines changed

vector/src/test/java/im/vector/app/features/settings/devices/v2/othersessions/OtherSessionsViewModelTest.kt

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import com.airbnb.mvrx.test.MavericksTestRule
2222
import im.vector.app.features.settings.devices.v2.DeviceFullInfo
2323
import im.vector.app.features.settings.devices.v2.GetDeviceFullInfoListUseCase
2424
import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase
25-
import im.vector.app.features.settings.devices.v2.details.extended.DeviceExtendedInfo
2625
import im.vector.app.features.settings.devices.v2.filter.DeviceManagerFilterType
27-
import im.vector.app.features.settings.devices.v2.list.DeviceType
2826
import im.vector.app.test.fakes.FakeActiveSessionHolder
2927
import im.vector.app.test.fakes.FakeVerificationService
28+
import im.vector.app.test.fixtures.aDeviceFullInfo
3029
import im.vector.app.test.test
3130
import im.vector.app.test.testDispatcher
3231
import io.mockk.every
@@ -39,8 +38,6 @@ import org.junit.After
3938
import org.junit.Before
4039
import org.junit.Rule
4140
import org.junit.Test
42-
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
43-
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
4441

4542
private const val A_TITLE_RES_ID = 1
4643
private const val A_DEVICE_ID = "device-id"
@@ -146,7 +143,7 @@ class OtherSessionsViewModelTest {
146143
@Test
147144
fun `given enable select mode action when handling the action then viewState is updated with correct info`() {
148145
// Given
149-
val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false)
146+
val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
150147
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo)
151148
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
152149
val expectedState = OtherSessionsViewState(
@@ -170,8 +167,8 @@ class OtherSessionsViewModelTest {
170167
@Test
171168
fun `given disable select mode action when handling the action then viewState is updated with correct info`() {
172169
// Given
173-
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true)
174-
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true)
170+
val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
171+
val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
175172
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
176173
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
177174
val expectedState = OtherSessionsViewState(
@@ -195,7 +192,7 @@ class OtherSessionsViewModelTest {
195192
@Test
196193
fun `given toggle selection for device action when handling the action then viewState is updated with correct info`() {
197194
// Given
198-
val deviceFullInfo = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false)
195+
val deviceFullInfo = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
199196
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo)
200197
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
201198
val expectedState = OtherSessionsViewState(
@@ -219,8 +216,8 @@ class OtherSessionsViewModelTest {
219216
@Test
220217
fun `given select all action when handling the action then viewState is updated with correct info`() {
221218
// Given
222-
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false)
223-
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true)
219+
val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
220+
val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
224221
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
225222
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
226223
val expectedState = OtherSessionsViewState(
@@ -244,8 +241,8 @@ class OtherSessionsViewModelTest {
244241
@Test
245242
fun `given deselect all action when handling the action then viewState is updated with correct info`() {
246243
// Given
247-
val deviceFullInfo1 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = false)
248-
val deviceFullInfo2 = givenDeviceFullInfo(A_DEVICE_ID, isSelected = true)
244+
val deviceFullInfo1 = aDeviceFullInfo(A_DEVICE_ID, isSelected = false)
245+
val deviceFullInfo2 = aDeviceFullInfo(A_DEVICE_ID, isSelected = true)
249246
val devices: List<DeviceFullInfo> = listOf(deviceFullInfo1, deviceFullInfo2)
250247
givenGetDeviceFullInfoListReturns(filterType = defaultArgs.defaultFilter, devices)
251248
val expectedState = OtherSessionsViewState(
@@ -272,21 +269,4 @@ class OtherSessionsViewModelTest {
272269
) {
273270
every { fakeGetDeviceFullInfoListUseCase.execute(filterType, any()) } returns flowOf(devices)
274271
}
275-
276-
private fun givenDeviceFullInfo(deviceId: String, isSelected: Boolean): DeviceFullInfo {
277-
return DeviceFullInfo(
278-
deviceInfo = DeviceInfo(
279-
deviceId = deviceId,
280-
),
281-
cryptoDeviceInfo = null,
282-
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
283-
isInactive = true,
284-
isCurrentDevice = true,
285-
deviceExtendedInfo = DeviceExtendedInfo(
286-
deviceType = DeviceType.MOBILE,
287-
),
288-
matrixClientInfo = null,
289-
isSelected = isSelected,
290-
)
291-
}
292272
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright (c) 2022 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.test.fixtures
18+
19+
import im.vector.app.features.settings.devices.v2.DeviceFullInfo
20+
import im.vector.app.features.settings.devices.v2.details.extended.DeviceExtendedInfo
21+
import im.vector.app.features.settings.devices.v2.list.DeviceType
22+
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
23+
import org.matrix.android.sdk.api.session.crypto.model.RoomEncryptionTrustLevel
24+
25+
fun aDeviceFullInfo(deviceId: String, isSelected: Boolean): DeviceFullInfo {
26+
return DeviceFullInfo(
27+
deviceInfo = DeviceInfo(
28+
deviceId = deviceId,
29+
),
30+
cryptoDeviceInfo = null,
31+
roomEncryptionTrustLevel = RoomEncryptionTrustLevel.Trusted,
32+
isInactive = true,
33+
isCurrentDevice = true,
34+
deviceExtendedInfo = DeviceExtendedInfo(
35+
deviceType = DeviceType.MOBILE,
36+
),
37+
matrixClientInfo = null,
38+
isSelected = isSelected,
39+
)
40+
}

0 commit comments

Comments
 (0)