File tree Expand file tree Collapse file tree 2 files changed +20
-1
lines changed
main/java/org/wordpress/android/ui/sitecreation
test/java/org/wordpress/android/ui/sitecreation Expand file tree Collapse file tree 2 files changed +20
-1
lines changed Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 (
You can’t perform that action at this time.
0 commit comments