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

Feat/authentication/UI #31

Merged
merged 16 commits into from
Oct 15, 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
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ android {
}
}


sonar {
properties {
property("sonar.projectKey", "periodpals_periodpals")
Expand Down Expand Up @@ -162,6 +163,8 @@ dependencies {
implementation(libs.androidx.lifecycle.runtime.ktx)
implementation(platform(libs.compose.bom))
implementation(libs.androidx.navigation.compose.v282)
implementation(libs.androidx.espresso.intents)
implementation(libs.androidx.espresso.core)

testImplementation(libs.junit)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
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 org.junit.Rule
import org.junit.Test

class SignInScreenTest {

@get:Rule val composeTestRule = createComposeRule()

@Test
fun signInScreen_displaysCorrectUI() {
// Set the content to the SignInScreen
composeTestRule.setContent { SignInScreen() }

// Check if the welcome text is displayed
composeTestRule.onNodeWithTag("signInScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInBackground").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInTitle").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInInstruction").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInEmail").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInPassword").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInPasswordVisibility").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInOrText").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInGoogleButton").assertIsDisplayed()
composeTestRule.onNodeWithTag("signInNotRegistered").assertIsDisplayed()
}

@Test
fun signInScreen_emailValidation_emptyEmail_showsError() {
composeTestRule.setContent { SignInScreen() }

// Click on the sign in button with empty fields
composeTestRule.onNodeWithTag("signInButton").performClick()

// Verify that the error message for email is displayed
composeTestRule.onNodeWithTag("signInEmailError").assertTextEquals("Email cannot be empty")
}

@Test
fun signInScreen_emailValidation_invalidEmail_showsError() {
composeTestRule.setContent { SignInScreen() }

// Enter an invalid email
composeTestRule.onNodeWithTag("signInEmail").performTextInput("invalidEmail")

// Click on the sign in button
composeTestRule.onNodeWithTag("signInButton").performClick()

// Verify that the error message for email is displayed
composeTestRule.onNodeWithTag("signInEmailError").assertTextEquals("Email must contain @")
}

@Test
fun signInScreen_passwordValidation_emptyPassword_showsError() {
composeTestRule.setContent { SignInScreen() }

// Enter a valid email
composeTestRule.onNodeWithTag("signInEmail").performTextInput("test@example.com")

// Click on the sign in button with empty password
composeTestRule.onNodeWithTag("signInButton").performClick()

// Verify that the error message for password is displayed
composeTestRule
.onNodeWithTag("signInPasswordError")
.assertTextEquals("Password cannot be empty")
}

@Test
fun signInScreen_signIn_successfulLogin() {
composeTestRule.setContent { SignInScreen() }

// Enter valid email and password
composeTestRule.onNodeWithTag("signInEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signInPassword").performTextInput("ValidPassword123")

// Click on the sign in button
composeTestRule.onNodeWithTag("signInButton").performClick()

// Check for a successful login Toast (mocking would be required here)
// Currently, you can't test Toast directly; you can use dependency injection or other methods
}

@Test
fun signInScreen_signIn_failsInvalidLogin() {
composeTestRule.setContent { SignInScreen() }

// Enter valid email and an invalid password
composeTestRule.onNodeWithTag("signInEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signInPassword").performTextInput("InvalidPassword")

// Click on the sign in button
composeTestRule.onNodeWithTag("signInButton").performClick()

// Check for a failed login Toast (mocking would be required here)
// You can set up your test to verify that the error message or Toast appears.
}

@Test
fun signInScreen_navigatesToSignUp() {
composeTestRule.setContent { SignInScreen() }

// Click on the "Not registered yet? Sign up here!" text
composeTestRule.onNodeWithTag("signInNotRegistered").performClick()

// Check for a navigation action (mocking would be required here)
// You would verify that the navigation to the sign-up screen is triggered.
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
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 org.junit.Rule
import org.junit.Test

class SignUpScreenTest {

@get:Rule val composeTestRule = createComposeRule()

@Test
fun signUpScreen_displaysCorrectUI() {
composeTestRule.setContent { SignUpScreen() }

// Assert visibility of UI elements
composeTestRule.onNodeWithTag("signUpScreen").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpBackground").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpTitle").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpInstruction").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpEmail").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpPassword").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpPasswordVisibility").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpConfirmText").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpConfirmPassword").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpConfirmVisibility").assertIsDisplayed()
composeTestRule.onNodeWithTag("signUpButton").assertIsDisplayed()
}

@Test
fun signUpScreen_emailValidation_emptyEmail_showsError() {
composeTestRule.setContent { SignUpScreen() }

// Attempt to sign up with an empty email
composeTestRule.onNodeWithTag("signUpButton").performClick()

// Assert the error message is displayed
composeTestRule.onNodeWithTag("signUpEmailError").assertTextEquals("Email cannot be empty")
}

@Test
fun signUpScreen_emailValidation_invalidEmail_showsError() {
composeTestRule.setContent { SignUpScreen() }

// Input an invalid email
composeTestRule.onNodeWithTag("signUpEmail").performTextInput("invalidEmail")
composeTestRule.onNodeWithTag("signUpButton").performClick()

// Assert the error message is displayed
composeTestRule.onNodeWithTag("signUpEmailError").assertTextEquals("Email must contain @")
}

@Test
fun signUpScreen_passwordValidation_emptyPassword_showsError() {
composeTestRule.setContent { SignUpScreen() }

// Input an email and attempt to sign up with an empty password
composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpButton").performClick()

// Assert the error message is displayed
composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password cannot be empty")
}

@Test
fun signUpScreen_passwordValidation_passwordTooShort_showsError() {
composeTestRule.setContent { SignUpScreen() }

composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("short")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("short")
composeTestRule.onNodeWithTag("signUpButton").performClick()

composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password must be at least 8 characters long")
}

@Test
fun signUpScreen_passwordValidation_passwordNoCapital_showsError() {
composeTestRule.setContent { SignUpScreen() }

composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("password")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("password")
composeTestRule.onNodeWithTag("signUpButton").performClick()

composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password must contain at least one capital letter")
}

@Test
fun signUpScreen_passwordValidation_passwordNoMinuscule_showsError() {
composeTestRule.setContent { SignUpScreen() }

composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("PASSWORD")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("PASSWORD")
composeTestRule.onNodeWithTag("signUpButton").performClick()

composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password must contain at least one lower case letter")
}

@Test
fun signUpScreen_passwordValidation_passwordNoNumber_showsError() {
composeTestRule.setContent { SignUpScreen() }

composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("Password")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("Password")
composeTestRule.onNodeWithTag("signUpButton").performClick()

composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password must contain at least one number")
}

@Test
fun signUpScreen_passwordValidation_passwordNoSpecial_showsError() {
composeTestRule.setContent { SignUpScreen() }

composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("Passw0rd")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("Passw0rd")
composeTestRule.onNodeWithTag("signUpButton").performClick()

composeTestRule
.onNodeWithTag("signUpPasswordError")
.assertTextEquals("Password must contain at least one special character")
}

@Test
fun signUpScreen_passwordValidation_passwordsDoNotMatch_showsError() {
composeTestRule.setContent { SignUpScreen() }

// Input an email and mismatched passwords
composeTestRule.onNodeWithTag("signUpEmail").performTextInput("test@example.com")
composeTestRule.onNodeWithTag("signUpPassword").performTextInput("Password123")
composeTestRule.onNodeWithTag("signUpConfirmPassword").performTextInput("Password456")
composeTestRule.onNodeWithTag("signUpButton").performClick()

// Assert the error message is displayed
composeTestRule.onNodeWithTag("signUpConfirmError").assertTextEquals("Passwords do not match")
}

@Test
fun signUpScreen_signUp_successfulRegistration() {
composeTestRule.setContent { SignUpScreen() }

// 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()

// 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
// TODO: Supabase integration for account creation
}
}
1 change: 0 additions & 1 deletion app/src/main/java/com/android/periodpals/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerIcon.Companion.Text
import androidx.compose.ui.unit.dp
import androidx.navigation.compose.rememberNavController
import com.android.periodpals.ui.navigation.NavigationActions
Expand Down
Loading
Loading