Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 WooCommerce/Classes/Extensions/Booking+Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ extension Booking {
.joined(separator: " • ")
}

var isOrderValid: Bool {
return orderID != 0
Copy link
Contributor

@itsmeichigo itsmeichigo Nov 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we should use orderID > 0 instead, as a negative number should be invalid too. Also, should we rename the property to hasAssociatedOrder?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in d059642

}

private enum Localization {
static let guest = NSLocalizedString(
"bookings.guest",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class BookingDetailsViewModel: ObservableObject {

@Published private(set) var navigationTitle = ""
@Published private(set) var sections: [Section] = []
@Published private(set) var isViewOrderAvailable = true
@Published var notice: Notice?

var bookingAttendanceStatus: BookingAttendanceStatus {
Expand Down Expand Up @@ -83,6 +84,7 @@ private extension BookingDetailsViewModel {

func updateDisplayProperties(from booking: Booking) {
navigationTitle = Self.navigationTitle(for: booking)
isViewOrderAvailable = booking.isOrderValid

headerContent.update(with: booking)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ extension BookingDetailsViewModel {

actions = [
.markAsPaid,
.issueRefund,
.viewOrder
]
.issueRefund
] + (booking.isOrderValid ? [.viewOrder] : [])
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ struct BookingDetailsView: View {
Button(Localization.markAsPaid) {
print("On mark as paid tap")
}
Button(Localization.viewOrder) {
viewModel.navigateToOrderDetails()
if viewModel.isViewOrderAvailable {
Button(Localization.viewOrder) {
viewModel.navigateToOrderDetails()
}
}
Button(Localization.cancelBookingAction, role: .destructive) {
print("On cancel booking tap")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,4 +357,31 @@ final class BookingDetailsViewModelTests: XCTestCase {

XCTAssertFalse(containsAttendanceSection)
}

func test_view_order_is_hidden_when_booking_order_id_is_invalid() {
// Given
let booking = Booking.fake().copy(
orderID: 0
)

// When
let viewModel = BookingDetailsViewModel(booking: booking, stores: storesManager)

// Then
let paymentSection = viewModel.sections.first { section in
if case .payment = section.content {
return true
}
return false
}

guard let paymentSection = paymentSection,
case let .payment(paymentContent) = paymentSection.content else {
XCTFail("Payment section not found")
return
}

XCTAssertFalse(viewModel.isViewOrderAvailable)
XCTAssertFalse(paymentContent.actions.contains(.viewOrder))
}
}
Loading