Skip to content
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

Fix #4803 Failed to add Admin (or non-admin) Profile Picture. #5118

Merged
merged 8 commits into from
Aug 10, 2023
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.oppia.android.app.profileprogress

import android.content.Intent
import android.provider.MediaStore
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
Expand Down Expand Up @@ -37,9 +36,9 @@ class ProfileProgressActivityPresenter @Inject constructor(
R.id.profile_progress_activity_toolbar
) as Toolbar
activity.setSupportActionBar(toolbar)
activity.supportActionBar!!.setTitle(R.string.profile)
activity.supportActionBar!!.setDisplayShowHomeEnabled(true)
activity.supportActionBar!!.setDisplayHomeAsUpEnabled(true)
(activity.supportActionBar ?: return).setTitle(R.string.profile)
(activity.supportActionBar ?: return).setDisplayShowHomeEnabled(true)
(activity.supportActionBar ?: return).setDisplayHomeAsUpEnabled(true)
toolbar.setNavigationOnClickListener {
activity.finish()
}
Expand All @@ -52,7 +51,7 @@ class ProfileProgressActivityPresenter @Inject constructor(
}

fun openGalleryIntent() {
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
val galleryIntent = Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
val galleryIntent = Intent(Intent.ACTION_GET_CONTENT).apply { type = "image/*" }
activity.startActivityForResult(galleryIntent, GALLERY_INTENT_RESULT_CODE)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import android.content.Context
import android.content.Intent
import android.content.res.Resources
import android.net.Uri
import android.provider.MediaStore
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
Expand All @@ -24,8 +23,8 @@ import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.Intents.intending
import androidx.test.espresso.intent.matcher.IntentMatchers.hasAction
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasData
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.intent.matcher.IntentMatchers.hasType
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.isClickable
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
Expand Down Expand Up @@ -342,8 +341,8 @@ class ProfileProgressFragmentTest {
@Test
fun testProfileProgressFragment_imageSelectAvatar_checkGalleryIntent() {
val expectedIntent: Matcher<Intent> = allOf(
hasAction(Intent.ACTION_PICK),
hasData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
hasAction(Intent.ACTION_GET_CONTENT),
hasType("image/*")
)
val activityResult = createGalleryPickActivityResultStub()
intending(expectedIntent).respondWith(activityResult)
Expand All @@ -360,24 +359,31 @@ class ProfileProgressFragmentTest {
@Test
fun testProfileProgressFragment_imageSelectAvatar_configChange_checkGalleryIntent() {
val expectedIntent: Matcher<Intent> = allOf(
hasAction(Intent.ACTION_PICK),
hasData(MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
hasAction(Intent.ACTION_GET_CONTENT),
hasType("image/*")
)
val activityResult = createGalleryPickActivityResultStub()
intending(expectedIntent).respondWith(activityResult)
launch<ProfileProgressActivity>(createProfileProgressActivityIntent(internalProfileId)).use {
onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()
clickProfileProgressItem(itemPosition = 0, targetViewId = R.id.profile_edit_image)
verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title))
onView(withText(R.string.profile_picture_edit_alert_dialog_choose_from_library))
.perform(click())
testCoroutineDispatchers.runCurrent()
intended(expectedIntent)
onView(isRoot()).perform(orientationLandscape())
}
}

@Test
fun testFragment_imageSelectAvatar_configChange_profilePictureDialogIsVisible() {
launch<ProfileProgressActivity>(createProfileProgressActivityIntent(internalProfileId)).use {
testCoroutineDispatchers.runCurrent()
intended(expectedIntent)
clickProfileProgressItem(itemPosition = 0, targetViewId = R.id.profile_edit_image)
// The dialog should still be open after a configuration change.
verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title))
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
testCoroutineDispatchers.runCurrent()
verifyTextInDialog(context.getString(R.string.profile_progress_edit_dialog_title))
}
}
Expand Down