-
Notifications
You must be signed in to change notification settings - Fork 109
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 totals logic to TotalsViewModel
#13211
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.
|
* trunk: Add a test case on `CartViewModel.removeItemFromCart`. Update tests Always fetch GLA from remote instead of relying on storage Update slug for GLA Update tests for DefaultGoogleAdsEligibilityChecker Add a comment regarding the plugin version limit Add tests for DefaultGoogleAdsEligibilityChecker Update MockFeatureFlagService Check google ads connection for Google ads Add GoogleAdsEligibilityChecker Add new feature flag googleAdsCampaignCreationOnWebView
var isShimmering: Bool { | ||
isSyncingOrder | ||
} | ||
|
||
var isPriceFieldRedacted: Bool { | ||
formattedOrderTotalTaxPrice == nil || isSyncingOrder | ||
} | ||
|
||
var isTotalPriceFieldRedacted: Bool { | ||
formattedOrderTotalPrice == nil || isSyncingOrder | ||
} |
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.
I like these descriptive view properties 💯
@@ -78,10 +95,6 @@ struct TotalsView: View { | |||
] | |||
} | |||
} | |||
|
|||
private var paymentButtonsDisabled: Bool { |
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.
This appears to be unused, thanks for cleaning it up.
@@ -0,0 +1,15 @@ | |||
import XCTest | |||
|
|||
final class TotalsViewModelTests: XCTestCase { |
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.
@iamgabrielma 👋 since the PR is already pretty big, maybe we can add the test cases in a separate PR?
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.
That sounds good, I've opened a separate issue so we can handle those: #13217
allProducts: allItems) | ||
self.order = order | ||
isSyncingOrder = false | ||
// TODO: this is temporary solution |
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.
@jaclync Do you know if there is any P2/thread/reference to what the non-temporary solution should be? We can add a link here for context.
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.
Good question, this TODO comment was in trunk before this PR. I just checked the history, It looks like it's from this PR comment: https://github.com/woocommerce/woocommerce-ios/pull/13099/files#r1647370089
@bozidarsevo would you like to share a link here if there is a GitHub issue or some reference about the following plan?
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.
Looks good! :)
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.
Looks good, test cases also work well 👍
@@ -39,19 +39,6 @@ struct PointOfSaleDashboardView: View { | |||
} | |||
.toolbarBackground(Color.toolbarBackground, for: .bottomBar) | |||
.toolbarBackground(.visible, for: .bottomBar) | |||
.sheet(isPresented: $viewModel.showsCardReaderSheet, content: { |
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.
This needs to be here because now the "Connect now" button in toolbar does not work.
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.
now it only works if the totals are presented.
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.
Ohh great catch! I will fix this today.
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.
I was looking at this now and even if I change to how it was the sheet does not show, did we change something behind the scenes on how we set showsCardReaderSheet?
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.
I was looking at this now and even if I change to how it was the sheet does not show, did we change something behind the scenes on how we set showsCardReaderSheet?
It does work for me with the changes on #13226, can you check if you can still reproduce the issue on that branch?
Part of #12998
Description
This PR is part 3 (and last) of splitting
PointOfSaleDashboardViewModel
responsibilities based on the 3 main views in POS:As order syncing and payment collection work hand in hand, the move of both parts is in the same PR to also unblock other work affected by the view models like Bozidar's UI updates #13166.
Most of the diffs move code from
PointOfSaleDashboardViewModel
toTotalsViewModel
with minimum changes and reorganization in the file to privatize the methods as much as possible.TotalsView
still depends onPointOfSaleDashboardViewModel
for starting a new transaction and to provide the cart items & POS items for calculating the total amount manually after an order sync failure, we can consider refactoring in the future.Changes
TotalsViewModel
, which encapsulates most of totals and payments logicTesting
Prerequisite: the store is eligible for POS and the feature switch is enabled in Menu > Settings > Experimental Features > POS
Checkout
--> the order total should be updated to a correct, non-zero valueCollect Payment
and proceed to tap a card to pay --> the transaction should succeedNew transaction
and repeat the above steps --> the second transaction should succeedExit POS
and go to the orders tab --> the two orders should be shown as completed