-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #200 from PeriodPals/test/misc/end-to-end-M2
Test/misc/end to end m2: EndToEnd for Sign-In and Edit Profile
- Loading branch information
Showing
1 changed file
with
104 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
app/src/androidTest/java/com/android/periodpals/endtoend/EndToEndM2.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |