Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor map to sky map #291

Merged
merged 13 commits into from
Dec 18, 2024
Merged
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 @@ -121,7 +121,7 @@ class End2EndTest {
composeTestRule.onNodeWithTag("menu_screen").assertIsDisplayed()

// Step 5: Navigate to MapScreen from MenuScreen
composeTestRule.onNodeWithText("Map").performClick()
composeTestRule.onNodeWithText("Sky Map").performClick()
composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag("map_screen").assertIsDisplayed()
composeTestRule.onNodeWithTag(TopLevelDestinations.MENU.textId).performClick()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ class MapKtTest {
@Test
fun mapScreen_bottomNavigation_clickMapTab_doesNotNavigateToMap() {
// Click on the "Map" tab
composeTestRule.onNodeWithTag("Map").performClick()
composeTestRule.onNodeWithTag("Sky Map").performClick()

val mapDestination = LIST_TOP_LEVEL_DESTINATION.first { it.textId == "Map" }
val mapDestination = LIST_TOP_LEVEL_DESTINATION.first { it.textId == "Sky Map" }

// Verify that navigation to the Map screen does NOT occur
verify(mockNavigationActions, never()).navigateTo(mapDestination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class LandingKtTest {
composeTestRule.waitForIdle()

// Assert that the Map screen is displayed by checking for specific text or UI elements
verify(mockNavigationActions).navigateTo(Screen.MAP)
verify(mockNavigationActions).navigateTo(Screen.SKY_MAP)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ class MenuKtTest {
}

// Click on the Map tab
composeTestRule.onNodeWithTag("Map").performClick()
composeTestRule.onNodeWithTag("Sky Map").performClick()

val mapDestination = LIST_TOP_LEVEL_DESTINATION.first { it.textId == "Map" }
val mapDestination = LIST_TOP_LEVEL_DESTINATION.first { it.textId == "Sky Map" }

// Verify that navigation to the Map screen is triggered with the correct object
verify(mockNavigationActions).navigateTo(mapDestination)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ class ProfileKtTest {
}

// Ensure that the "Map" and "Menu" tabs are still displayed even if the route is empty
composeTestRule.onNodeWithText(getResourceString(R.string.map)).assertExists()
composeTestRule.onNodeWithText(getResourceString(R.string.sky_map)).assertExists()
composeTestRule.onNodeWithText(getResourceString(R.string.menu)).assertExists()

// Verify that currentRoute() was called
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ fun LookUpApp() {
composable(Screen.LOGIN) { LoginScreen(loginViewModel, navigationActions) }
composable(Screen.REGISTER) { RegisterScreen(navigationActions, registerViewModel) }
}
navigation(startDestination = Screen.MAP, route = Route.MAP) {
composable(Screen.MAP) { MapScreen(navigationActions, mapViewModel) }
navigation(startDestination = Screen.SKY_MAP, route = Route.SKY_MAP) {
composable(Screen.SKY_MAP) { MapScreen(navigationActions, mapViewModel) }
}
navigation(
startDestination = Screen.LANDING,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fun MapScreen(navigationActions: NavigationActions, mapViewModel: MapViewModel)
onTabSelect = { destination -> navigationActions.navigateTo(destination) },
tabList = LIST_TOP_LEVEL_DESTINATION,
isUserLoggedIn = isUserLoggedIn,
selectedItem = Route.MAP)
selectedItem = Route.SKY_MAP)
}) { innerPadding ->
if (locationProvider.currentLocation.value != null) {
Box(modifier = Modifier.fillMaxSize().padding(innerPadding).testTag("map_screen")) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.github.lookupgroup27.lookup.ui.navigation

import android.widget.Toast
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Icon
import androidx.compose.material3.NavigationBar
Expand All @@ -12,8 +14,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp

@Composable
Expand All @@ -30,7 +34,22 @@ fun BottomNavigationMenu(
content = {
tabList.forEach { tab ->
NavigationBarItem(
icon = { Icon(tab.icon, contentDescription = null, tint = Color.White) },
icon = {
// Load the correct icon based on the type (ImageVector or Painter)
when {
tab.iconVector != null ->
Icon(
imageVector = tab.iconVector,
contentDescription = null,
tint = Color.White)
tab.iconResource != null ->
Image(
painter = painterResource(id = tab.iconResource),
contentDescription = null,
modifier = Modifier.size(34.dp),
colorFilter = ColorFilter.tint(Color.White))
}
},
label = { Text(text = tab.textId, color = Color.White) },
selected = tab.route == selectedItem,
onClick = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package com.github.lookupgroup27.lookup.ui.navigation
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.List
import androidx.compose.material.icons.outlined.Menu
import androidx.compose.material.icons.outlined.Place
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.navigation.NavGraph.Companion.findStartDestination
import androidx.navigation.NavHostController
import com.github.lookupgroup27.lookup.R

object Route {
const val AUTH = "Auth"
const val LANDING = "Landing"
const val MAP = "Map"
const val SKY_MAP = "SkyMap"
const val CALENDAR = "Calendar"
const val GOOGLE_MAP = "Google Map"
const val QUIZ = "Quiz"
Expand All @@ -33,7 +33,7 @@ object Route {
object Screen {
const val AUTH = "Auth Screen"
const val LANDING = "Landing Screen"
const val MAP = "Map Screen"
const val SKY_MAP = "Sky Map Screen"
const val CALENDAR = "Calendar Screen"
const val GOOGLE_MAP = "Google Map Screen"
const val QUIZ = "Quiz Screen"
Expand All @@ -52,16 +52,25 @@ object Screen {
const val EDIT_IMAGE = "Edit Image"
}

data class TopLevelDestination(val route: String, val icon: ImageVector, val textId: String)
data class TopLevelDestination(
val route: String,
val iconVector: ImageVector? = null, // For ImageVector icons
val iconResource: Int? = null, // For PainterResource drawable icons
val textId: String
)

object TopLevelDestinations {
val MENU = TopLevelDestination(route = Route.MENU, icon = Icons.Outlined.Menu, textId = "Menu")
val MAP = TopLevelDestination(route = Route.MAP, icon = Icons.Outlined.Place, textId = "Map")
val FEED = TopLevelDestination(route = Route.FEED, icon = Icons.Outlined.List, textId = "Feed")
val MENU =
TopLevelDestination(route = Route.MENU, iconVector = Icons.Outlined.Menu, textId = "Menu")
val SKY_MAP =
TopLevelDestination(
route = Route.SKY_MAP, iconResource = R.drawable.skymap_icon, textId = "Sky Map")
val FEED =
TopLevelDestination(route = Route.FEED, iconVector = Icons.Outlined.List, textId = "Feed")
}

val LIST_TOP_LEVEL_DESTINATION =
listOf(TopLevelDestinations.MENU, TopLevelDestinations.MAP, TopLevelDestinations.FEED)
listOf(TopLevelDestinations.MENU, TopLevelDestinations.SKY_MAP, TopLevelDestinations.FEED)

open class NavigationActions(
private val navController: NavHostController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun LandingScreen(navigationActions: NavigationActions) {
BoxWithConstraints(
modifier =
Modifier.fillMaxSize().testTag("LandingScreen").clickable {
navigationActions.navigateTo(Screen.MAP)
navigationActions.navigateTo(Screen.SKY_MAP)
}) {
// Background Image
BackgroundImage(
Expand Down
Binary file added app/src/main/res/drawable/skymap_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<string name="profile_change_avatar">Change Avatar</string>
<string name="profile_personal_info_button">Personal Info ></string>
<string name="profile_collection_button">Your Collection ></string>
<string name="map">Map</string>
<string name="sky_map">Sky Map</string>
<string name="menu">Menu</string>
<string name="map_button_reset_text">Reset</string>
<string name="map_slider_test_tag">map_slider_tag</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ class NavigationActionsTest {
@Test
fun navigateToCallsController() {
// Test navigating to top-level destinations
navigationActions.navigateTo(TopLevelDestinations.MAP)
verify(navHostController).navigate(eq(Route.MAP), any<NavOptionsBuilder.() -> Unit>())
navigationActions.navigateTo(TopLevelDestinations.SKY_MAP)
verify(navHostController).navigate(eq(Route.SKY_MAP), any<NavOptionsBuilder.() -> Unit>())

navigationActions.navigateTo(TopLevelDestinations.MENU)
verify(navHostController).navigate(eq(Route.MENU), any<NavOptionsBuilder.() -> Unit>())
Expand Down Expand Up @@ -70,16 +70,16 @@ class NavigationActionsTest {
@Test
fun topLevelDestinationsListIsCorrect() {
val expectedList =
listOf(TopLevelDestinations.MENU, TopLevelDestinations.MAP, TopLevelDestinations.FEED)
listOf(TopLevelDestinations.MENU, TopLevelDestinations.SKY_MAP, TopLevelDestinations.FEED)
assertThat(LIST_TOP_LEVEL_DESTINATION, `is`(expectedList))
}

@Test
fun navigateToTopLevelDestinationSetsCorrectOptions() {
val optionsCaptor = argumentCaptor<NavOptionsBuilder.() -> Unit>()

navigationActions.navigateTo(TopLevelDestinations.MAP)
verify(navHostController).navigate(eq(Route.MAP), optionsCaptor.capture())
navigationActions.navigateTo(TopLevelDestinations.SKY_MAP)
verify(navHostController).navigate(eq(Route.SKY_MAP), optionsCaptor.capture())

val navOptionsBuilder = NavOptionsBuilder().apply(optionsCaptor.firstValue)
assertThat(navOptionsBuilder.launchSingleTop, `is`(true))
Expand Down
Loading