Skip to content

Commit

Permalink
Merge pull request #200 from PeriodPals/test/misc/end-to-end-M2
Browse files Browse the repository at this point in the history
Test/misc/end to end m2: EndToEnd for Sign-In and Edit Profile
  • Loading branch information
agonzalez-r authored Nov 15, 2024
2 parents 24eaebb + cbc880d commit 5e6e976
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package com.android.periodpals.endtoend

import android.util.Log
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.assertTextEquals
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onAllNodesWithTag
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.android.periodpals.MainActivity
import com.android.periodpals.resources.C.Tag.AuthenticationScreens
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.TopAppBar
import com.kaspersky.kaspresso.testcases.api.testcase.TestCase
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

private const val TAG = "EndToEnd2"
private const val TIMEOUT = 10000L // 10 seconds, adjust for slower devices, networks and CI

@RunWith(AndroidJUnit4::class)
class EndToEndM2 : TestCase() {
@get:Rule val composeTestRule = createComposeRule()
@get:Rule val activityRule = ActivityTestRule(MainActivity::class.java)

companion object {
private val randomNumber = (1..9).random()
private const val EMAIL = "end2end@test"
private const val PASSWORD = "Secure!password123"
private val name = "Mocknica$randomNumber"
private val dob = "0$randomNumber/01/2000"
private val description = "I'm a mathematician, my favourite number is $randomNumber!"
}

@Before
fun setUp() {
composeTestRule.setContent { MainActivity() }
}

@Test
fun signInAndEditProfile() {
// Sign in using existing account
composeTestRule.waitForIdle()
Log.d(TAG, "User arrives on SignIn Screen")
composeTestRule.onNodeWithTag(SignInScreen.SCREEN).assertExists() // or is displayed?
composeTestRule
.onNodeWithTag(AuthenticationScreens.EMAIL_FIELD)
.assertIsDisplayed()
.performTextInput(EMAIL)
composeTestRule
.onNodeWithTag(AuthenticationScreens.PASSWORD_FIELD)
.assertIsDisplayed()
.performTextInput(PASSWORD)
composeTestRule.onNodeWithTag(SignInScreen.SIGN_IN_BUTTON).assertIsDisplayed().performClick()
composeTestRule.waitUntil(TIMEOUT) {
composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1
}

// Profile Screen is displayed
composeTestRule.waitForIdle()
Log.d(TAG, "User arrives on Profile Screen")
composeTestRule.onNodeWithTag(TopAppBar.EDIT_BUTTON).assertIsDisplayed().performClick()
composeTestRule.waitUntil(TIMEOUT) {
composeTestRule.onAllNodesWithTag(EditProfileScreen.SCREEN).fetchSemanticsNodes().size == 1
}

// Edit Profile Screen is displayed, edit name, dob and description
composeTestRule.waitForIdle()
Log.d(TAG, "User arrives on Edit Profile Screen")
composeTestRule
.onNodeWithTag(ProfileScreens.NAME_INPUT_FIELD)
.assertIsDisplayed()
.performTextInput(name)
composeTestRule
.onNodeWithTag(ProfileScreens.DOB_INPUT_FIELD)
.assertIsDisplayed()
.performTextInput(dob)
composeTestRule
.onNodeWithTag(ProfileScreens.DESCRIPTION_INPUT_FIELD)
.assertIsDisplayed()
.performTextInput(description)
composeTestRule.onNodeWithTag(ProfileScreens.SAVE_BUTTON).assertIsDisplayed().performClick()
composeTestRule.waitUntil(TIMEOUT) {
composeTestRule.onAllNodesWithTag(ProfileScreen.SCREEN).fetchSemanticsNodes().size == 1
}

// Profile Screen, check if the changes are saved
composeTestRule.waitForIdle()
Log.d(TAG, "User arrives on Profile Screen")
composeTestRule.onNodeWithTag(ProfileScreen.NAME_FIELD).assertExists().assertTextEquals(name)
composeTestRule
.onNodeWithTag(ProfileScreen.DESCRIPTION_FIELD)
.assertExists()
.assertTextEquals(description)
}
}

0 comments on commit 5e6e976

Please sign in to comment.