Adds DefaultNavigatorTest

This commit is contained in:
ericdecanini 2022-08-18 17:15:12 +02:00
parent 789dffe4df
commit 58e1fe4c01
7 changed files with 173 additions and 4 deletions

View file

@ -188,7 +188,15 @@ class DefaultNavigator @Inject constructor(
return
}
spaceStateHandler.setCurrentSpace(spaceId, overriddenSpaceName = overriddenSpaceName)
when (postSwitchSpaceAction) {
handlePostSwitchAction(context, spaceId, postSwitchSpaceAction)
}
private fun handlePostSwitchAction(
context: Context,
spaceId: String,
action: Navigator.PostSwitchSpaceAction,
) {
when (action) {
Navigator.PostSwitchSpaceAction.None -> {
// go back to home if we are showing room details?
// This is a bit ugly, but the navigator is supposed to know about the activity stack
@ -204,9 +212,9 @@ class DefaultNavigator @Inject constructor(
}
is Navigator.PostSwitchSpaceAction.OpenDefaultRoom -> {
val args = TimelineArgs(
postSwitchSpaceAction.roomId,
action.roomId,
eventId = null,
openShareSpaceForId = spaceId.takeIf { postSwitchSpaceAction.showShareSheet }
openShareSpaceForId = spaceId.takeIf { action.showShareSheet }
)
val intent = RoomDetailActivity.newIntent(context, args, false)
startActivity(context, intent, false)

View file

@ -0,0 +1,77 @@
/*
* 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.features.navigation
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakeAnalyticsTracker
import im.vector.app.test.fakes.FakeContext
import im.vector.app.test.fakes.FakeSpaceStateHandler
import im.vector.app.test.fakes.FakeSupportedVerificationMethodsProvider
import im.vector.app.test.fakes.FakeVectorFeatures
import im.vector.app.test.fakes.FakeVectorPreferences
import im.vector.app.test.fakes.FakeWidgetArgsBuilder
import im.vector.app.test.fixtures.RoomSummaryFixture.aRoomSummary
import org.junit.Test
internal class DefaultNavigatorTest {
private val sessionHolder = FakeActiveSessionHolder()
private val vectorPreferences = FakeVectorPreferences()
private val widgetArgsBuilder = FakeWidgetArgsBuilder()
private val spaceStateHandler = FakeSpaceStateHandler()
private val supportedVerificationMethodsProvider = FakeSupportedVerificationMethodsProvider()
private val features = FakeVectorFeatures()
private val analyticsTracker = FakeAnalyticsTracker()
private val navigator = DefaultNavigator(
sessionHolder.instance,
vectorPreferences.instance,
widgetArgsBuilder.instance,
spaceStateHandler,
supportedVerificationMethodsProvider.instance,
features,
analyticsTracker,
)
/**
* The below tests are by no means all that we want to test in [DefaultNavigator]
* Please add relevant tests as you make changes to or related to other functions in the class
*/
@Test
fun `when switchToSpace, then current space set`() {
val spaceId = "space-id"
val spaceSummary = aRoomSummary(spaceId)
sessionHolder.fakeSession.fakeRoomService.getRoomSummaryReturns(spaceSummary)
navigator.switchToSpace(FakeContext().instance, spaceId, Navigator.PostSwitchSpaceAction.None)
spaceStateHandler.verifySetCurrentSpace(spaceId)
}
@Test
fun `given non-null overriddenSpaceName, when switchToSpace, then current space set`() {
val spaceId = "space-id"
val spaceSummary = aRoomSummary(spaceId)
sessionHolder.fakeSession.fakeRoomService.getRoomSummaryReturns(spaceSummary)
val overriddenSpaceName = "new-space-name"
navigator.switchToSpace(FakeContext().instance, spaceId, Navigator.PostSwitchSpaceAction.None, overriddenSpaceName)
spaceStateHandler.verifySetCurrentSpace(spaceId, overriddenSpaceName = overriddenSpaceName)
}
}

View file

@ -16,12 +16,18 @@
package im.vector.app.test.fakes
import io.mockk.every
import io.mockk.mockk
import org.matrix.android.sdk.api.session.room.RoomService
import org.matrix.android.sdk.api.session.room.model.RoomSummary
class FakeRoomService(
private val fakeRoom: FakeRoom = FakeRoom()
) : RoomService by mockk() {
override fun getRoom(roomId: String) = fakeRoom
fun getRoomSummaryReturns(roomSummary: RoomSummary?) {
every { getRoomSummary(any()) } returns roomSummary
}
}

View file

@ -37,7 +37,7 @@ class FakeSession(
val fakeProfileService: FakeProfileService = FakeProfileService(),
val fakeHomeServerCapabilitiesService: FakeHomeServerCapabilitiesService = FakeHomeServerCapabilitiesService(),
val fakeSharedSecretStorageService: FakeSharedSecretStorageService = FakeSharedSecretStorageService(),
private val fakeRoomService: FakeRoomService = FakeRoomService(),
val fakeRoomService: FakeRoomService = FakeRoomService(),
private val fakeEventService: FakeEventService = FakeEventService(),
) : Session by mockk(relaxed = true) {

View file

@ -0,0 +1,28 @@
/*
* 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.fakes
import im.vector.app.SpaceStateHandler
import io.mockk.mockk
import io.mockk.verify
class FakeSpaceStateHandler : SpaceStateHandler by mockk(relaxUnitFun = true) {
fun verifySetCurrentSpace(spaceId: String, overriddenSpaceName: String? = null) {
verify { setCurrentSpace(spaceId, overriddenSpaceName = overriddenSpaceName) }
}
}

View file

@ -0,0 +1,25 @@
/*
* 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.fakes
import im.vector.app.features.crypto.verification.SupportedVerificationMethodsProvider
import io.mockk.mockk
class FakeSupportedVerificationMethodsProvider {
val instance = mockk<SupportedVerificationMethodsProvider>()
}

View file

@ -0,0 +1,25 @@
/*
* 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.fakes
import im.vector.app.features.widgets.WidgetArgsBuilder
import io.mockk.mockk
class FakeWidgetArgsBuilder {
val instance = mockk<WidgetArgsBuilder>()
}