Benoit Marty
12 months ago
committed by
GitHub
53 changed files with 184 additions and 99 deletions
@ -0,0 +1,93 @@
@@ -0,0 +1,93 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.appnav.di |
||||
|
||||
import com.bumble.appyx.core.state.MutableSavedStateMapImpl |
||||
import com.google.common.truth.Truth.assertThat |
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID |
||||
import io.element.android.libraries.matrix.test.FakeMatrixClient |
||||
import io.element.android.libraries.matrix.test.auth.FakeAuthenticationService |
||||
import kotlinx.coroutines.test.runTest |
||||
import org.junit.Test |
||||
|
||||
class MatrixClientsHolderTest { |
||||
@Test |
||||
fun `test getOrNull`() { |
||||
val fakeAuthenticationService = FakeAuthenticationService() |
||||
val matrixClientsHolder = MatrixClientsHolder(fakeAuthenticationService) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isNull() |
||||
} |
||||
|
||||
@Test |
||||
fun `test getOrRestore`() = runTest { |
||||
val fakeAuthenticationService = FakeAuthenticationService() |
||||
val matrixClientsHolder = MatrixClientsHolder(fakeAuthenticationService) |
||||
val fakeMatrixClient = FakeMatrixClient() |
||||
fakeAuthenticationService.givenMatrixClient(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isNull() |
||||
assertThat(matrixClientsHolder.getOrRestore(A_SESSION_ID).getOrNull()).isEqualTo(fakeMatrixClient) |
||||
// Do it again to it the cache |
||||
assertThat(matrixClientsHolder.getOrRestore(A_SESSION_ID).getOrNull()).isEqualTo(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isEqualTo(fakeMatrixClient) |
||||
} |
||||
|
||||
@Test |
||||
fun `test remove`() = runTest { |
||||
val fakeAuthenticationService = FakeAuthenticationService() |
||||
val matrixClientsHolder = MatrixClientsHolder(fakeAuthenticationService) |
||||
val fakeMatrixClient = FakeMatrixClient() |
||||
fakeAuthenticationService.givenMatrixClient(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrRestore(A_SESSION_ID).getOrNull()).isEqualTo(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isEqualTo(fakeMatrixClient) |
||||
// Remove |
||||
matrixClientsHolder.remove(A_SESSION_ID) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isNull() |
||||
} |
||||
|
||||
@Test |
||||
fun `test remove all`() = runTest { |
||||
val fakeAuthenticationService = FakeAuthenticationService() |
||||
val matrixClientsHolder = MatrixClientsHolder(fakeAuthenticationService) |
||||
val fakeMatrixClient = FakeMatrixClient() |
||||
fakeAuthenticationService.givenMatrixClient(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrRestore(A_SESSION_ID).getOrNull()).isEqualTo(fakeMatrixClient) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isEqualTo(fakeMatrixClient) |
||||
// Remove all |
||||
matrixClientsHolder.removeAll() |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isNull() |
||||
} |
||||
|
||||
@Test |
||||
fun `test save and restore`() = runTest { |
||||
val fakeAuthenticationService = FakeAuthenticationService() |
||||
val matrixClientsHolder = MatrixClientsHolder(fakeAuthenticationService) |
||||
val fakeMatrixClient = FakeMatrixClient() |
||||
fakeAuthenticationService.givenMatrixClient(fakeMatrixClient) |
||||
matrixClientsHolder.getOrRestore(A_SESSION_ID) |
||||
val savedStateMap = MutableSavedStateMapImpl { true } |
||||
matrixClientsHolder.saveIntoSavedState(savedStateMap) |
||||
assertThat(savedStateMap.size).isEqualTo(1) |
||||
// Test Restore with non-empty map |
||||
matrixClientsHolder.restoreWithSavedState(savedStateMap) |
||||
// Empty the map |
||||
matrixClientsHolder.removeAll() |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isNull() |
||||
// Restore again |
||||
matrixClientsHolder.restoreWithSavedState(savedStateMap) |
||||
assertThat(matrixClientsHolder.getOrNull(A_SESSION_ID)).isEqualTo(fakeMatrixClient) |
||||
} |
||||
} |
@ -1,30 +0,0 @@
@@ -1,30 +0,0 @@
|
||||
/* |
||||
* Copyright (c) 2023 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 io.element.android.features.leaveroom.fake |
||||
|
||||
import com.squareup.anvil.annotations.ContributesTo |
||||
import dagger.Binds |
||||
import dagger.Module |
||||
import io.element.android.features.leaveroom.api.LeaveRoomPresenter |
||||
import io.element.android.libraries.di.SessionScope |
||||
|
||||
@Module |
||||
@ContributesTo(SessionScope::class) |
||||
interface LeaveRoomPresenterFakeModule { |
||||
@Binds |
||||
fun leaveRoomPresenter(leaveRoomPresenter: LeaveRoomPresenterFake): LeaveRoomPresenter |
||||
} |
Binary file not shown.
Binary file not shown.
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-D-3_3_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-D-4_4_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-D-3_3_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-D-4_4_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-N-3_4_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-N-4_5_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-N-3_4_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.changeaccountprovider_null_ChangeAccountProviderView-N-4_5_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-D-4_4_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-D-5_5_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-D-4_4_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-D-5_5_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-N-4_5_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-N-5_6_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-N-4_5_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.confirmaccountprovider_null_ConfirmAccountProviderView-N-5_6_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-6_6_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-7_7_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-6_6_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-7_7_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-6_6_null_1,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-7_7_null_1,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-6_6_null_1,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-D-7_7_null_1,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-6_7_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-7_8_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-6_7_null_0,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-7_8_null_0,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-6_7_null_1,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-7_8_null_1,NEXUS_5,1.0,en].png
0
tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-6_7_null_1,NEXUS_5,1.0,en].png → tests/uitests/src/test/snapshots/images/ui_S_t[f.login.impl.screens.searchaccountprovider_null_SearchAccountProviderView-N-7_8_null_1,NEXUS_5,1.0,en].png
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in new issue