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

Fixes #4294 : Added Success Dialog for Profile Deletion with Updated Flow and Tests. #5575

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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 @@ -63,6 +63,7 @@ import org.oppia.android.app.profile.ResetPinDialogFragment
import org.oppia.android.app.profileprogress.ProfilePictureEditDialogFragment
import org.oppia.android.app.profileprogress.ProfileProgressFragment
import org.oppia.android.app.resumelesson.ResumeLessonFragment
import org.oppia.android.app.settings.profile.DeleteProfileSuccessDialogFragment
import org.oppia.android.app.settings.profile.ProfileEditDeletionDialogFragment
import org.oppia.android.app.settings.profile.ProfileEditFragment
import org.oppia.android.app.settings.profile.ProfileListFragment
Expand Down Expand Up @@ -128,6 +129,7 @@ interface FragmentComponentImpl : FragmentComponent, ViewComponentBuilderInjecto
fun inject(cellularAudioDialogFragment: CellularAudioDialogFragment)
fun inject(completedStoryListFragment: CompletedStoryListFragment)
fun inject(conceptCardFragment: ConceptCardFragment)
fun inject(deleteProfileSuccessDialogFragment: DeleteProfileSuccessDialogFragment)
fun inject(developerOptionsFragment: DeveloperOptionsFragment)
fun inject(downloadsTabFragment: DownloadsTabFragment)
fun inject(dragDropTestFragment: DragDropTestFragment)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.oppia.android.app.settings.profile

import android.app.Dialog
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import org.oppia.android.R
import org.oppia.android.app.administratorcontrols.AdministratorControlsActivity
import org.oppia.android.app.fragment.FragmentComponentImpl
import org.oppia.android.app.fragment.InjectableDialogFragment
import org.oppia.android.app.translation.AppLanguageResourceHandler
import javax.inject.Inject

/** [DialogFragment] that notifies the user after a profile is successfully deleted. */
class DeleteProfileSuccessDialogFragment : InjectableDialogFragment() {

companion object {
/** Argument key for Profile Deletion Success Dialog in [ProfileEditFragmentPresenter]. */
const val DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT_TAG = "DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT"

/** This function returns a new instance of [DeleteProfileSuccessDialogFragment]. */
fun createNewInstance(): DeleteProfileSuccessDialogFragment {
return DeleteProfileSuccessDialogFragment()
}
}

@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

override fun onAttach(context: Context) {
super.onAttach(context)
(fragmentComponent as FragmentComponentImpl).inject(this)
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val alertDialog = AlertDialog
.Builder(requireContext(), R.style.OppiaAlertDialogTheme).apply {
setMessage(
resourceHandler.getStringInLocale(R.string.profile_edit_delete_successful_message)
)
setPositiveButton(
resourceHandler.getStringInLocale(R.string.log_out_dialog_okay_button)
) { _, _ ->
if (requireContext().resources.getBoolean(R.bool.isTablet)) {
val intent =
Intent(requireContext(), AdministratorControlsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
} else {
val intent = Intent(requireContext(), ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
}
}
}.create()
alertDialog.setCanceledOnTouchOutside(true)
return alertDialog
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,11 @@ class ProfileEditFragmentPresenter @Inject constructor(
fragment,
Observer {
if (it is AsyncResult.Success) {
if (fragment.requireContext().resources.getBoolean(R.bool.isTablet)) {
val intent =
Intent(fragment.requireContext(), AdministratorControlsActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
fragment.startActivity(intent)
} else {
val intent = Intent(fragment.requireContext(), ProfileListActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
fragment.startActivity(intent)
}
DeleteProfileSuccessDialogFragment.createNewInstance()
.showNow(
fragment.childFragmentManager,
DeleteProfileSuccessDialogFragment.DELETE_PROFILE_SUCCESS_DIALOG_FRAGMENT_TAG
)
}
}
)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@
<string name="profile_edit_delete_dialog_message">All progress will be deleted and cannot be recovered.</string>
<string name="profile_edit_delete_dialog_positive">Delete</string>
<string name="profile_edit_delete_dialog_negative">Cancel</string>
<string name="profile_edit_delete_dialog_success_message">Profile deleted successfully.</string>
<string name="profile_edit_allow_download_heading">Allow Download Access</string>
<string name="profile_edit_allow_download_sub">User is able to download and delete content without Administrator password</string>
<!-- ProfilePictureActivity -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ class ProfileEditFragmentTest {
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_success_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
}
}

Expand All @@ -196,9 +201,50 @@ class ProfileEditFragmentTest {
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_message))
.inRoot(isDialog()).check(matches(isCompletelyDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_success_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
}
}

@Test
@Config(qualifiers = "land")
fun testProfileEdit_startWithUserProfile_clickDelete_checkOpensDeletionSuccessDialog() {
launchFragmentTestActivity(internalProfileId = 1).use {
onView(withId(R.id.profile_delete_button)).perform(scrollTo()).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_success_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
}
}

@Test
@Config(qualifiers = "land")
fun testProfileEdit_deleteProfile_checkNavigationAfterDeletion() {
launchFragmentTestActivity(internalProfileId = 1).use {
onView(withId(R.id.profile_delete_button)).perform(scrollTo()).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
testCoroutineDispatchers.runCurrent()
onView(withText(R.string.profile_edit_delete_dialog_success_message))
.inRoot(isDialog()).check(matches(isDisplayed()))
onView(withText(android.R.string.ok)).perform(click())
if (fragment.requireContext().resources.getBoolean(R.bool.isTablet)) {
intended(hasComponent(AdministratorControlsActivity::class.java.name))
} else {
intended(hasComponent(ProfileListActivity::class.java.name))
}
}
}
@Test
fun testProfileEdit_startWithUserHasDownloadAccess_downloadsDisabled_switchIsNotDisplayed() {
TestPlatformParameterModule.forceEnableDownloadsSupport(false)
Expand Down
Loading