Skip to content

Fixed tests so that they expect button to the disabled #1098 #1099

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

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,14 @@ class LoginActivityTest {
* with:
* username: EMPTY
* password: EMPTY
* expected: Empty username and password error
* expected: Login button disabled
*/
@Test
fun testLoginButtonClickedWhenUsernameAndPasswordAreEmpty() {
enterCredentials("", "")

// Checks that the error message in both the editTexts appears after button click
onView(withId(R.id.tiUsername)).check(matches(hasTextInputLayoutErrorText(EMPTY_USERNAME_ERROR)))
onView(withId(R.id.tiPassword)).check(matches(hasTextInputLayoutErrorText(EMPTY_PASSWORD_ERROR)))
// Checks that the login button is disabled
onView(withId(R.id.btnLogin)).check(matches(not(isEnabled())))

}

Expand All @@ -133,31 +132,28 @@ class LoginActivityTest {
* with:
* username: EMPTY
* password: PRESENT
* expected : Empty username error
* expected : Login button disabled
*/
@Test
fun testLoginButtonClickedWhenUsernameIsEmptyAndPasswordIsFilled() {
enterCredentials("", CORRECT_TEST_PASSWORD)

// Check for error message on username and not on password
onView(withId(R.id.tiUsername)).check(matches(hasTextInputLayoutErrorText(EMPTY_USERNAME_ERROR)))
onView(withId(R.id.tiPassword)).check(matches(not(hasTextInputLayoutErrorText(EMPTY_PASSWORD_ERROR))))
onView(withId(R.id.btnLogin)).check(matches(not(isEnabled())))
}

/**
* This test checks that error messages are shown after the Login button is clicked
* with:
* username: PRESENT, correct
* password: EMPTY
* expected: empty password error
* expected: login button disabled
*/
@Test
fun testLoginButtonClickedWhenUsernameIsFilledAndPasswordIsEmpty() {
enterCredentials(CORRECT_TEST_USERNAME, "")

// Check for no error message on username with an error message on password
onView(withId(R.id.tiUsername)).check(matches(not(hasTextInputLayoutErrorText(EMPTY_USERNAME_ERROR))))
onView(withId(R.id.tiPassword)).check(matches(hasTextInputLayoutErrorText(EMPTY_PASSWORD_ERROR)))
onView(withId(R.id.btnLogin)).check(matches(not(isEnabled())))
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@ import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.rule.IntentsTestRule
import androidx.test.platform.app.InstrumentationRegistry
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers
import org.hamcrest.TypeSafeMatcher
import org.hamcrest.*
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -75,7 +72,7 @@ class SignUpActivityTest {
*/
fun findEditTextInTextInputLayout(@IdRes textInputLayoutId: Int): ViewInteraction {

return Espresso.onView(Matchers.allOf(ViewMatchers.isDescendantOfA(ViewMatchers.withId(textInputLayoutId)),ViewMatchers.isAssignableFrom(EditText::class.java)))
return onView(Matchers.allOf(isDescendantOfA(withId(textInputLayoutId)), isAssignableFrom(EditText::class.java)))
}


Expand Down Expand Up @@ -127,8 +124,8 @@ class SignUpActivityTest {
}

/**
* This test method is defined to test that when all the fields are empty and the user
* clicks the signUp button then the errors in all the fields are displayed or not
* Input : All fields are empty
* Expected : Button is disabled
*/
@Test
fun testSignUpClickedWhenAllFieldsAreEmpty() {
Expand All @@ -142,12 +139,7 @@ class SignUpActivityTest {

onView(withId(R.id.btnSignUp)).perform(scrollTo(), click())

onView(withId(R.id.tiName)).check(matches(hasTextInputLayoutErrorText(EMPTY_NAME_ERROR)))
onView(withId(R.id.tiUsername)).check(matches(hasTextInputLayoutErrorText(EMPTY_USERNAME_ERROR)))
onView(withId(R.id.tiEmail)).check(matches(hasTextInputLayoutErrorText(EMPTY_EMAIL_ERROR)))
onView(withId(R.id.tiPassword)).check(matches(hasTextInputLayoutErrorText(EMPTY_PASSWORD_ERROR)))
onView(withId(R.id.tiConfirmPassword)).check(matches(hasTextInputLayoutErrorText(EMPTY_CONFIRM_PASSWORD_ERROR)))
onView(withId(R.id.tvNoteSignUp)).check(matches(withEffectiveVisibility(Visibility.VISIBLE)))
onView(withId(R.id.btnSignUp)).check(matches(CoreMatchers.not(isEnabled())))

}

Expand Down Expand Up @@ -225,10 +217,10 @@ class SignUpActivityTest {
@Test
fun whenUsernameIsAlreadyRegistered() {
findEditTextInTextInputLayout(R.id.tiName).perform(typeText("name"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiUsername).perform(typeText("Divyansh"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiEmail).perform(typeText("justdvnsh2208@gmail.com"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiPassword).perform(typeText("Divyansh@2001"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiConfirmPassword).perform(typeText("Divyansh@2001"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiUsername).perform(typeText("isabel"), closeSoftKeyboard())
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@isabelcosta sorry I couldn't really think of any other username so I used your, if we do end up creating a user solely for testing we can update it here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

username is fine ;)

findEditTextInTextInputLayout(R.id.tiEmail).perform(typeText("random_emailid@gmail.com"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiPassword).perform(typeText("Password@2001"), closeSoftKeyboard())
findEditTextInTextInputLayout(R.id.tiConfirmPassword).perform(typeText("Password@2001"), closeSoftKeyboard())
onView(withId(R.id.cbBoth)).perform(click())
onView(withId(R.id.cbTC)).perform(click())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class ChangePasswordFragmentTest {
ChangePasswordFragment.newInstance().show(activityTestRule.activity.supportFragmentManager, null)

enter_credentials(R.id.tilNewPassword, "ab")
enter_credentials(R.id.tilConfirmPassword, "ab")

// clicks the OK button in the Dialog Fragment
onView(withText(R.string.ok)).inRoot(isDialog())
Expand Down Expand Up @@ -92,6 +93,7 @@ class ChangePasswordFragmentTest {
check(matches(isDisplayed()))
perform(click())
perform(typeText(password))
perform(closeSoftKeyboard())
}

// helper method to find Edit Text
Expand Down