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,