Skip to content

Commit

Permalink
Merge pull request #58 from PeriodPals/test/flow
Browse files Browse the repository at this point in the history
fix: resolve navigation and sign-in and sign-up flows
  • Loading branch information
francelu authored Oct 18, 2024
2 parents 068a13c + 04d8a69 commit 2feb0e8
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 52 deletions.
Original file line number Diff line number Diff line change
@@ -1,36 +1,23 @@
package com.android.periodpals.ui.authentication
// package com.android.periodpals.ui.authentication
//
// import androidx.compose.ui.test.assertIsDisplayed
// import androidx.compose.ui.test.assertTextEquals
// import androidx.compose.ui.test.junit4.createComposeRule
// import androidx.compose.ui.test.onNodeWithTag
// import androidx.compose.ui.test.performClick
// import androidx.compose.ui.test.performTextInput
// import com.android.periodpals.model.auth.AuthViewModel
// import io.github.jan.supabase.SupabaseClient
// import org.junit.Before
// import androidx.navigation.compose.rememberNavController
// import com.android.periodpals.ui.navigation.NavigationActions
// import org.junit.Rule
// import org.junit.Test
// import org.mockito.Mockito.mock
//
// class SignUpScreenTest {
//
// @get:Rule val composeTestRule = createComposeRule()
// lateinit var authViewModel: AuthViewModel
// lateinit var supabaseClient: SupabaseClient
//
// @Before
// fun setUp() {
// authViewModel = mock(AuthViewModel::class.java)
// supabaseClient = mock(SupabaseClient::class.java)
// }
//
// @Test
// fun signUpScreen_displaysCorrectUI() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Assert visibility of UI elements
// composeTestRule.onNodeWithTag("signUpScreen").assertIsDisplayed()
Expand All @@ -48,8 +35,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_emailValidation_emptyEmail_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Attempt to sign up with an empty email
// composeTestRule.onNodeWithTag("signUpButton").performClick()
Expand All @@ -60,8 +46,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_emailValidation_invalidEmail_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Input an invalid email
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("invalidEmail")
Expand All @@ -73,8 +58,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_emptyPassword_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Input an email and attempt to sign up with an empty password
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
Expand All @@ -88,8 +72,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordTooShort_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("short")
Expand All @@ -103,8 +86,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordNoCapital_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("password")
Expand All @@ -118,8 +100,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordNoMinuscule_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("PASSWORD")
Expand All @@ -133,8 +114,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordNoNumber_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("Password")
Expand All @@ -148,8 +128,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordNoSpecial_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("Passw0rd")
Expand All @@ -163,8 +142,7 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_passwordValidation_passwordsDoNotMatch_showsError() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Input an email and mismatched passwords
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
Expand All @@ -178,14 +156,14 @@ package com.android.periodpals.ui.authentication
//
// @Test
// fun signUpScreen_signUp_successfulRegistration() {
// composeTestRule.setContent { SignUpScreen(authViewModel,
// NavigationActions(rememberNavController())) }
// composeTestRule.setContent { SignUpScreen(NavigationActions(rememberNavController())) }
//
// // Input valid data and perform sign up
// composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
// composeTestRule.onNodeWithTag("signUpPassword").performTextInput("ValidPassword123!")
// composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("ValidPassword123!")
// composeTestRule.onNodeWithTag("signUpButton").performClick()
// // Cannot test navigation actions currently
// // composeTestRule.onNodeWithTag("signUpButton").performClick()
//
// // You can assert here for a visual change or a Toast message if possible
// // Since Toast can't be tested directly, consider an alternative for future testing
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@ fun PeriodPalsApp(locationPermissionGranted: Boolean, authViewModel: AuthViewMod

NavHost(navController = navController, startDestination = Route.AUTH) {
// Authentication
navigation(startDestination = Screen.AUTH, route = Route.AUTH) {
composable(Screen.AUTH) { SignInScreen(authViewModel, navigationActions) }
composable(Screen.REGISTER) { SignUpScreen(authViewModel, navigationActions) }
navigation(
startDestination = Screen.SIGN_IN,
route = Route.AUTH,
) {
composable(Screen.SIGN_IN) { SignInScreen(authViewModel, navigationActions) }
composable(Screen.SIGN_UP) { SignUpScreen(authViewModel, navigationActions) }
composable(Screen.CREATE_PROFILE) { CreateProfileScreen(navigationActions) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ fun MyAlerts() {
verticalArrangement = Arrangement.spacedBy(20.dp)) {
// TODO: Display the items in a LazyColum or the NoAlertDialog if there aren't any
AlertItem()
// NoAlertDialog()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ fun SignInScreen(authViewModel: AuthViewModel, navigationActions: NavigationActi
.padding(24.dp)) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterVertically)) {
verticalArrangement = Arrangement.spacedBy(8.dp, Alignment.CenterVertically)) {
// Sign in instruction
AuthInstruction(
text = "Sign in to your account", testTag = "signInInstruction")
Expand Down Expand Up @@ -195,10 +195,7 @@ fun SignInScreen(authViewModel: AuthViewModel, navigationActions: NavigationActi
annotatedText
.getStringAnnotations(tag = "SignUp", start = offset, end = offset)
.firstOrNull()
?.let {
Toast.makeText(context, "Yay! I'm waiting for navigation", Toast.LENGTH_SHORT)
.show()
}
?.let { navigationActions.navigateTo(Screen.SIGN_UP) }
})
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ import com.android.periodpals.ui.theme.Pink40
import com.android.periodpals.ui.theme.Purple40
import com.android.periodpals.ui.theme.PurpleGrey80

private const val TAG = "SignUpScreen"

@Composable
fun SignUpScreen(authViewModel: AuthViewModel, navigationActions: NavigationActions) {
val context = LocalContext.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ object Route {
}

object Screen {
const val AUTH = "Auth Screen"
const val SIGN_IN = "Auth Screen"
const val ALERT = "Alert Screen"
const val ALERT_LIST = "AlertList Screen"
const val MAP = "Map Screen"
const val TIMER = "Timer Screen"
const val PROFILE = "Profile Screen"
const val REGISTER = "Register Screen"
const val SIGN_UP = "Register Screen"
const val CREATE_PROFILE = "CreateProfile Screen"
const val EDIT_PROFILE = "EditProfile Screen"
// TODO: Add as app is being built
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class NavigationActionsTest {
*/
@Test
fun navigateToAuthScreens() {
navigationActions.navigateTo(Screen.AUTH)
verify(navHostController).navigate(Screen.AUTH)
navigationActions.navigateTo(Screen.REGISTER)
verify(navHostController).navigate(Screen.REGISTER)
navigationActions.navigateTo(Screen.SIGN_IN)
verify(navHostController).navigate(Screen.SIGN_IN)
navigationActions.navigateTo(Screen.SIGN_UP)
verify(navHostController).navigate(Screen.SIGN_UP)
navigationActions.navigateTo(Screen.CREATE_PROFILE)
verify(navHostController).navigate(Screen.CREATE_PROFILE)
}
Expand Down

0 comments on commit 2feb0e8

Please sign in to comment.