Repository navigation
fix: bind profile removal to its original owner #1693
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
ben-kaufman
wants to merge
6
commits into
fix/profile-cleanup-outcomes
Choose a base branch
from
fix/profile-removal-ownership
base: fix/profile-cleanup-outcomes
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+6,837
−1,177
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
edd6476
fix: bind profile removal to its original owner
ben-kaufman ff4dc35
chore: rename changelog fragment
ben-kaufman 7e2e466
fix: complete profile removal recovery safely
ben-kaufman 7e2fd14
fix: keep pending profile cleanup distinct from expiry
ben-kaufman 188f456
fix: preserve receipt attribution during profile cleanup
ben-kaufman e6a75f0
fix: preserve receipt and recovery state through cleanup
ben-kaufman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
138 changes: 138 additions & 0 deletions
138
app/src/androidTest/java/to/bitkit/ui/screens/profile/ProfileRecoveryContentTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| package to.bitkit.ui.screens.profile | ||
|
|
||
| import androidx.compose.runtime.CompositionLocalProvider | ||
| import androidx.compose.runtime.getValue | ||
| import androidx.compose.runtime.mutableStateOf | ||
| import androidx.compose.runtime.setValue | ||
| import androidx.compose.ui.platform.LocalInspectionMode | ||
| import androidx.compose.ui.test.assertIsDisplayed | ||
| import androidx.compose.ui.test.assertIsNotEnabled | ||
| import androidx.compose.ui.test.junit4.v2.createComposeRule | ||
| import androidx.compose.ui.test.onNodeWithTag | ||
| import androidx.compose.ui.test.onNodeWithText | ||
| import androidx.compose.ui.test.performClick | ||
| import androidx.test.espresso.Espresso.pressBackUnconditionally | ||
| import androidx.test.platform.app.InstrumentationRegistry | ||
| import org.junit.Rule | ||
| import org.junit.Test | ||
| import to.bitkit.R | ||
| import to.bitkit.test.annotations.ComposeUi | ||
| import to.bitkit.ui.theme.AppThemeSurface | ||
| import kotlin.test.assertEquals | ||
|
|
||
| @ComposeUi | ||
| class ProfileRecoveryContentTest { | ||
| @get:Rule | ||
| val compose = createComposeRule() | ||
|
|
||
| private val context get() = InstrumentationRegistry.getInstrumentation().targetContext | ||
|
|
||
| @Test | ||
| fun restartRecoveryWithoutCredentialsRequiresLocalConfirmation() { | ||
| var state by mutableStateOf( | ||
| ProfileUiState(recoveryPending = true, localDisconnect = true), | ||
| ) | ||
| var confirmations = 0 | ||
| var back = 0 | ||
| compose.setContent { | ||
| AppThemeSurface { | ||
| CompositionLocalProvider(LocalInspectionMode provides true) { | ||
| ProfileContent( | ||
| uiState = state, | ||
| onBackClick = { back++ }, | ||
| onClickEdit = { error("Pending recovery must not offer editing") }, | ||
| onClickCopy = {}, | ||
| onClickShare = {}, | ||
| onClickSignOut = { state = state.copy(showSignOutDialog = true) }, | ||
| onDismissSignOutDialog = { state = state.copy(showSignOutDialog = false) }, | ||
| onConfirmSignOut = { | ||
| confirmations++ | ||
| state = state.copy(showSignOutDialog = false, isSigningOut = true) | ||
| }, | ||
| onClickRetry = { error("Pending recovery must not restore credentials") }, | ||
| onClickAddTag = {}, | ||
| onRemoveTag = {}, | ||
| onDismissAddTagSheet = {}, | ||
| onSaveTag = {}, | ||
| onDismissCopiedPopup = {}, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| compose.onNodeWithText(context.getString(R.string.profile__wallet_recovery_pending)).assertIsDisplayed() | ||
| compose.onNodeWithTag("ProfileRecoveryDisconnect").assertDoesNotExist() | ||
| compose.runOnIdle { state = state.copy(recoveryCanDisconnect = true) } | ||
| compose.onNodeWithText(context.getString(R.string.profile__cleanup_pending)).assertIsDisplayed() | ||
| compose.onNodeWithTag("ProfileRecoveryDisconnect").assertIsDisplayed().performClick() | ||
| compose.onNodeWithText(context.getString(R.string.profile__disconnect_local_description)).assertIsDisplayed() | ||
| compose.runOnIdle { assertEquals(0, confirmations) } | ||
| compose.onNodeWithTag("DialogCancel").performClick() | ||
| val dismissedAt = System.currentTimeMillis() | ||
| compose.runOnIdle { assertEquals(0, confirmations) } | ||
| compose.waitUntil(1_000) { System.currentTimeMillis() - dismissedAt > 600 } | ||
| compose.onNodeWithTag("ProfileRecoveryDisconnect").performClick() | ||
| compose.onNodeWithTag("DialogConfirm").performClick() | ||
| compose.runOnIdle { assertEquals(1, confirmations) } | ||
| compose.onNodeWithTag("ProfileRecoveryDisconnect").assertIsNotEnabled() | ||
| compose.onNodeWithTag("NavigationBack").performClick() | ||
| compose.onNodeWithTag("HeaderMenu").assertDoesNotExist() | ||
| pressBackUnconditionally() | ||
| compose.onNodeWithTag("ProfileRecoveryDisconnect").assertIsDisplayed() | ||
| compose.runOnIdle { assertEquals(0, back) } | ||
| } | ||
|
|
||
| @Test | ||
| fun uncertainDeletionOffersReviewThenSeparateConfirmation() { | ||
| var state by mutableStateOf(EditProfileUiState(showDeleteFailureDialog = true, canReviewRemoval = true)) | ||
| var reviews = 0 | ||
| var deletes = 0 | ||
| editContent({ state }, onReview = { | ||
| reviews++ | ||
| state = state.copy(showDeleteFailureDialog = false, showDeleteDialog = true) | ||
| }, onConfirm = { deletes++ }) | ||
| compose.onNodeWithText(context.getString(R.string.profile__review_removal)).assertIsDisplayed() | ||
| compose.onNodeWithTag("DialogConfirm").performClick() | ||
| compose.runOnIdle { | ||
| assertEquals(1, reviews) | ||
| assertEquals(0, deletes) | ||
| } | ||
| compose.onNodeWithTag("DialogConfirm").performClick() | ||
| compose.runOnIdle { assertEquals(1, deletes) } | ||
| } | ||
|
|
||
| @Test | ||
| fun localCompletionFailureOnlyOffersDisconnectAndClose() { | ||
| var disconnects = 0 | ||
| editContent( | ||
| state = { EditProfileUiState(showDeleteFailureDialog = true, canReviewRemoval = false) }, | ||
| onReview = { error("Local completion cannot repeat remote deletion") }, | ||
| onDisconnect = { disconnects++ }, | ||
| ) | ||
| compose.onNodeWithText(context.getString(R.string.profile__review_removal)).assertDoesNotExist() | ||
| compose.onNodeWithText(context.getString(R.string.common__close)).assertIsDisplayed() | ||
| compose.onNodeWithTag("DialogConfirm").performClick() | ||
| compose.runOnIdle { assertEquals(1, disconnects) } | ||
| } | ||
|
|
||
| private fun editContent( | ||
| state: () -> EditProfileUiState, | ||
| onReview: () -> Unit, | ||
| onDisconnect: () -> Unit = {}, | ||
| onConfirm: () -> Unit = {}, | ||
| ) { | ||
| compose.setContent { | ||
| AppThemeSurface { | ||
| CompositionLocalProvider(LocalInspectionMode provides true) { | ||
| EditProfileContent( | ||
| uiState = state(), | ||
| onBackClick = {}, onNameChange = {}, onBioChange = {}, onLinkUrlChange = { _, _ -> }, | ||
| onAvatarSelected = {}, onAddLink = {}, onRemoveLink = {}, onAddTag = {}, onRemoveTag = {}, | ||
| onSave = {}, onDelete = {}, onDismissDeleteDialog = {}, onConfirmDelete = onConfirm, | ||
| onRetryDelete = onReview, onDismissDeleteFailureDialog = {}, onDisconnectProfile = onDisconnect, | ||
| onDismissAddLinkSheet = {}, onSaveLink = { _, _ -> }, onDismissAddTagSheet = {}, onSaveTag = {}, | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.