Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,6 @@ internal fun NavGraphBuilder.wearOnboarding(
}

navigation<WearOnboardingRoute>(startDestination = startRoute) {
// TODO discovery should be able to add existing system
commonScreens(navController = navController, wearNameToOnboard = wearNameToOnboard)
nameYourWearDeviceScreen(
onBackClick = navController::popBackStack,
Expand Down Expand Up @@ -451,6 +450,5 @@ internal fun NavGraphBuilder.wearOnboarding(
},
onNext = onOnboardingDone,
)
// TODO: Consider making auth_code a value class to prevent string parameter mismatches
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it (I have a stash with the changes). I've used a value class in the AuthRepository to enforce a strong type but then this types is not properly use by the navigation library and it needs a custom NavType mapping which I don't like.

I hope this is going to work in nav3 let see, for now I'm going to keep it like this.

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import androidx.navigation.toRoute
import dagger.hilt.android.lifecycle.HiltViewModel
import io.homeassistant.companion.android.database.sensor.SensorDao
import io.homeassistant.companion.android.onboarding.locationsharing.navigation.LocationSharingRoute
import io.homeassistant.companion.android.sensors.LocationSensorManager
import javax.inject.Inject
import kotlinx.coroutines.launch
import timber.log.Timber
Expand All @@ -29,10 +30,9 @@ internal class LocationSharingViewModel @VisibleForTesting constructor(
try {
sensorDao.setSensorsEnabled(
sensorIds = listOf(
// TODO add sensor ID from `LocationSensorManager` instead of string
"location_background",
"zone_background",
"accurate_location",
LocationSensorManager.backgroundLocation.id,
LocationSensorManager.zoneLocation.id,
LocationSensorManager.singleAccurateLocation.id,
),
serverId = serverId,
enabled = enabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ private fun ServerUrlTextField(
if (isError) {
Text(
text = stringResource(commonR.string.manual_server_wrong_url),
// TODO probably wrong style and color/token
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All TODOs regarding the color and sytle have been removed since the design team won't have time for us and for now it looks ok. We are going to need a more general change over the app later at least for the typographie.

style = HATextStyle.BodyMedium.copy(color = LocalHAColorScheme.current.colorBorderDangerNormal),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,7 @@ private fun OneServerFound(
imageVector = Icons.Default.Storage,
contentDescription = null,
modifier = Modifier
.size(ICON_SIZE), // TODO double check the size of the icon within the modal
// TODO change the color with proper token
.size(ICON_SIZE),
tint = LocalHAColorScheme.current.colorFillPrimaryLoudResting,
)
Text(
Expand Down Expand Up @@ -384,7 +383,7 @@ private fun AnimatedIcon() {
.size(80.dp)
.scale(pulse)
.align(Alignment.Center)
.background(HABrandColors.Blue, CircleShape), // TODO we might want to use a semantic token?
.background(HABrandColors.Blue, CircleShape),
) {
Icon(
imageVector = ImageVector.vectorResource(commonR.drawable.ic_stat_ic_notification_blue),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package io.homeassistant.companion.android.onboarding

import android.content.pm.PackageManager
import androidx.activity.compose.LocalActivityResultRegistryOwner
import androidx.activity.result.ActivityResultRegistry
import androidx.activity.result.ActivityResultRegistryOwner
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.core.content.ContextCompat
import androidx.navigation.NavController
import androidx.navigation.compose.ComposeNavigator
import androidx.navigation.compose.NavHost
import androidx.navigation.testing.TestNavHostController
import dagger.hilt.android.testing.HiltAndroidRule
import io.homeassistant.companion.android.HiltComponentActivity
import io.homeassistant.companion.android.testing.unit.ConsoleLogRule
import io.homeassistant.companion.android.util.LocationPermissionActivityResultRegistry
import io.homeassistant.companion.android.util.compose.navigateToUri
import io.mockk.Runs
import io.mockk.every
import io.mockk.just
import io.mockk.mockkStatic
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule

/**
* Base class for onboarding navigation tests providing shared setup, mocks, and utilities.
*
* Subclasses should extend this class and use [testNavigation] to set up the navigation
* test environment with the onboarding flow.
*/
internal abstract class BaseOnboardingNavigationTest {

@get:Rule(order = 0)
var consoleLog = ConsoleLogRule()

@get:Rule(order = 1)
val hiltRule = HiltAndroidRule(this)

@get:Rule(order = 2)
val composeTestRule = createAndroidComposeRule<HiltComponentActivity>()

protected lateinit var navController: TestNavHostController

protected var onboardingDone = false

@Before
fun baseSetup() {
mockkStatic(NavController::navigateToUri)
every { any<NavController>().navigateToUri(any()) } just Runs
}

protected fun setContent(
urlToOnboard: String? = null,
hideExistingServers: Boolean = false,
skipWelcome: Boolean = false,
hasLocationTracking: Boolean = true,
) {
composeTestRule.setContent {
navController = TestNavHostController(LocalContext.current)
navController.navigatorProvider.addNavigator(ComposeNavigator())

CompositionLocalProvider(
LocalActivityResultRegistryOwner provides object : ActivityResultRegistryOwner {
override val activityResultRegistry: ActivityResultRegistry =
LocationPermissionActivityResultRegistry(true)
},
) {
NavHost(
navController = navController,
startDestination = OnboardingRoute(hasLocationTracking = true),
) {
onboarding(
navController,
onShowSnackbar = { _, _ -> true },
onOnboardingDone = {
onboardingDone = true
},
urlToOnboard = urlToOnboard,
hideExistingServers = hideExistingServers,
skipWelcome = skipWelcome,
hasLocationTracking = hasLocationTracking,
)
}
}
}
}

protected fun testNavigation(
urlToOnboard: String? = null,
hideExistingServers: Boolean = false,
skipWelcome: Boolean = false,
hasLocationTracking: Boolean = true,
testContent: suspend AndroidComposeTestRule<*, *>.() -> Unit,
) {
setContent(
urlToOnboard = urlToOnboard,
hideExistingServers = hideExistingServers,
skipWelcome = skipWelcome,
hasLocationTracking = hasLocationTracking,
)
runTest {
composeTestRule.testContent()
}
}

protected fun mockCheckPermission(grant: Boolean) {
mockkStatic(ContextCompat::class)
every {
ContextCompat.checkSelfPermission(any(), any())
} returns if (grant) PackageManager.PERMISSION_GRANTED else PackageManager.PERMISSION_DENIED
}
}
Loading
Loading