Skip to content

Commit fcac184

Browse files
committed
Write unit test for toggling ip address visibility.
1 parent 73e2f02 commit fcac184

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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.features.settings.devices.v2
18+
19+
import im.vector.app.test.fakes.FakeVectorPreferences
20+
import org.junit.Test
21+
22+
class ToggleIpAddressVisibilityUseCaseTest {
23+
24+
private val fakeVectorPreferences = FakeVectorPreferences()
25+
26+
private val toggleIpAddressVisibilityUseCase = ToggleIpAddressVisibilityUseCase(
27+
vectorPreferences = fakeVectorPreferences.instance,
28+
)
29+
30+
@Test
31+
fun `given ip addresses are currently visible then then visibility is set as false`() {
32+
// Given
33+
fakeVectorPreferences.givenShowIpAddressInSessionManagerScreens(true)
34+
35+
// When
36+
toggleIpAddressVisibilityUseCase.execute()
37+
38+
// Then
39+
fakeVectorPreferences.verifySetIpAddressVisibilityInDeviceManagerScreens(false)
40+
}
41+
42+
@Test
43+
fun `given ip addresses are currently not visible then then visibility is set as true`() {
44+
// Given
45+
fakeVectorPreferences.givenShowIpAddressInSessionManagerScreens(false)
46+
47+
// When
48+
toggleIpAddressVisibilityUseCase.execute()
49+
50+
// Then
51+
fakeVectorPreferences.verifySetIpAddressVisibilityInDeviceManagerScreens(true)
52+
}
53+
}

vector/src/test/java/im/vector/app/test/fakes/FakeVectorPreferences.kt

+8
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,12 @@ class FakeVectorPreferences {
7777
fun givenIsBackgroundSyncEnabled(isEnabled: Boolean) {
7878
every { instance.isBackgroundSyncEnabled() } returns isEnabled
7979
}
80+
81+
fun givenShowIpAddressInSessionManagerScreens(show: Boolean) {
82+
every { instance.showIpAddressInSessionManagerScreens() } returns show
83+
}
84+
85+
fun verifySetIpAddressVisibilityInDeviceManagerScreens(isVisible: Boolean) {
86+
verify { instance.setIpAddressVisibilityInDeviceManagerScreens(isVisible) }
87+
}
8088
}

0 commit comments

Comments
 (0)