Skip to content

Commit

Permalink
test: delete accounts using UI in e2e
Browse files Browse the repository at this point in the history
  • Loading branch information
francelu committed Dec 20, 2024
1 parent 96c8aa0 commit d76e77e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 100 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.android.periodpals.resources.C.Tag.AuthenticationScreens.SignInScreen
import com.android.periodpals.resources.C.Tag.ProfileScreens
import com.android.periodpals.resources.C.Tag.ProfileScreens.EditProfileScreen
import com.android.periodpals.resources.C.Tag.ProfileScreens.ProfileScreen
import com.android.periodpals.resources.C.Tag.SettingsScreen
import com.android.periodpals.resources.C.Tag.TopAppBar
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import io.github.jan.supabase.SupabaseClient
Expand All @@ -35,7 +36,6 @@ import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.storage.Storage
import java.util.concurrent.TimeUnit
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -125,26 +125,26 @@ class EndToEndProfile : TestCase() {
)
}

@After
fun tearDown() = runBlocking {
authenticationViewModel.loadAuthenticationUserData(
onSuccess = {
Log.d(TAG, "Successfully loaded user data")
authenticationViewModel.logOut(
onSuccess = {
Log.d(TAG, "Successfully logged out")
userViewModel.deleteUser(
idUser = authenticationViewModel.authUserData.value?.uid ?: "",
onSuccess = { Log.d(TAG, "Successfully deleted user") },
onFailure = { e: Exception -> Log.e(TAG, "Failed to delete user: $e") },
)
},
onFailure = { e: Exception -> Log.e(TAG, "Failed to log out: $e") },
)
},
onFailure = { e: Exception -> Log.e(TAG, "Failed to load user data: $e") },
)
}
// @After
// fun tearDown() = runBlocking {
// authenticationViewModel.loadAuthenticationUserData(
// onSuccess = {
// Log.d(TAG, "Successfully loaded user data")
// authenticationViewModel.logOut(
// onSuccess = {
// Log.d(TAG, "Successfully logged out")
// userViewModel.deleteUser(
// idUser = authenticationViewModel.authUserData.value?.uid ?: "",
// onSuccess = { Log.d(TAG, "Successfully deleted user") },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to delete user: $e") },
// )
// },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to log out: $e") },
// )
// },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to load user data: $e") },
// )
// }

/**
* End-to-end test for the
Expand Down Expand Up @@ -280,58 +280,37 @@ class EndToEndProfile : TestCase() {
.assertIsDisplayed()
.assertTextEquals(EDIT_DESCRIPTION)
}
step("User navigates to Settings Screen to delete their account") {
composeTestRule.onNodeWithTag(TopAppBar.SETTINGS_BUTTON).assertIsDisplayed().performClick()

composeTestRule.waitForIdle()
composeTestRule.waitUntil(TIMEOUT) {
try {
composeTestRule.onAllNodesWithTag(SettingsScreen.SCREEN).fetchSemanticsNodes().size == 1
} catch (e: AssertionError) {
false
}
}
composeTestRule.onNodeWithTag(SettingsScreen.SCREEN).assertIsDisplayed()

// step("User navigates to Settings Screen to delete their account") {
//
// composeTestRule.onNodeWithTag(TopAppBar.SETTINGS_BUTTON).assertIsDisplayed().performClick()
//
// composeTestRule.waitForIdle()
// composeTestRule.waitUntil(TIMEOUT) {
// try {
// composeTestRule.onAllNodesWithTag(SettingsScreen.SCREEN).fetchSemanticsNodes().size
// == 1
// } catch (e: AssertionError) {
// false
// }
// }
// composeTestRule.onNodeWithTag(SettingsScreen.SCREEN).assertIsDisplayed()
//
// Log.d(TAG, "User arrives on Settings Screen")
// composeTestRule
// .onNodeWithTag(SettingsScreen.DELETE_ACCOUNT_ICON)
// .performScrollTo()
// .assertIsDisplayed()
// .performClick()
//
// composeTestRule.waitUntil(TIMEOUT) {
// try {
// composeTestRule
// .onAllNodesWithTag(SettingsScreen.DELETE_ACCOUNT_CARD)
// .fetchSemanticsNodes()
// .size == 1
// } catch (e: AssertionError) {
// false
// }
// }
//
// step("User confirms deletion of their account") {
// composeTestRule.waitForIdle()
// composeTestRule
// .onNodeWithTag(SettingsScreen.DELETE_BUTTON)
// .assertIsDisplayed()
// .performClick()
//
// composeTestRule.waitUntil(TIMEOUT) {
// try {
// composeTestRule.onAllNodesWithTag(SignInScreen.SCREEN).fetchSemanticsNodes().size
// == 1
// } catch (e: AssertionError) {
// false
// }
// }
//
// composeTestRule.waitForIdle()
// }
// }
Log.d(TAG, "User arrives on Settings Screen")
composeTestRule
.onNodeWithTag(SettingsScreen.DELETE_ACCOUNT_ICON)
.performScrollTo()
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(SettingsScreen.DELETE_BUTTON).assertIsDisplayed().performClick()
}

step("User is lead back to the Sign In Screen") {
composeTestRule.waitForIdle()
composeTestRule.waitUntil(TIMEOUT) {
try {
composeTestRule.onAllNodesWithTag(SignInScreen.SCREEN).fetchSemanticsNodes().size == 1
} catch (e: AssertionError) {
false
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import io.github.jan.supabase.createSupabaseClient
import io.github.jan.supabase.postgrest.Postgrest
import io.github.jan.supabase.storage.Storage
import kotlinx.coroutines.runBlocking
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
Expand Down Expand Up @@ -120,26 +119,26 @@ class EndToEndSignIn : TestCase() {
)
}

@After
fun tearDown() = runBlocking {
authenticationViewModel.loadAuthenticationUserData(
onSuccess = {
Log.d(TAG, "Successfully loaded user data")
authenticationViewModel.logOut(
onSuccess = {
Log.d(TAG, "Successfully logged out")
userViewModel.deleteUser(
idUser = authenticationViewModel.authUserData.value?.uid ?: "",
onSuccess = { Log.d(TAG, "Successfully deleted user") },
onFailure = { e: Exception -> Log.e(TAG, "Failed to delete user: $e") },
)
},
onFailure = { e: Exception -> Log.e(TAG, "Failed to log out: $e") },
)
},
onFailure = { e: Exception -> Log.e(TAG, "Failed to load user data: $e") },
)
}
// @After
// fun tearDown() = runBlocking {
// authenticationViewModel.loadAuthenticationUserData(
// onSuccess = {
// Log.d(TAG, "Successfully loaded user data")
// authenticationViewModel.logOut(
// onSuccess = {
// Log.d(TAG, "Successfully logged out")
// userViewModel.deleteUser(
// idUser = authenticationViewModel.authUserData.value?.uid ?: "",
// onSuccess = { Log.d(TAG, "Successfully deleted user") },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to delete user: $e") },
// )
// },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to log out: $e") },
// )
// },
// onFailure = { e: Exception -> Log.e(TAG, "Failed to load user data: $e") },
// )
// }

/**
* End-to-end test for the
Expand Down Expand Up @@ -219,9 +218,18 @@ class EndToEndSignIn : TestCase() {
.performScrollTo()
.assertIsDisplayed()
.performClick()

composeTestRule.onNodeWithTag(SettingsScreen.DELETE_BUTTON).assertIsDisplayed().performClick()
}

step("User is lead back to the Sign In Screen") {
composeTestRule.waitForIdle()
composeTestRule.waitUntil(TIMEOUT) {
try {
composeTestRule.onAllNodesWithTag(SignInScreen.SCREEN).fetchSemanticsNodes().size == 1
} catch (e: AssertionError) {
false
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,15 @@ class EndToEndSignUp : TestCase() {
val authenticationModel = AuthenticationModelSupabase(supabaseClient)
authenticationViewModel = AuthenticationViewModel(authenticationModel)

authenticationViewModel.logOut(
onSuccess = { Log.d(TAG, "setUp: successfully logged out") },
onFailure = { Log.d(TAG, "setUp: failed to log out: ${it.message}") },
authenticationViewModel.isUserLoggedIn(
onSuccess = {
Log.d(TAG, "setUp: user is already logged in")
authenticationViewModel.logOut(
onSuccess = { Log.d(TAG, "setUp: successfully logged out") },
onFailure = { Log.d(TAG, "setUp: failed to log out: ${it.message}") },
)
},
onFailure = { Log.d(TAG, "setUp: failed to check if user is logged in: ${it.message}") },
)
}

Expand Down Expand Up @@ -213,11 +219,11 @@ class EndToEndSignUp : TestCase() {
.performScrollTo()
.assertIsDisplayed()
.assertTextEquals(DESCRIPTION)

composeTestRule.onNodeWithTag(TopAppBar.SETTINGS_BUTTON).assertIsDisplayed().performClick()
}

step("User navigates to Settings Screen to delete their account") {
composeTestRule.onNodeWithTag(TopAppBar.SETTINGS_BUTTON).assertIsDisplayed().performClick()

composeTestRule.waitForIdle()
composeTestRule.waitUntil(TIMEOUT) {
try {
Expand All @@ -235,7 +241,17 @@ class EndToEndSignUp : TestCase() {
.assertIsDisplayed()
.performClick()
composeTestRule.onNodeWithTag(SettingsScreen.DELETE_BUTTON).assertIsDisplayed().performClick()
}

step("User is lead back to the Sign In Screen") {
composeTestRule.waitForIdle()
composeTestRule.waitUntil(TIMEOUT) {
try {
composeTestRule.onAllNodesWithTag(SignInScreen.SCREEN).fetchSemanticsNodes().size == 1
} catch (e: AssertionError) {
false
}
}
}
}
}

0 comments on commit d76e77e

Please sign in to comment.