Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
4d86489
fix: decouple wallet restore from profile refresh
ben-kaufman Oct 24, 2026
ac2a7c6
docs: associate restore note with PR 1686
ben-kaufman Oct 24, 2026
ab59838
fix: stop automatic profile deletion replay
ben-kaufman Oct 24, 2026
99b446a
docs: associate deletion fix with PR 1688
ben-kaufman Oct 24, 2026
a8f0810
fix: preserve pending backups across restart
ben-kaufman Oct 25, 2026
e585fcc
fix: retain backup changes while restart drains
ben-kaufman Oct 25, 2026
618087a
fix: stop profile deletion after incomplete cleanup
ben-kaufman Oct 25, 2026
479c530
chore: rename changelog fragment
ben-kaufman Oct 25, 2026
2daec90
fix: preserve sessions after uncertain profile deletion
ben-kaufman Oct 25, 2026
edd6476
fix: bind profile removal to its original owner
ben-kaufman Oct 26, 2026
ff4dc35
chore: rename changelog fragment
ben-kaufman Oct 26, 2026
7e2e466
fix: complete profile removal recovery safely
ben-kaufman Oct 26, 2026
d4ba907
fix: preserve active identity during scheduled restore setup
ben-kaufman Oct 26, 2026
0fd5e42
Merge validated connection recovery into deferred identity restoration
ben-kaufman Oct 26, 2026
7e2fd14
fix: keep pending profile cleanup distinct from expiry
ben-kaufman Oct 26, 2026
c255458
Merge restore recovery parent into backup lifecycle fix
ben-kaufman Oct 26, 2026
a102e0e
fix: recognize native backup request transport failures
ben-kaufman Oct 26, 2026
49e9a99
fix: retain explicit backup retry ownership
ben-kaufman Oct 26, 2026
0f66cc3
merge validated restore admission parent
ben-kaufman Oct 28, 2026
89e2702
Merge current required-recovery parent
ben-kaufman Oct 28, 2026
5fe0bf6
fix: integrate current restore recovery parent
ben-kaufman Oct 28, 2026
5fca5cd
fix: integrate current restore recovery parent
ben-kaufman Oct 28, 2026
f72e0c0
fix: integrate current restore recovery parent
ben-kaufman Oct 28, 2026
188f456
fix: preserve receipt attribution during profile cleanup
ben-kaufman Oct 28, 2026
9ac9746
Retry missing profile enrichment after connectivity recovery
ben-kaufman Oct 28, 2026
9ce4302
Merge validated current master into identity recovery
ben-kaufman Oct 28, 2026
e6a75f0
fix: preserve receipt and recovery state through cleanup
ben-kaufman Oct 28, 2026
e80ca3f
Merge updated restore identity parent into backup lifecycle
ben-kaufman Oct 29, 2026
9a837a6
fix: keep recovery callbacks ahead of backup debounce
ben-kaufman Oct 29, 2026
7afdd3e
fix: block profile removal with active subscriptions
ben-kaufman Oct 29, 2026
e1cc3b1
fix: preserve subscription checks in profile removal
ben-kaufman Oct 29, 2026
5ae48f9
Merge branch 'master' into fix/restore-identity-background
ovitrif Oct 29, 2026
217b42e
Merge current master into identity recovery
ben-kaufman Oct 29, 2026
2aac53e
Merge current identity recovery into profile session recovery
ben-kaufman Oct 29, 2026
98797f2
fix: explain fixed-term profile removal restrictions
ben-kaufman Oct 29, 2026
0dcad96
fix: offer original-owner local disconnect after removal refusal
ben-kaufman Oct 29, 2026
815e85c
Merge current profile session recovery into cleanup outcomes
ben-kaufman Oct 29, 2026
564a54d
Merge current cleanup parent into local profile recovery
ben-kaufman Oct 29, 2026
1d3ba14
Merge current identity recovery parent into backup observers
ben-kaufman Oct 29, 2026
4d67734
test: wire local disconnect in profile recovery content
ben-kaufman Oct 29, 2026
f311807
fix: require acknowledged private endpoint withdrawal
ben-kaufman Oct 30, 2026
716e88e
fix: retain acknowledged profile withdrawal on review
ben-kaufman Oct 30, 2026
78a0ff7
Merge current parent guards into restored identity recovery
ben-kaufman Oct 30, 2026
ff5aa32
Merge restored identity guards into profile deletion recovery
ben-kaufman Oct 30, 2026
9cfe052
Merge restore metadata guards into backup observer lifecycle
ben-kaufman Oct 30, 2026
3001faf
test: report Pubky alias state on routing failures
ben-kaufman Oct 30, 2026
7ef3432
Merge current deletion recovery parent into cleanup guards
ben-kaufman Oct 30, 2026
ebc3910
fix: preserve profile removal across confirmed retries
ben-kaufman Oct 31, 2026
b2cd2aa
fix: preserve profile cleanup retries
ben-kaufman Oct 31, 2026
71fa609
Merge current master into deferred identity restoration
ben-kaufman Oct 31, 2026
e3384ed
chore: merge validated restore identity parent
ben-kaufman Oct 31, 2026
7b795fd
fix: stop queued allowance offers after deactivation
ben-kaufman Nov 1, 2026
55afaad
Merge queued allowance admission fix
ben-kaufman Nov 1, 2026
cfe7daf
Merge validated identity restore parent
ben-kaufman Nov 1, 2026
78269d8
Preserve active allowance ownership during contact refresh
ben-kaufman Nov 1, 2026
9226253
Merge restored-identity allowance admission
ben-kaufman Nov 1, 2026
3f4b19f
Merge stable allowance activation into profile recovery
ben-kaufman Nov 1, 2026
a3693b0
Merge stable allowance activation into backup observation
ben-kaufman Nov 1, 2026
6e02af2
Merge current profile recovery into local cleanup
ben-kaufman Nov 1, 2026
9bf19f1
Merge current profile recovery into local cleanup
ben-kaufman Nov 1, 2026
2d8c991
Refresh profile review eligibility after credential failure
ben-kaufman Nov 1, 2026
1b1426f
fix: preserve pending profile setup and revoke stale activation
ben-kaufman Nov 1, 2026
2621f81
Merge guarded identity and allowance recovery parent
ben-kaufman Nov 1, 2026
2eb0c49
Merge guarded identity and allowance recovery parent
ben-kaufman Nov 1, 2026
120553f
Merge current session recovery parent into cleanup outcomes
ben-kaufman Nov 1, 2026
395314b
fix: recover failed wallet resets before wallet admission
ben-kaufman Nov 1, 2026
181d664
fix: resume allowances after a paused activation
ben-kaufman Nov 1, 2026
9c145d9
Merge current allowance resume fix into recovery branch
ben-kaufman Nov 1, 2026
f068aba
Merge current allowance resume fix into recovery branch
ben-kaufman Nov 1, 2026
b6751e2
test: report Pubky alias state on routing failures
ben-kaufman Oct 30, 2026
2efaff0
merge: include final identity recovery parent
ben-kaufman Nov 1, 2026
439b5d0
merge: include identity recovery diagnostics
ben-kaufman Nov 1, 2026
7040c89
fix: compose validated profile cleanup parent
ben-kaufman Nov 1, 2026
011f47f
fix: preserve authenticated recovery for unreadable reset state
ben-kaufman Nov 2, 2026
581fed7
fix: preserve cleanup and local pin recovery
ben-kaufman Nov 2, 2026
595c364
fix: resume migration after cleanup state recovery
ben-kaufman Nov 2, 2026
78f7209
fix: offer retry for unavailable migration status
ben-kaufman Nov 2, 2026
43e0f3f
merge: integrate current wallet restore contracts
ben-kaufman Nov 3, 2026
3d8a328
merge: integrate current identity recovery
ben-kaufman Nov 3, 2026
add2c04
merge: integrate current identity recovery
ben-kaufman Nov 3, 2026
2e79e10
merge: integrate current profile recovery parent
ben-kaufman Nov 3, 2026
a5cd94f
Merge current cleanup parent and bound receipt credential checks
ben-kaufman Nov 3, 2026
8727da0
fix: initialize cold explicit backup retries
ben-kaufman Nov 3, 2026
3b3b226
fix: keep unreadable recovery retry available with PIN access
ben-kaufman Nov 3, 2026
e7fb0ac
fix: retry backup authentication transport failures
ben-kaufman Nov 3, 2026
4056d2c
fix: keep VSS operations with their original wallet
ben-kaufman Nov 4, 2026
916c6d5
fix: compose original-wallet VSS ownership with profile deletion
ben-kaufman Nov 4, 2026
1a6048a
fix: retain backup ownership across wallet transitions
ben-kaufman Nov 4, 2026
84c803d
fix: compose vss ownership with profile cleanup
ben-kaufman Nov 4, 2026
051f60f
fix: preserve profile ownership with vss retirement
ben-kaufman Nov 4, 2026
b93444c
fix: keep queued backups marked as running
ben-kaufman Nov 4, 2026
5cf930f
merge: compose queued backup status
ben-kaufman Nov 4, 2026
97dbdff
merge: compose queued backup status
ben-kaufman Nov 4, 2026
2fa4098
merge: compose queued backup status
ben-kaufman Nov 4, 2026
a2c58f2
fix: clear status for unadmitted backups
ben-kaufman Nov 4, 2026
1cf5d39
merge: compose admitted backup status
ben-kaufman Nov 4, 2026
a8c3fd3
merge: compose admitted backup status
ben-kaufman Nov 4, 2026
b2c4b9e
merge: compose admitted backup status
ben-kaufman Nov 4, 2026
32fc96f
fix: keep reset recovery and wallet presence consistent
ben-kaufman Nov 4, 2026
8ceaca2
fix: recheck subscriptions before profile deletion
ben-kaufman Nov 4, 2026
c228adb
fix: compose final profile subscription admission
ben-kaufman Nov 4, 2026
b5d5858
Merge master into the identity recovery branch
ben-kaufman Nov 6, 2026
a60add9
Merge the current restore identity branch into backup observation
ben-kaufman Nov 9, 2026
be4e1ba
fix: retry wallet and USDT recovery uploads after VSS setup times out
ben-kaufman Nov 9, 2026
3e1fdb7
Preserve wallet ownership when coalescing activity backups
ben-kaufman Nov 9, 2026
f8b2ffc
Preserve full activity uploads across backup observation
ben-kaufman Nov 9, 2026
710292a
Preserve Spark backup notifications across wallet retirement
ben-kaufman Nov 11, 2026
534b3d8
Preserve Spark backups in admitted observation lifecycle
ben-kaufman Nov 11, 2026
acdd99c
fix: resume spark backups after restore
ben-kaufman Nov 11, 2026
9f60111
fix: compose spark restore backup recovery
ben-kaufman Nov 11, 2026
cd0befc
test: align recovery controls with profile loading
ben-kaufman Nov 11, 2026
e0d2598
fix: preserve explicit profile deletion recovery
ben-kaufman Nov 11, 2026
dc9a981
fix: preserve explicit profile deletion recovery
ben-kaufman Nov 11, 2026
97b3c8d
fix: guard profile removal after subscription changes
ben-kaufman Nov 11, 2026
cd1d129
fix: keep profile recovery with its original identity
ben-kaufman Nov 11, 2026
8a96806
fix: preserve profile ownership during recovery
ben-kaufman Nov 11, 2026
c53a459
fix: preserve profile ownership during recovery
ben-kaufman Nov 11, 2026
0bda04a
fix: preserve profile ownership during recovery
ben-kaufman Nov 11, 2026
2dc86ae
fix: preserve restore ownership with updated invoice guards
ben-kaufman Nov 12, 2026
8d10218
fix: retain recovery guards in the composed parent
ben-kaufman Nov 12, 2026
9a53355
fix: retain recovery guards in the composed parent
ben-kaufman Nov 12, 2026
daee65e
fix: preserve original ownership during profile cleanup
ben-kaufman Nov 12, 2026
f9b3ed2
fix: retain recovery guards during profile cleanup
ben-kaufman Nov 12, 2026
62c8cf2
fix: retain recovery guards in the composed parent
ben-kaufman Nov 12, 2026
ff9275d
fix: keep spark balances and payment results current
ben-kaufman Nov 12, 2026
5f0a8ad
fix: preserve recovery with spark balance and result updates
ben-kaufman Nov 12, 2026
ac4dcf2
fix: preserve recovery with spark balance and result updates
ben-kaufman Nov 12, 2026
89f3bc6
fix: load cached wallet data during node startup
ben-kaufman Nov 12, 2026
66ba140
fix: retain recovery with spark balance updates
ben-kaufman Nov 12, 2026
46d5901
fix: preserve recovery with startup cache loading
ben-kaufman Nov 12, 2026
430588b
fix: preserve recovery with startup cache loading
ben-kaufman Nov 12, 2026
fc96942
fix: retain recovery with spark balance updates
ben-kaufman Nov 12, 2026
35806d6
fix: preserve recovery with startup cache loading
ben-kaufman Nov 12, 2026
4024e8b
fix: preserve recovery with startup cache loading
ben-kaufman Nov 12, 2026
040c9f8
fix: refresh spark balances after node startup timeout
ben-kaufman Nov 12, 2026
b2c3ea6
fix: preserve restore ownership with spark routing updates
ben-kaufman Nov 12, 2026
ac1549f
fix: preserve recovery with node timeout balance updates
ben-kaufman Nov 12, 2026
f270a9e
fix: preserve recovery with node timeout balance updates
ben-kaufman Nov 12, 2026
bacf2b6
fix: preserve recovery with node timeout balance updates
ben-kaufman Nov 12, 2026
a681b2b
Merge validated recovery parent into profile cleanup
ben-kaufman Nov 12, 2026
55694dd
fix: preserve recovery balances across Spark exits
ben-kaufman Nov 12, 2026
4aa622f
fix: preserve recovery state with current profile updates
ben-kaufman Nov 12, 2026
172851d
fix: preserve recovery across parent changes
ben-kaufman Nov 12, 2026
afb4f06
fix: preserve recovery across parent changes
ben-kaufman Nov 12, 2026
d28a157
fix: refresh spark balances after finished exits
ben-kaufman Nov 12, 2026
1bc89c1
fix: preserve recovery with finished-exit balance updates
ben-kaufman Nov 12, 2026
43e314c
fix: preserve recovery with finished-exit balance updates
ben-kaufman Nov 12, 2026
274bb68
fix: preserve recovery with finished-exit balance updates
ben-kaufman Nov 12, 2026
83155d8
fix: preserve recovery with finished-exit balance updates
ben-kaufman Nov 12, 2026
9330e24
fix: retry consumed backup marks after storage failures
ben-kaufman Nov 13, 2026
7fac7ab
fix: retain backup marks before wallet retirement
ben-kaufman Nov 13, 2026
78d65fe
fix: resume backups after cancelled wallet wipe
ben-kaufman Nov 14, 2026
c4d9939
Merge master into restore identity background recovery
ben-kaufman Nov 14, 2026
dca0a5b
test: retain backup wipe controls with swap cleanup dependency
ben-kaufman Nov 14, 2026
7de4f23
Merge pull request #1688 from synonymdev/fix/profile-delete-session-r…
ovitrif Nov 26, 2026
e5b5c96
Merge pull request #1690 from synonymdev/fix/profile-cleanup-outcomes
ovitrif Nov 26, 2026
0fd9345
chore: merge restore identity background into profile removal ownership
ovitrif Nov 26, 2026
2ee2eb7
Merge pull request #1693 from synonymdev/fix/profile-removal-ownership
ovitrif Nov 26, 2026
a24e8a5
chore: merge restore identity background into backup observer lifecycle
ovitrif Nov 26, 2026
1f956ba
Merge pull request #1689 from synonymdev/fix/backup-observer-lifecycle
ovitrif Nov 26, 2026
b5c6b3b
chore: merge master into restore identity background
ovitrif Nov 26, 2026
3c2682a
fix: reconcile stack tests and wipe order with master
ovitrif Nov 26, 2026
077de6d
Merge remote-tracking branch 'origin/master' into fix/restore-identit…
ovitrif Nov 29, 2026
438a161
fix: keep spark out of a wallet a pending reset holds
ovitrif Nov 29, 2026
c8c3402
fix: let a wallet change cancel on-chain receipt handlers quietly
ovitrif Nov 29, 2026
89e28e4
chore: merge this pr's changelog fragments into one
ovitrif Nov 29, 2026
a78b556
fix: start spark only once the lifecycle lock admits the wallet
ovitrif Nov 29, 2026
5c7df26
chore: say pending backups retry after connection failures
ovitrif Nov 29, 2026
ae66286
Merge remote-tracking branch 'origin/master' into fix/restore-identit…
ovitrif Nov 30, 2026
bc6b171
Merge remote-tracking branch 'origin/master' into fix/restore-identit…
ovitrif Dec 2, 2026
0294558
fix: keep payment alerts and reset progress while work drains
ovitrif Dec 2, 2026
198f3e3
fix: let reset interrupt a stalled session restore
ovitrif Dec 2, 2026
94c7e21
fix: retry the session restore when reset fails
ovitrif Dec 3, 2026
f166072
fix: keep resumed restores out of pending teardown
ovitrif Dec 3, 2026
d22508b
fix: stop queued paykit work from delaying reset
ovitrif Dec 3, 2026
e53c2a7
fix: detect wipe refusals through wrapped errors
ovitrif Dec 3, 2026
0625a27
Merge master into fix/restore-identity-background
ovitrif Dec 3, 2026
84599e3
fix: release unwritten removal sessions and fail vss timeouts
ovitrif Dec 3, 2026
5d94c53
Merge branch 'master' into fix/restore-identity-background
ovitrif Dec 3, 2026
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
132 changes: 121 additions & 11 deletions app/src/androidTest/java/to/bitkit/ui/RootDestinationTest.kt
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package to.bitkit.ui

import androidx.compose.material3.Text
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.test.junit4.v2.createComposeRule
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick
import org.junit.Rule
import org.junit.Test
import kotlin.test.assertEquals
import to.bitkit.data.WalletResetRecovery
import to.bitkit.test.annotations.ComposeUi
import to.bitkit.ui.screens.MigrationRecoveryScreen
import to.bitkit.ui.theme.AppThemeSurface

@ComposeUi
class RootDestinationTest {
Expand All @@ -18,30 +24,131 @@ class RootDestinationTest {
private fun setContent(
isCriticalUpdateRequired: Boolean = false,
isShowingMigrationLoading: Boolean = false,
isCheckingRNMigration: Boolean = false,
isRNMigrationUnavailable: Boolean = false,
walletExists: Boolean = true,
isRecoveryMode: Boolean = false,
walletResetRecovery: WalletResetRecovery = WalletResetRecovery.Clear,
) {
composeTestRule.setContent {
RootDestination(
isCriticalUpdateRequired = isCriticalUpdateRequired,
isShowingMigrationLoading = isShowingMigrationLoading,
walletExists = walletExists,
isRecoveryMode = isRecoveryMode,
criticalUpdate = { Text(text = "critical", modifier = Modifier.testTag(TAG_CRITICAL)) },
migrationLoading = { Text(text = "migration", modifier = Modifier.testTag(TAG_MIGRATION)) },
onboarding = { Text(text = "onboarding", modifier = Modifier.testTag(TAG_ONBOARDING)) },
wallet = { Text(text = "wallet", modifier = Modifier.testTag(TAG_WALLET)) },
)
AppThemeSurface {
RootDestination(
isCriticalUpdateRequired = isCriticalUpdateRequired,
isShowingMigrationLoading = isShowingMigrationLoading,
isCheckingRNMigration = isCheckingRNMigration,
isRNMigrationUnavailable = isRNMigrationUnavailable,
walletExists = walletExists,
isRecoveryMode = isRecoveryMode,
walletResetRecovery = walletResetRecovery,
resetRecovery = { Text(text = "reset", modifier = Modifier.testTag(TAG_RESET)) },
criticalUpdate = { Text(text = "critical", modifier = Modifier.testTag(TAG_CRITICAL)) },
migrationLoading = { Text(text = "migration", modifier = Modifier.testTag(TAG_MIGRATION)) },
migrationRecovery = { MigrationRecoveryScreen(onRetry = {}) },
onboarding = { Text(text = "onboarding", modifier = Modifier.testTag(TAG_ONBOARDING)) },
wallet = { Text(text = "wallet", modifier = Modifier.testTag(TAG_WALLET)) },
)
}
}
}

private fun assertOnly(tag: String) {
composeTestRule.onNodeWithTag(tag).assertExists()
listOf(TAG_CRITICAL, TAG_MIGRATION, TAG_ONBOARDING, TAG_WALLET)
listOf(TAG_CRITICAL, TAG_MIGRATION, TAG_MIGRATION_ERROR, TAG_ONBOARDING, TAG_WALLET, TAG_RESET)
.filterNot { it == tag }
.forEach { composeTestRule.onNodeWithTag(it).assertDoesNotExist() }
}

@Test
fun migrationAdmissionPrecedesOnboarding() {
setContent(walletExists = false, isCheckingRNMigration = true)
assertOnly(TAG_MIGRATION)
}

@Test
fun recoveryModeCannotBypassMigrationAdmission() {
setContent(walletExists = false, isRecoveryMode = true, isCheckingRNMigration = true)
assertOnly(TAG_MIGRATION)
}

@Test
fun unreadableCleanupKeepsItsRetryAheadOfMigrationAdmission() {
setContent(
isCheckingRNMigration = true,
isRNMigrationUnavailable = true,
walletResetRecovery = WalletResetRecovery.Unavailable,
)
assertOnly(TAG_RESET)
}

@Test
fun unavailableMigrationOffersRetryBeforeWalletAndRecoveryMode() {
val unavailable = mutableStateOf(true)
val checking = mutableStateOf(true)
var retries = 0
composeTestRule.setContent {
AppThemeSurface {
RootDestination(
isCriticalUpdateRequired = false,
isShowingMigrationLoading = false,
isCheckingRNMigration = checking.value,
isRNMigrationUnavailable = unavailable.value,
walletExists = true,
isRecoveryMode = true,
walletResetRecovery = WalletResetRecovery.Clear,
resetRecovery = { Text("reset", Modifier.testTag(TAG_RESET)) },
criticalUpdate = { Text("critical", Modifier.testTag(TAG_CRITICAL)) },
migrationLoading = { Text("migration", Modifier.testTag(TAG_MIGRATION)) },
migrationRecovery = {
MigrationRecoveryScreen(onRetry = {
retries++
unavailable.value = false
})
},
onboarding = { Text("onboarding", Modifier.testTag(TAG_ONBOARDING)) },
wallet = { Text("wallet", Modifier.testTag(TAG_WALLET)) },
)
}
}
assertOnly(TAG_MIGRATION_ERROR)
composeTestRule.onNodeWithTag("MigrationReadRetry").performClick()
assertOnly(TAG_MIGRATION)
composeTestRule.runOnIdle {
assertEquals(1, retries)
checking.value = false
}
assertOnly(TAG_WALLET)
}

@Test
fun unavailableMigrationPrecedesFreshOnboarding() {
setContent(walletExists = false, isCheckingRNMigration = true, isRNMigrationUnavailable = true)
assertOnly(TAG_MIGRATION_ERROR)
}

@Test
fun pendingResetPrecedesOnboardingAndRecoveryMode() {
setContent(walletExists = false, isRecoveryMode = true, walletResetRecovery = WalletResetRecovery.Pending("test"))
assertOnly(TAG_RESET)
}

@Test
fun unreadableResetStateBlocksOrdinaryWallet() {
setContent(walletResetRecovery = WalletResetRecovery.Unavailable)
assertOnly(TAG_RESET)
}

@Test
fun corruptedResetStateDoesNotOpenWalletOrOnboarding() {
setContent(walletExists = false, isRecoveryMode = true, walletResetRecovery = WalletResetRecovery.Unreadable("test"))
assertOnly(TAG_RESET)
}

@Test
fun loadingResetStateBlocksOnboarding() {
setContent(walletExists = false, walletResetRecovery = WalletResetRecovery.Loading)
assertOnly(TAG_RESET)
}

@Test
fun whenCriticalUpdateRequiredDuringMigration_shouldShowCriticalUpdateOnly() {
setContent(isCriticalUpdateRequired = true, isShowingMigrationLoading = true)
Expand Down Expand Up @@ -108,5 +215,8 @@ class RootDestinationTest {

private const val TAG_CRITICAL = "TestCriticalUpdate"
private const val TAG_MIGRATION = "TestMigrationLoading"
private const val TAG_MIGRATION_ERROR = "MigrationRecovery"
private const val TAG_ONBOARDING = "TestOnboarding"
private const val TAG_WALLET = "TestWallet"

private const val TAG_RESET = "TestWalletReset"
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
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,
onLocalDisconnect = { error("Fresh local disconnect is not part of this recovery scenario") },
onDismissAddLinkSheet = {}, onSaveLink = { _, _ -> }, onDismissAddTagSheet = {}, onSaveTag = {},
)
}
}
}
}
}
Loading