Skip to content

Commit

Permalink
chore(Matomo): Add test to make sure newTransferDestination className…
Browse files Browse the repository at this point in the history
…s aren't changed
  • Loading branch information
FabianDevel committed Mar 5, 2025
1 parent 330eb50 commit 679c103
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ sealed class MainNavigation(override val matomoValue: String) : NavigationDestin
private const val sentDestinationName = "SentDestination"
private const val receivedDestinationName = "ReceivedDestination"
private const val settingsDestinationName = "SettingsDestination"
val destinationsNames = listOf(
val mainDestinationsNames = listOf(
sentDestinationName,
receivedDestinationName,
settingsDestinationName,
Expand All @@ -93,10 +93,10 @@ sealed class MainNavigation(override val matomoValue: String) : NavigationDestin
fun NavBackStackEntry.toMainDestination(): MainNavigation? {
return runCatching {
val destinationRoute = destination.route ?: error("Destination route cannot be empty")
when (destinationsNames.firstOrNull { destinationRoute.contains(it) }) {
sentDestinationName -> this.toRoute<SentDestination>()
receivedDestinationName -> this.toRoute<ReceivedDestination>()
settingsDestinationName -> this.toRoute<SettingsDestination>()
when (mainDestinationsNames.firstOrNull { destinationRoute.contains(it) }) {
sentDestinationName -> toRoute<SentDestination>()
receivedDestinationName -> toRoute<ReceivedDestination>()
settingsDestinationName -> toRoute<SettingsDestination>()
else -> error("Destination $destinationRoute is not handled")
}
}.getOrElse { exception ->
Expand Down Expand Up @@ -151,34 +151,37 @@ sealed class NewTransferNavigation(override val matomoValue: String) : Navigatio

private val TAG = NewTransferNavigation::class.java.simpleName

// Because of the minification, we can't directly use the classes names here. It won't work in production environment.
// So, if these classes have to be renamed, they need to be renamed here too.
// Don't worry if you forget, there's a unit test about that.
private const val importFilesDestinationName = "ImportFilesDestination"
private const val ValidateUserEmailDestinationName = "ValidateUserEmailDestination"
private const val UploadProgressDestinationName = "UploadProgressDestination"
private const val UploadSuccessDestinationName = "UploadSuccessDestination"
private const val UploadErrorDestinationName = "UploadErrorDestination"
private const val UploadIntegrityErrorDestinationName = "UploadIntegrityErrorDestination"
private const val NewTransferFilesDetailsDestinationName = "NewTransferFilesDetailsDestination"
private const val validateUserEmailDestinationName = "ValidateUserEmailDestination"
private const val uploadProgressDestinationName = "UploadProgressDestination"
private const val uploadSuccessDestinationName = "UploadSuccessDestination"
private const val uploadErrorDestinationName = "UploadErrorDestination"
private const val uploadIntegrityErrorDestinationName = "UploadIntegrityErrorDestination"
private const val newTransferFilesDetailsDestinationName = "NewTransferFilesDetailsDestination"
val newTransferDestinationsNames = listOf(
importFilesDestinationName,
ValidateUserEmailDestinationName,
UploadProgressDestinationName,
UploadSuccessDestinationName,
UploadErrorDestinationName,
UploadIntegrityErrorDestinationName,
NewTransferFilesDetailsDestinationName,
validateUserEmailDestinationName,
uploadProgressDestinationName,
uploadSuccessDestinationName,
uploadErrorDestinationName,
uploadIntegrityErrorDestinationName,
newTransferFilesDetailsDestinationName,
)

fun NavBackStackEntry.toNewTransferDestination(): NewTransferNavigation? {
return runCatching {
val destinationRoute = destination.route ?: error("Destination route cannot be empty")
when (newTransferDestinationsNames.firstOrNull(destinationRoute::contains)) {
importFilesDestinationName -> this.toRoute<ImportFilesDestination>()
ValidateUserEmailDestinationName -> this.toRoute<ValidateUserEmailDestination>()
UploadProgressDestinationName -> this.toRoute<UploadProgressDestination>()
UploadSuccessDestinationName -> this.toRoute<UploadSuccessDestination>()
UploadErrorDestinationName -> this.toRoute<UploadErrorDestination>()
UploadIntegrityErrorDestinationName -> this.toRoute<UploadIntegrityErrorDestination>()
NewTransferFilesDetailsDestinationName -> this.toRoute<NewTransferFilesDetailsDestination>()
importFilesDestinationName -> toRoute<ImportFilesDestination>()
validateUserEmailDestinationName -> toRoute<ValidateUserEmailDestination>()
uploadProgressDestinationName -> toRoute<UploadProgressDestination>()
uploadSuccessDestinationName -> toRoute<UploadSuccessDestination>()
uploadErrorDestinationName -> toRoute<UploadErrorDestination>()
uploadIntegrityErrorDestinationName -> toRoute<UploadIntegrityErrorDestination>()
newTransferFilesDetailsDestinationName -> toRoute<NewTransferFilesDetailsDestination>()
else -> error("Destination $destinationRoute is not handled")
}
}.getOrElse { exception ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,37 @@
package com.infomaniak.swisstransfer

import com.infomaniak.swisstransfer.ui.navigation.MainNavigation
import com.infomaniak.swisstransfer.ui.navigation.NewTransferNavigation
import org.junit.Assert.assertNotNull
import org.junit.Test

class NavigationDestinationUnitTest {

/**
* Make sure that NavigationDestination names are not changed without changing the `entries` list, because of minification issue.
* Make sure that MainNavigationDestination names are not changed without changing the `entries` list,
* because of minification issue.
*/
@Test
fun check_destinations_names_are_correct() {
val destinationsNames = MainNavigation.Companion.destinationsNames
fun check_main_destinations_names_are_correct() {
val destinationsNames = MainNavigation.Companion.mainDestinationsNames
assertNotNull(destinationsNames.find { it == MainNavigation.SentDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == MainNavigation.ReceivedDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == MainNavigation.SettingsDestination::class.simpleName })
}

/**
* Make sure that NewTransferNavigationDestination names are not changed without changing the `entries` list,
* because of minification issue.
*/
@Test
fun check_new_transfer_destinations_names_are_correct() {
val destinationsNames = NewTransferNavigation.Companion.newTransferDestinationsNames
assertNotNull(destinationsNames.find { it == NewTransferNavigation.ImportFilesDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.ValidateUserEmailDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.UploadProgressDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.UploadSuccessDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.UploadIntegrityErrorDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.UploadIntegrityErrorDestination::class.simpleName })
assertNotNull(destinationsNames.find { it == NewTransferNavigation.NewTransferFilesDetailsDestination::class.simpleName })
}
}

0 comments on commit 679c103

Please sign in to comment.