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

[Order Editing] Show exit confirmation for unsynced changes in a split view #15394

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
*** PLEASE FOLLOW THIS FORMAT: [<priority indicator, more stars = higher priority>] <description> [<PR URL>]
*** Use [*****] to indicate smoke tests of all critical flows should be run on the final IPA before release (e.g. major library or OS update).

22.1
-----
- [*] Order Creation: Resolved an issue where the exit confirmation was not displayed when there were unsaved changes in a split view [https://github.com/woocommerce/woocommerce-ios/pull/15394].

22.0
-----
- [*] Payments: Puerto Rico is now available in the list of countries that are supported by In-Person Payments, when using WooPayments [https://github.com/woocommerce/woocommerce-ios/pull/14972]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,10 @@ final class EditableOrderViewModel: ObservableObject {
switch flow {
case .creation: // Creation can be dismissed when there aren't changes pending to commit.
return !hasChanges
case .editing: // Editing can always be dismissed because changes are committed instantly.
return true
case .editing:
// In a single-view layout: Editing can always be dismissed because changes are committed instantly.
// In a split-view layout: Editing can be dismissed when there aren't product changes pending to recalculate.
return !(selectionSyncApproach == .onRecalculateButtonTap && syncRequired)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ private extension OrderFormHostingController {
}

func discardOrderAndDismiss() {
viewModel.discardOrder()
if viewModel.flow == .creation {
viewModel.discardOrder()
}
dismiss(animated: true)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3312,6 +3312,45 @@ final class EditableOrderViewModelTests: XCTestCase {
assertEqual(customerData.billing, orderToUpdate.billingAddress)
assertEqual(customerData.shipping, orderToUpdate.shippingAddress)
}

func test_canBeDismissed_whenEditing_withNoChanges_returnsTrue() {
// Given
let initialOrder = Order.fake()
let viewModel = EditableOrderViewModel(siteID: 123, flow: .editing(initialOrder: initialOrder))

// When
viewModel.selectionSyncApproach = .onRecalculateButtonTap
viewModel.syncRequired = false

// Then
XCTAssertTrue(viewModel.canBeDismissed)
}

func test_canBeDismissed_whenEditing_withPendingRecalculation_returnsFalse() {
// Given
let initialOrder = Order.fake()
let viewModel = EditableOrderViewModel(siteID: 123, flow: .editing(initialOrder: initialOrder))

// When
viewModel.selectionSyncApproach = .onRecalculateButtonTap
viewModel.syncRequired = true

// Then
XCTAssertFalse(viewModel.canBeDismissed)
}

func test_canBeDismissed_whenEditing_withImmediateSync_returnsTrue() {
// Given
let initialOrder = Order.fake()
let viewModel = EditableOrderViewModel(siteID: 123, flow: .editing(initialOrder: initialOrder))

// When
viewModel.selectionSyncApproach = .immediate
viewModel.syncRequired = true

// Then
XCTAssertTrue(viewModel.canBeDismissed)
}
}

private extension EditableOrderViewModelTests {
Expand Down