Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix shipping label new experience navigation #13431

Merged
merged 4 commits into from
Jan 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ class WooShippingLabelCreationFragment : BaseFragment(), BackPressListener {
}
}

override fun onRequestAllowBackPress(): Boolean = viewModel.onNavigateBack()
override fun onRequestAllowBackPress(): Boolean = viewModel.allowBackNavigation()
}
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ class WooShippingLabelCreationViewModel @Inject constructor(
customWeight = input
}

fun onNavigateBack(): Boolean {
fun allowBackNavigation(): Boolean {
val state = uiState.value
return when {
state.isAddressSelectionExpanded -> {
Expand All @@ -487,6 +487,10 @@ class WooShippingLabelCreationViewModel @Inject constructor(
}
}

fun onNavigateBack() {
if (allowBackNavigation()) triggerEvent(Event.Exit)
}

data object StartPackageSelection : Event()
data class LabelPurchased(val purchaseData: PurchasedShippingLabelData) : Event()
data class StartOriginAddressEdit(val originAddress: OriginShippingAddress) : Event()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -797,15 +797,15 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
sut.onSelectAddressExpandedChange(true)

// Close address selection
var shouldNavigateBack = sut.onNavigateBack()
var shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isFalse()

// Close shipment details
shouldNavigateBack = sut.onNavigateBack()
shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isFalse()

// Navigate back
shouldNavigateBack = sut.onNavigateBack()
shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isTrue()
}

Expand All @@ -823,11 +823,11 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
sut.onShipmentDetailsExpandedChange(true)

// Close shipment details
var shouldNavigateBack = sut.onNavigateBack()
var shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isFalse()

// Navigate back
shouldNavigateBack = sut.onNavigateBack()
shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isTrue()
}

Expand All @@ -844,7 +844,7 @@ class WooShippingLabelCreationViewModelTest : BaseUnitTest() {
advanceUntilIdle()

// Navigate back
val shouldNavigateBack = sut.onNavigateBack()
val shouldNavigateBack = sut.allowBackNavigation()
assertThat(shouldNavigateBack).isTrue()
}
}