-
Notifications
You must be signed in to change notification settings - Fork 114
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
[Woo POS] Extract cart logic to CartViewModel
#13191
Conversation
|
…s-extract-cart-vm * task/12998-pos-extract-item-list-vm: (46 commits) Nit updates. Allow setting a different title for the top performers list Update localized string keys and comments Freeze strings for localization Update metadata strings Update release_notes for 19.3 Update CHANGELOG for 19.3 Ensure Google Campaigns list contains top 5 campaigns by total sales Fix linting error Remove unused imports Add unit tests for Google Campaigns analytics card view model Hide campaign image placeholder when card is redacted Update total sales properties Release Notes: add new section for next version (19.4) Update draft release notes for 19.3. Bump version number Hide image placeholder on Google Campaigns card Add view model for Google Campaigns analytics card Add Google Ads Programs web report Update naming for analytics card to display a stat and list of top performers ...
…12998-pos-extract-cart-vm * task/12998-fix-items-not-set-for-order-sync: Fix order sync from passing empty items for the products. # Conflicts: # WooCommerce/Classes/POS/ViewModels/PointOfSaleDashboardViewModel.swift
Only one review is needed. cc: @staskus just looping you in for awareness, but feel free to review/drop any comment as well 🙇 |
I see few more // TODO: 12998, will there be more extraction PRs for the PointOfSaleDashboardViewModel? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just that question regarding TODOs 👍
👋 I added those TODO comments, and yes they will be moved/extracted from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for updating the preview and tests! I added a test case and tested it for 2 transactions again, LGTM I'll merge it shortly to unblock #13211.
let orderStageSubject = PassthroughSubject<PointOfSaleDashboardViewModel.OrderStage, Never>() | ||
let orderStagePublisher = orderStageSubject.eraseToAnyPublisher() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In SwiftUI preview, we could also pass a constant value like passing Just< PointOfSaleDashboardViewModel.OrderStage >(.building)
to CartViewModel(orderStage:)
. We can potentially have two previews, one for each order stage case.
Would like to see what you think about this change, I will merge the PR without updating this 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for merging, appreciated! 🙇
In SwiftUI preview, we could also pass a constant value like passing Just< PointOfSaleDashboardViewModel.OrderStage >(.building) to CartViewModel(orderStage:). We can potentially have two previews, one for each order stage case.
That sounds good, I've updated #13207 for reference
/* TODO: | ||
https://github.com/woocommerce/woocommerce-ios/issues/13209 | ||
The unique UUID for CartItem is set on init, but CartItem is only internal to addItemToCart() | ||
We need to extract this to a separate function and assure that ID's are correct, | ||
otherwise the UUID's for testing won't match | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this test case, I wonder if we could first add some items by using the cart item from itemsInCart
. I added a simple test case in e15efe2, feel free to add other edge cases in the TODO issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, initially I wanted to test only by id
to assure that we remove the exact "line item" if a cart has multiple of the same productID
, so if we happen to change the implementation, we wouldn't get a false positive from tests if we happen to have just another item with the same name or property in the list.
That said I think testing it like this and adding the followup is good enough for the moment (better than having no test case!). Thanks for tackling it 🙇
Part of #12998
Description
This is the step 2 of #12998 , here we move Cart-related actions and its handling to a separate
CartViewModel
.Its design follows the same pattern as with the product list, we'll observe changes in the model from the dashboard and use these to coordinate and communicate between different subviews. In general:
submitCart(_:)
, emits the cart items to its subscribers.addMoreToCart()
, emits a signal to its subscribers.Changes
CartViewModel
Testing
There's 3 items that I left outside of this PR, since are not totally related to the refactor itself, and can be tackled separately:
CartViewModel
for preview simplicity: [Woo POS] MockCartViewModel
#13207CartItem
: [Woo POS] Improve testability: Consider change unique ID forCartItem
#13209PointOfSaleDashboardViewModel
#13210