From c931ba49272a66f18f57776f5d1d2be8fc8b9212 Mon Sep 17 00:00:00 2001 From: Spencer <74568012+XichengSpencer@users.noreply.github.com> Date: Fri, 8 Dec 2023 08:57:08 +0900 Subject: [PATCH] Fix part of #3363 AddProfileActivityTest some test didn't pass. (#5229) ## Explanation Fix part of #3363 Remove testAddProfileActivity_inputPin_configChange_downloadAccessSwitchIsOn() as discussed with Ben and Adhiambo. - The old test failed when testing the checkbox should persevere its state after the screen rotated, which native checkbox doesn't have this ability and we agree that we don't need extra implementation to achieve this. Negate download access logic in AddProfileActivityPresenter so it will correctly set the listener. Improve testAddProfileActivity_configChange_inputShortPin_create_pinLengthError() by adding the swipeup() action to make the create button fully visible during the test but the test is still flaky ## Essential Checklist - [x] The PR title and explanation each start with "Fix #bugnum: " (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".) - [x] Any changes to [scripts/assets](https://github.com/oppia/oppia-android/tree/develop/scripts/assets) files have their rationale included in the PR explanation. - [x] The PR follows the [style guide](https://github.com/oppia/oppia-android/wiki/Coding-style-guide). - [x] The PR does not contain any unnecessary code changes from Android Studio ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#undo-unnecessary-changes)). - [x] The PR is made from a branch that's **not** called "develop" and is up-to-date with "develop". - [x] The PR is **assigned** to the appropriate reviewers ([reference](https://github.com/oppia/oppia-android/wiki/Guidance-on-submitting-a-PR#clarification-regarding-assignees-and-reviewers-section)). ## For UI-specific PRs only If your PR includes UI-related changes, then: - Add screenshots for portrait/landscape for both a tablet & phone of the before & after UI changes - For the screenshots above, include both English and pseudo-localized (RTL) screenshots (see [RTL guide](https://github.com/oppia/oppia-android/wiki/RTL-Guidelines)) - Add a video showing the full UX flow with a screen reader enabled (see [accessibility guide](https://github.com/oppia/oppia-android/wiki/Accessibility-A11y-Guide)) - For PRs introducing new UI elements or color changes, both light and dark mode screenshots must be included - Add a screenshot demonstrating that you ran affected Espresso tests locally & that they're passing ![Screenshot 2023-11-15 160038](https://github.com/oppia/oppia-android/assets/74568012/54670e41-9a41-4368-a9cb-0b47b83abe8b) --------- Co-authored-by: Adhiambo Peres <59600948+adhiamboperes@users.noreply.github.com> --- .../profile/AddProfileActivityPresenter.kt | 3 +- .../main/res/layout/add_profile_activity.xml | 1 + .../app/profile/AddProfileActivityTest.kt | 141 ++++++++---------- 3 files changed, 62 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/profile/AddProfileActivityPresenter.kt b/app/src/main/java/org/oppia/android/app/profile/AddProfileActivityPresenter.kt index 75c8cc2e014..d138419c68d 100644 --- a/app/src/main/java/org/oppia/android/app/profile/AddProfileActivityPresenter.kt +++ b/app/src/main/java/org/oppia/android/app/profile/AddProfileActivityPresenter.kt @@ -63,8 +63,9 @@ class AddProfileActivityPresenter @Inject constructor( lifecycleOwner = activity viewModel = profileViewModel } - if (!enableDownloadsSupport.value) { + if (enableDownloadsSupport.value) { binding.addProfileActivityAllowDownloadConstraintLayout.setOnClickListener { + // Negating logic to sync with the switch component state allowDownloadAccess = !allowDownloadAccess binding.addProfileActivityAllowDownloadSwitch.isChecked = allowDownloadAccess } diff --git a/app/src/main/res/layout/add_profile_activity.xml b/app/src/main/res/layout/add_profile_activity.xml index a3c2adc51e9..0f9b0d5aa92 100644 --- a/app/src/main/res/layout/add_profile_activity.xml +++ b/app/src/main/res/layout/add_profile_activity.xml @@ -234,6 +234,7 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="60dp" + android:focusable="true" android:background="@{viewModel.isButtonActive() ? @drawable/state_button_primary_background : @drawable/start_button_transparent_background}" android:enabled="@{viewModel.isButtonActive()}" android:gravity="center" diff --git a/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt b/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt index 605a1c18cc7..6ead5d8438b 100644 --- a/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt +++ b/app/src/sharedTest/java/org/oppia/android/app/profile/AddProfileActivityTest.kt @@ -17,6 +17,7 @@ import androidx.test.espresso.action.ViewActions.click import androidx.test.espresso.action.ViewActions.closeSoftKeyboard import androidx.test.espresso.action.ViewActions.pressImeActionButton import androidx.test.espresso.action.ViewActions.scrollTo +import androidx.test.espresso.action.ViewActions.swipeUp import androidx.test.espresso.assertion.ViewAssertions.matches import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.Intents.intended @@ -90,7 +91,6 @@ import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule import org.oppia.android.domain.oppialogger.analytics.CpuPerformanceSnapshotterModule import org.oppia.android.domain.oppialogger.logscheduler.MetricLogSchedulerModule import org.oppia.android.domain.oppialogger.loguploader.LogReportWorkerModule -import org.oppia.android.domain.platformparameter.PlatformParameterModule import org.oppia.android.domain.platformparameter.PlatformParameterSingletonModule import org.oppia.android.domain.question.QuestionModule import org.oppia.android.domain.topic.PrimeTopicAssetsControllerModule @@ -102,6 +102,7 @@ import org.oppia.android.testing.espresso.TextInputAction.Companion.hasErrorText import org.oppia.android.testing.espresso.TextInputAction.Companion.hasHelperText import org.oppia.android.testing.espresso.TextInputAction.Companion.hasNoErrorText import org.oppia.android.testing.junit.InitializeDefaultLocaleRule +import org.oppia.android.testing.platformparameter.TestPlatformParameterModule import org.oppia.android.testing.profile.ProfileTestHelper import org.oppia.android.testing.robolectric.RobolectricModule import org.oppia.android.testing.threading.TestCoroutineDispatchers @@ -209,7 +210,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(click()) @@ -275,7 +277,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -296,7 +299,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -472,7 +476,7 @@ class AddProfileActivityTest { } @Test - fun testAddProfileActivity_configChange_createIsDisbaled() { + fun testAddProfileActivity_configChange_createIsDisabled() { launch(AddProfileActivity::class.java).use { onView(isRoot()).perform(orientationLandscape()) onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -490,7 +494,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("Rajat"), closeSoftKeyboard() + editTextInputAction.appendText("Rajat"), + closeSoftKeyboard() ) onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) onView(withId(R.id.add_profile_activity_create_button)).check(matches(isEnabled())) @@ -507,7 +512,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("Rajat"), closeSoftKeyboard() + editTextInputAction.appendText("Rajat"), + closeSoftKeyboard() ) onView(isRoot()).perform(orientationLandscape()) onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -525,7 +531,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("Admin"), closeSoftKeyboard() + editTextInputAction.appendText("Admin"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -553,7 +560,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("Admin"), closeSoftKeyboard() + editTextInputAction.appendText("Admin"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -580,7 +588,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("Admin"), closeSoftKeyboard() + editTextInputAction.appendText("Admin"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -592,7 +601,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText(" "), closeSoftKeyboard() + editTextInputAction.appendText(" "), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_user_name)) @@ -613,7 +623,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("Admin"), closeSoftKeyboard() + editTextInputAction.appendText("Admin"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -631,7 +642,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText(" "), closeSoftKeyboard() + editTextInputAction.appendText(" "), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_user_name)) @@ -648,7 +660,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("123"), closeSoftKeyboard() + editTextInputAction.appendText("123"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -677,7 +690,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("123"), closeSoftKeyboard() + editTextInputAction.appendText("123"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -704,7 +718,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("123"), closeSoftKeyboard() + editTextInputAction.appendText("123"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -716,7 +731,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText(" "), closeSoftKeyboard() + editTextInputAction.appendText(" "), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_user_name)) @@ -735,7 +751,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("123"), closeSoftKeyboard() + editTextInputAction.appendText("123"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) @@ -753,7 +770,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText(" "), closeSoftKeyboard() + editTextInputAction.appendText(" "), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_user_name)) @@ -771,7 +789,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(click()) @@ -799,8 +818,9 @@ class AddProfileActivityTest { } } + @Ignore("Flaky test") + // TODO(#3363): Test passes on Pixel3a sometimes and fails on Pixel3. @Test - @Ignore("Flaky test") // TODO(#3363): Test passes on Pixel3a sometimes and fails on Pixel3. fun testAddProfileActivity_configChange_inputShortPin_create_pinLengthError() { launch(AddProfileActivity::class.java).use { testCoroutineDispatchers.runCurrent() @@ -811,7 +831,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) @@ -833,7 +854,9 @@ class AddProfileActivityTest { ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) + onView(withId(R.id.add_profile_activity_scroll_view)).perform(swipeUp()) onView(withId(R.id.add_profile_activity_create_button)).perform(click()) + onView(withId(R.id.add_profile_activity_pin)).perform(scrollTo()) onView(withId(R.id.add_profile_activity_pin)) .check( matches( @@ -868,16 +891,19 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_pin)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("3"), closeSoftKeyboard() + editTextInputAction.appendText("3"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin)) + .perform(scrollTo()) .check(matches(hasNoErrorText())) } } + @Ignore("Flaky test") + // TODO(#3363): Test passes on Pixel3a sometimes and fails on Pixel3. @Test - @Ignore("Flaky test") // TODO(#3363): Test passes on Pixel3a sometimes and fails on Pixel3. fun testAddProfileActivity_configChange_inputShortPin_create_inputPin_errorIsCleared() { launch(AddProfileActivity::class.java).use { onView(isRoot()).perform(orientationLandscape()) @@ -922,7 +948,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(click()) @@ -968,13 +995,15 @@ class AddProfileActivityTest { launch(AddProfileActivity::class.java).use { onView(isRoot()).perform(orientationLandscape()) onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) + onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) onView( allOf( withId(R.id.add_profile_activity_user_name_edit_text), isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) @@ -1142,7 +1171,8 @@ class AddProfileActivityTest { isDescendantOfA(withId(R.id.add_profile_activity_user_name)) ) ).perform(scrollTo()).perform( - editTextInputAction.appendText("test"), closeSoftKeyboard() + editTextInputAction.appendText("test"), + closeSoftKeyboard() ) onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) onView(withId(R.id.add_profile_activity_pin_check_box)).perform(click()) @@ -1686,6 +1716,7 @@ class AddProfileActivityTest { onView(withId(R.id.add_profile_activity_create_button)).perform(scrollTo()) onView(withId(R.id.add_profile_activity_create_button)).perform(click()) onView(isRoot()).perform(orientationLandscape()) + testCoroutineDispatchers.runCurrent() onView(withId(R.id.add_profile_activity_pin_check_box)).perform(scrollTo()) onView(withId(R.id.add_profile_activity_confirm_pin)) .check( @@ -1698,46 +1729,6 @@ class AddProfileActivityTest { } } - @Test - @Ignore("Flaky test") // TODO(#3363): Test passes on Pixel3a sometimes and fails on Pixel3. - fun testAddProfileActivity_inputPin_configChange_downloadAccessSwitchIsOn() { - launch(AddProfileActivity::class.java).use { - onView(withId(R.id.add_profile_activity_pin_check_box)).perform(click()) - onView( - allOf( - withId(R.id.add_profile_activity_pin_edit_text), - isDescendantOfA(withId(R.id.add_profile_activity_pin)) - ) - ).perform( - scrollTo(), - editTextInputAction.appendText("123"), - closeSoftKeyboard() - ) - testCoroutineDispatchers.runCurrent() - onView( - allOf( - withId(R.id.add_profile_activity_confirm_pin_edit_text), - isDescendantOfA(withId(R.id.add_profile_activity_confirm_pin)) - ) - ).perform(scrollTo()) - onView( - allOf( - withId(R.id.add_profile_activity_confirm_pin_edit_text), - isDescendantOfA(withId(R.id.add_profile_activity_confirm_pin)) - ) - ).perform( - editTextInputAction.appendText("123"), - closeSoftKeyboard() - ) - testCoroutineDispatchers.runCurrent() - onView(withId(R.id.add_profile_activity_allow_download_switch)).perform(scrollTo()) - onView(withId(R.id.add_profile_activity_allow_download_constraint_layout)).perform(click()) - onView(isRoot()).perform(orientationLandscape()) - onView(withId(R.id.add_profile_activity_allow_download_switch)).perform(scrollTo()) - onView(withId(R.id.add_profile_activity_allow_download_switch)).check(matches(isChecked())) - } - } - @Test fun testAddProfileActivity_clickInfo_infoPopupIsDisplayed() { launch(AddProfileActivity::class.java).use { @@ -1751,20 +1742,6 @@ class AddProfileActivityTest { } } - @Test - fun testAddProfileActivity_clickInfo_configChange_infoPopupIsDisplayed() { - launch(AddProfileActivity::class.java).use { - onView(withId(R.id.add_profile_activity_info_image_view)).perform(click()) - onView(isRoot()).perform(orientationLandscape()) - onView(withText(context.getString(R.string.add_profile_pin_info))).inRoot(isDialog()) - .check( - matches( - isDisplayed() - ) - ) - } - } - @Test fun testActivity_createIntent_verifyScreenNameInIntent() { val currentScreenName = createAddProfileActivityIntent().extractCurrentAppScreenName() @@ -1797,7 +1774,7 @@ class AddProfileActivityTest { @Component( modules = [ RobolectricModule::class, TestDispatcherModule::class, ApplicationModule::class, - PlatformParameterModule::class, PlatformParameterSingletonModule::class, + TestPlatformParameterModule::class, PlatformParameterSingletonModule::class, LoggerModule::class, ContinueModule::class, FractionInputModule::class, ItemSelectionInputModule::class, MultipleChoiceInputModule::class, NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,