Skip to content

Commit ddad2ae

Browse files
author
Artyom Vlasov
authored
Merge pull request #19760 from wordpress-mobile/fix/19758-InvalidWizardStep
If the step index saved in the instance state is invalid reset the wizard
2 parents 3d55ca2 + bf6fe27 commit ddad2ae

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

WordPress/src/main/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVM.kt

+7-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,13 @@ class SiteCreationMainVM @Inject constructor(
169169
} else {
170170
siteCreationState = requireNotNull(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE))
171171
val currentStepIndex = savedInstanceState.getInt(KEY_CURRENT_STEP)
172-
wizardManager.setCurrentStepIndex(currentStepIndex)
172+
try {
173+
wizardManager.setCurrentStepIndex(currentStepIndex)
174+
} catch (e: IllegalStateException) {
175+
// If the current step index is invalid, we reset the wizard
176+
wizardManager.setCurrentStepIndex(0)
177+
AppLog.e(T.THEMES, "Resetting site creation wizard: ${e.message}")
178+
}
173179
}
174180
isStarted = true
175181
}

WordPress/src/test/java/org/wordpress/android/ui/sitecreation/SiteCreationMainVMTest.kt

+13
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,19 @@ class SiteCreationMainVMTest : BaseUnitTest() {
364364
verify(tracker, times(1)).trackSiteCreationAccessed(SiteCreationSource.UNSPECIFIED)
365365
}
366366

367+
@Test
368+
fun `given instance state returns an invalid step, when start, then site creation is reset`() {
369+
val expectedState = SiteCreationState(segmentId = SEGMENT_ID)
370+
whenever(savedInstanceState.getParcelableCompat<SiteCreationState>(KEY_SITE_CREATION_STATE))
371+
.thenReturn(expectedState)
372+
whenever(savedInstanceState.getInt(KEY_CURRENT_STEP)).thenReturn(-1) // Invalid step
373+
374+
val newViewModel = getNewViewModel()
375+
newViewModel.start(savedInstanceState, SiteCreationSource.UNSPECIFIED)
376+
377+
assertEquals(0, wizardManager.currentStep)
378+
}
379+
367380
private fun currentWizardState(vm: SiteCreationMainVM) = vm.navigationTargetObservable.lastEvent!!.wizardState
368381

369382
private fun getNewViewModel() = SiteCreationMainVM(

0 commit comments

Comments
 (0)