File tree Expand file tree Collapse file tree 3 files changed +6
-7
lines changed
WooCommerceTests/POS/ViewModels Expand file tree Collapse file tree 3 files changed +6
-7
lines changed Original file line number Diff line number Diff line change @@ -95,9 +95,9 @@ struct CartView: View {
9595 . coordinateSpace ( name: Constants . scrollViewCoordinateSpaceIdentifier)
9696 . onChange ( of: cartViewModel. itemToScrollToWhenCartUpdated? . id) { _ in
9797 if viewModel. orderStage == . building,
98- let last = cartViewModel. itemToScrollToWhenCartUpdated? . id {
98+ let itemToScrollTo = cartViewModel. itemToScrollToWhenCartUpdated? . id {
9999 withAnimation {
100- proxy. scrollTo ( last )
100+ proxy. scrollTo ( itemToScrollTo )
101101 }
102102 }
103103 }
Original file line number Diff line number Diff line change @@ -46,6 +46,7 @@ final class CartViewModel: CartViewModelProtocol {
4646 func addItemToCart( _ item: POSItem ) {
4747 let cartItem = CartItem ( id: UUID ( ) , item: item, quantity: 1 )
4848 itemsInCart. insert ( cartItem, at: 0 )
49+ itemToScrollToWhenCartUpdated = cartItem
4950
5051 analytics. track ( . pointOfSaleAddItemToCart)
5152 }
@@ -58,9 +59,7 @@ final class CartViewModel: CartViewModelProtocol {
5859 itemsInCart. removeAll ( )
5960 }
6061
61- var itemToScrollToWhenCartUpdated : CartItem ? {
62- return itemsInCart. last
63- }
62+ var itemToScrollToWhenCartUpdated : CartItem ?
6463
6564 var itemsInCartLabel : String ? {
6665 switch itemsInCart. count {
Original file line number Diff line number Diff line change @@ -84,15 +84,15 @@ final class CartViewModelTests: XCTestCase {
8484 sut. addItemToCart ( item)
8585 sut. addItemToCart ( anotherItem)
8686 XCTAssertEqual ( sut. itemsInCart. count, 2 )
87- XCTAssertEqual ( sut. itemsInCart. map { $0. item. name } , [ item , anotherItem ] . map { $0. name } )
87+ XCTAssertEqual ( sut. itemsInCart. map { $0. item. name } , [ anotherItem , item ] . map { $0. name } )
8888
8989 // When
9090 let firstCartItem = try XCTUnwrap ( sut. itemsInCart. first)
9191 sut. removeItemFromCart ( firstCartItem)
9292
9393 // Then
9494 XCTAssertEqual ( sut. itemsInCart. count, 1 )
95- XCTAssertEqual ( sut. itemsInCart. map { $0. item. name } , [ anotherItem . name] )
95+ XCTAssertEqual ( sut. itemsInCart. map { $0. item. name } , [ item . name] )
9696 }
9797
9898 func test_cart_when_removeAllItemsFromCart_is_invoked_then_removes_all_items_from_cart( ) {
You can’t perform that action at this time.
0 commit comments