File tree 2 files changed +20
-1
lines changed
main/java/org/wordpress/android/ui/sitecreation
test/java/org/wordpress/android/ui/sitecreation
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(
169
169
} else {
170
170
siteCreationState = requireNotNull(savedInstanceState.getParcelableCompat(KEY_SITE_CREATION_STATE ))
171
171
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
+ }
173
179
}
174
180
isStarted = true
175
181
}
Original file line number Diff line number Diff line change @@ -364,6 +364,19 @@ class SiteCreationMainVMTest : BaseUnitTest() {
364
364
verify(tracker, times(1 )).trackSiteCreationAccessed(SiteCreationSource .UNSPECIFIED )
365
365
}
366
366
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
+
367
380
private fun currentWizardState (vm : SiteCreationMainVM ) = vm.navigationTargetObservable.lastEvent!! .wizardState
368
381
369
382
private fun getNewViewModel () = SiteCreationMainVM (
You can’t perform that action at this time.
0 commit comments