@@ -265,7 +265,7 @@ internal class AddressElementActivityTest {
265265 }
266266
267267 @Test
268- fun `standalone shipping can be canceled with close before saving` () = runScenario(
268+ fun `standalone unchanged input can be canceled with close before saving` () = runScenario(
269269 args = AddressElementActivityContract .Args .Standalone (
270270 apiConfiguration = DEFAULT_API_CONFIG ,
271271 config = AddressLauncher .Configuration .Builder ()
@@ -276,6 +276,7 @@ internal class AddressElementActivityTest {
276276 addressPage.assertReadyToSave()
277277 addressPage.clickClose()
278278
279+ addressPage.assertDiscardConfirmationNotDisplayed()
279280 assertThat(awaitStandaloneResult()).isEqualTo(AddressLauncherResult .Canceled ())
280281 }
281282
@@ -330,7 +331,7 @@ internal class AddressElementActivityTest {
330331 }
331332
332333 @Test
333- fun `checkout shipping root back requests confirmation without popping input` () = runScenario {
334+ fun `checkout shipping can be canceled with root back before saving without popping input` () = runScenario {
334335 addressPage.assertReadyToSave()
335336
336337 activityScenario.onActivity { activity ->
@@ -344,23 +345,42 @@ internal class AddressElementActivityTest {
344345 .isSameInstanceAs(inputEntry)
345346 }
346347
347- addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
348- assertThat(activityScenario.state).isEqualTo(Lifecycle .State .RESUMED )
349- addressPage.discardChanges()
348+ assertThat(awaitResult()).isEqualTo(AddressElementActivityContract .Result .Canceled )
349+ }
350+
351+ @Test
352+ fun `checkout shipping can be canceled with scrim accessibility action before saving` () = runScenario {
353+ addressPage.assertReadyToSave()
354+ addressPage.dismissViaScrimAccessibilityAction()
350355
351356 assertThat(awaitResult()).isEqualTo(AddressElementActivityContract .Result .Canceled )
352357 }
353358
354359 @Test
355- fun `checkout shipping scrim requests confirmation before canceling` () = runScenario {
356- assertCheckoutDismissalRequestsConfirmation {
360+ fun `checkout shipping close confirms edited input and cancel preserves the form` () = runScenario {
361+ assertDirtyDismissal(editedName = EDITED_NAME ) { addressPage.clickClose() }
362+ }
363+
364+ @Test
365+ fun `checkout shipping root back confirms edited input and cancel preserves the form` () = runScenario {
366+ assertDirtyDismissal(editedName = EDITED_NAME ) {
367+ activityScenario.onActivity { activity ->
368+ activity.onBackPressedDispatcher.onBackPressed()
369+ }
370+ }
371+ }
372+
373+ @Test
374+ fun `checkout shipping scrim confirms edited input and cancel preserves the form` () = runScenario {
375+ assertDirtyDismissal(editedName = EDITED_NAME ) {
357376 addressPage.dismissViaScrimAccessibilityAction()
358377 }
359378 }
360379
361380 @Test
362381 fun `finished cancellation allows the sheet to hide without requesting confirmation again` () = runScenario {
363382 addressPage.assertReadyToSave()
383+ addressPage.editName(EDITED_NAME )
364384
365385 activityScenario.onActivity { activity ->
366386 val stateHolder = ViewModelProvider (activity)[AddressElementViewModel ::class .java].resultStateHolder
@@ -482,30 +502,32 @@ internal class AddressElementActivityTest {
482502 }
483503
484504 @Test
485- fun `checkout shipping close requests confirmation before canceling` () = runScenario {
486- assertCheckoutDismissalRequestsConfirmation {
487- addressPage.clickClose()
488- }
505+ fun `checkout shipping can be canceled with close before saving` () = runScenario {
506+ addressPage.assertReadyToSave()
507+ addressPage.clickClose()
508+
509+ assertThat(awaitResult()).isEqualTo(AddressElementActivityContract .Result .Canceled )
489510 }
490511
491512 @Test
492- fun `checkout shipping canceling discard confirmation preserves edits and enables the form` () = runScenario {
493- addressPage.assertReadyToSave()
494- addressPage.editName(EDITED_NAME )
495-
513+ fun `checkout shipping unchanged name-only input dismisses immediately` () = runScenario(
514+ args = AddressElementActivityContract .Args .CheckoutShipping (
515+ apiConfiguration = DEFAULT_API_CONFIG ,
516+ config = AddressLauncher .Configuration .Builder ().address(AddressDetails (name = " Jenny Rosen" )).build(),
517+ checkoutSessionResponse = CheckoutSessionResponseFactory .create(),
518+ ),
519+ ) {
520+ addressPage.assertName(" Jenny Rosen" )
496521 addressPage.clickClose()
497522
498- addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
499- addressPage.keepEditing()
500523 addressPage.assertDiscardConfirmationNotDisplayed()
501- addressPage.assertName(EDITED_NAME )
502- addressPage.assertReadyToSave()
503- assertThat(activityScenario.state).isEqualTo(Lifecycle .State .RESUMED )
524+ assertThat(awaitResult()).isEqualTo(AddressElementActivityContract .Result .Canceled )
504525 }
505526
506527 @Test
507528 fun `checkout shipping discard dialog survives recreation` () = runScenario {
508529 addressPage.assertReadyToSave()
530+ addressPage.editName(EDITED_NAME )
509531 addressPage.clickClose()
510532 addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
511533
@@ -517,30 +539,91 @@ internal class AddressElementActivityTest {
517539 }
518540
519541 @Test
520- fun `standalone close immediately cancels edited input` () = runScenario(
542+ fun `standalone close confirms edited input and cancel preserves the form ` () = runScenario(
521543 args = standaloneArgs(SHIPPING_ADDRESS ),
522544 ) {
523- assertStandaloneDismissesImmediately (editedName = EDITED_NAME ) { addressPage.clickClose() }
545+ assertDirtyDismissal (editedName = EDITED_NAME ) { addressPage.clickClose() }
524546 }
525547
526548 @Test
527- fun `standalone root back immediately cancels edited input` () = runScenario(
549+ fun `standalone root back confirms edited input and cancel preserves the form ` () = runScenario(
528550 args = standaloneArgs(SHIPPING_ADDRESS ),
529551 ) {
530- assertStandaloneDismissesImmediately(editedName = EDITED_NAME ) {
531- activityScenario.onActivity { it.onBackPressedDispatcher.onBackPressed() }
552+ assertDirtyDismissal(editedName = EDITED_NAME ) {
553+ activityScenario.onActivity { activity ->
554+ activity.onBackPressedDispatcher.onBackPressed()
555+ }
532556 }
533557 }
534558
535559 @Test
536- fun `standalone scrim immediately cancels edited input` () = runScenario(
560+ fun `standalone scrim confirms edited input and cancel preserves the form ` () = runScenario(
537561 args = standaloneArgs(SHIPPING_ADDRESS ),
538562 ) {
539- assertStandaloneDismissesImmediately (editedName = EDITED_NAME ) {
563+ assertDirtyDismissal (editedName = EDITED_NAME ) {
540564 addressPage.dismissViaScrimAccessibilityAction()
541565 }
542566 }
543567
568+ @Test
569+ fun `standalone reverted edits cancel immediately` () = runScenario(
570+ args = standaloneArgs(SHIPPING_ADDRESS ),
571+ ) {
572+ addressPage.assertReadyToSave()
573+ addressPage.editName(EDITED_NAME )
574+ addressPage.editName(requireNotNull(SHIPPING_ADDRESS .name))
575+ addressPage.assertName(requireNotNull(SHIPPING_ADDRESS .name))
576+
577+ addressPage.clickClose()
578+
579+ addressPage.assertDiscardConfirmationNotDisplayed()
580+ assertThat(awaitStandaloneResult()).isEqualTo(AddressLauncherResult .Canceled ())
581+ }
582+
583+ @Test
584+ fun `standalone edited input still requires confirmation after recreation` () = runScenario(
585+ args = standaloneArgs(SHIPPING_ADDRESS ),
586+ ) {
587+ addressPage.assertReadyToSave()
588+ addressPage.editName(EDITED_NAME )
589+ activityScenario.recreate()
590+ activityScenario.onActivity { activity = it }
591+ composeTestRule.waitForIdle()
592+ addressPage.assertName(EDITED_NAME )
593+
594+ addressPage.clickClose()
595+ addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
596+ addressPage.discardChanges()
597+
598+ assertThat(awaitStandaloneResult()).isEqualTo(AddressLauncherResult .Canceled ())
599+ }
600+
601+ @Test
602+ fun `standalone discard confirmation survives recreation and keep editing preserves input` () = runScenario(
603+ args = standaloneArgs(SHIPPING_ADDRESS ),
604+ ) {
605+ addressPage.assertReadyToSave()
606+ addressPage.editName(EDITED_NAME )
607+ addressPage.clickClose()
608+ addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
609+
610+ activityScenario.recreate()
611+ activityScenario.onActivity { activity = it }
612+ composeTestRule.waitForIdle()
613+
614+ addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
615+ addressPage.keepEditing()
616+ addressPage.assertDiscardConfirmationNotDisplayed()
617+ addressPage.assertName(EDITED_NAME )
618+ addressPage.assertReadyToSave()
619+
620+ addressPage.clickClose()
621+ addressPage.assertDiscardConfirmation(PRIMARY_BUTTON_LOADING_INDICATOR_TEST_TAG )
622+ addressPage.discardChanges()
623+
624+ assertThat(awaitStandaloneResult()).isEqualTo(AddressLauncherResult .Canceled ())
625+ }
626+
544627 private fun standaloneArgs (address : AddressDetails ) = AddressElementActivityContract .Args .Standalone (
545628 apiConfiguration = DEFAULT_API_CONFIG ,
546629 config = AddressLauncher .Configuration .Builder ().address(address).build(),
0 commit comments