File tree Expand file tree Collapse file tree 5 files changed +39
-5
lines changed
ViewModels/Booking Details
ViewRelated/Bookings/Booking Details
WooCommerceTests/ViewRelated/Bookings Expand file tree Collapse file tree 5 files changed +39
-5
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ extension Booking {
1919 . joined ( separator: " • " )
2020 }
2121
22+ var hasAssociatedOrder : Bool {
23+ return orderID > 0
24+ }
25+
2226 private enum Localization {
2327 static let guest = NSLocalizedString (
2428 " bookings.guest " ,
Original file line number Diff line number Diff line change @@ -27,6 +27,7 @@ final class BookingDetailsViewModel: ObservableObject {
2727
2828 @Published private( set) var navigationTitle = " "
2929 @Published private( set) var sections : [ Section ] = [ ]
30+ @Published private( set) var isViewOrderAvailable = true
3031 @Published var notice : Notice ?
3132
3233 var bookingAttendanceStatus : BookingAttendanceStatus {
@@ -86,6 +87,7 @@ private extension BookingDetailsViewModel {
8687
8788 func updateDisplayProperties( from booking: Booking ) {
8889 navigationTitle = Self . navigationTitle ( for: booking)
90+ isViewOrderAvailable = booking. hasAssociatedOrder
8991
9092 headerContent. update ( with: booking)
9193
Original file line number Diff line number Diff line change @@ -28,9 +28,8 @@ extension BookingDetailsViewModel {
2828
2929 actions = [
3030 . markAsPaid,
31- . issueRefund,
32- . viewOrder
33- ]
31+ . issueRefund
32+ ] + ( booking. hasAssociatedOrder ? [ . viewOrder] : [ ] )
3433 }
3534 }
3635}
Original file line number Diff line number Diff line change @@ -64,8 +64,10 @@ struct BookingDetailsView: View {
6464 Button ( Localization . markAsPaid) {
6565 print ( " On mark as paid tap " )
6666 }
67- Button ( Localization . viewOrder) {
68- viewModel. navigateToOrderDetails ( )
67+ if viewModel. isViewOrderAvailable {
68+ Button ( Localization . viewOrder) {
69+ viewModel. navigateToOrderDetails ( )
70+ }
6971 }
7072 Button ( Localization . cancelBookingAction, role: . destructive) {
7173 showingCancelAlert = true
Original file line number Diff line number Diff line change @@ -357,4 +357,31 @@ final class BookingDetailsViewModelTests: XCTestCase {
357357
358358 XCTAssertFalse ( containsAttendanceSection)
359359 }
360+
361+ func test_view_order_is_hidden_when_booking_order_id_is_invalid( ) {
362+ // Given
363+ let booking = Booking . fake ( ) . copy (
364+ orderID: 0
365+ )
366+
367+ // When
368+ let viewModel = BookingDetailsViewModel ( booking: booking, stores: storesManager)
369+
370+ // Then
371+ let paymentSection = viewModel. sections. first { section in
372+ if case . payment = section. content {
373+ return true
374+ }
375+ return false
376+ }
377+
378+ guard let paymentSection = paymentSection,
379+ case let . payment( paymentContent) = paymentSection. content else {
380+ XCTFail ( " Payment section not found " )
381+ return
382+ }
383+
384+ XCTAssertFalse ( viewModel. isViewOrderAvailable)
385+ XCTAssertFalse ( paymentContent. actions. contains ( . viewOrder) )
386+ }
360387}
You can’t perform that action at this time.
0 commit comments