File tree Expand file tree Collapse file tree 3 files changed +45
-0
lines changed
WooCommerceTests/POS/ViewHelpers Expand file tree Collapse file tree 3 files changed +45
-0
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,7 @@ private extension CartView {
280280 Text ( Localization . checkoutButtonTitle)
281281 }
282282 . buttonStyle ( POSFilledButtonStyle ( size: . normal) )
283+ . disabled ( CartViewHelper ( ) . hasUnresolvedItems ( cart: posModel. cart) )
283284 }
284285
285286 var backButtonConfiguration : POSPageHeaderBackButtonConfiguration ? {
Original file line number Diff line number Diff line change @@ -27,6 +27,15 @@ struct CartViewHelper {
2727
2828 return cart. purchasableItems. isNotEmpty
2929 }
30+
31+ func hasUnresolvedItems( cart: Cart ) -> Bool {
32+ cart. purchasableItems. contains { item in
33+ if case . loading = item. state {
34+ return true
35+ }
36+ return false
37+ }
38+ }
3039}
3140
3241private extension PointOfSalePaymentState {
Original file line number Diff line number Diff line change @@ -214,6 +214,41 @@ struct CartViewHelperTests {
214214 // When, Then
215215 #expect( sut. shouldShowCheckout ( orderStage: . building, cart: cart) == true )
216216 }
217+
218+ @Test func hasUnresolvedItems_when_cart_is_empty_returns_false( ) async throws {
219+ // Given
220+ let cart = Cart ( )
221+
222+ // When, Then
223+ #expect( sut. hasUnresolvedItems ( cart: cart) == false )
224+ }
225+
226+ @Test func hasUnresolvedItems_when_cart_has_only_loaded_items_returns_false( ) async throws {
227+ // Given
228+ let cart = Cart ( purchasableItems: [ makeItem ( ) ] )
229+
230+ // When, Then
231+ #expect( sut. hasUnresolvedItems ( cart: cart) == false )
232+ }
233+
234+ @Test func hasUnresolvedItems_when_cart_has_loading_item_returns_true( ) async throws {
235+ // Given
236+ let loadingItem = Cart . PurchasableItem. loading ( id: UUID ( ) )
237+ let cart = Cart ( purchasableItems: [ loadingItem] )
238+
239+ // When, Then
240+ #expect( sut. hasUnresolvedItems ( cart: cart) == true )
241+ }
242+
243+ @Test func hasUnresolvedItems_when_cart_has_mixed_items_returns_true( ) async throws {
244+ // Given
245+ let loadingItem = Cart . PurchasableItem. loading ( id: UUID ( ) )
246+ let loadedItem = makeItem ( )
247+ let cart = Cart ( purchasableItems: [ loadingItem, loadedItem] )
248+
249+ // When, Then
250+ #expect( sut. hasUnresolvedItems ( cart: cart) == true )
251+ }
217252}
218253
219254private func makeItem( ) -> Cart . PurchasableItem {
You can’t perform that action at this time.
0 commit comments