Skip to content
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

Merged
merged 9 commits into from
Jul 2, 2024

Conversation

iamgabrielma
Copy link
Contributor

@iamgabrielma iamgabrielma commented Jul 1, 2024

Part of #12998

Description

This PR is part 3 (and last) of splitting PointOfSaleDashboardViewModel responsibilities based on the 3 main views in POS:

  • Item selector
  • Cart view
  • Totals view (this PR)

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 to TotalsViewModel with minimum changes and reorganization in the file to privatize the methods as much as possible.

TotalsView still depends on PointOfSaleDashboardViewModel 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

  • Created TotalsViewModel, which encapsulates most of totals and payments logic
  • CurrencyFormatter is injected from the app to the pos through the entry point
  • Cleanup of unused code
  • Added empty preliminary list of unit test, that will be tackled on a separate PR

Testing

Prerequisite: the store is eligible for POS and the feature switch is enabled in Menu > Settings > Experimental Features > POS

  • Launch app
  • Go to Menu > Point of Sale
  • Add an item (with a non-zero price and ideally with tax applied on checkout) to cart
  • Tap Checkout --> the order total should be updated to a correct, non-zero value
  • Tap Collect Payment and proceed to tap a card to pay --> the transaction should succeed
  • Tap New transaction and repeat the above steps --> the second transaction should succeed
  • Tap Exit POS and go to the orders tab --> the two orders should be shown as completed

@iamgabrielma iamgabrielma added type: task An internally driven task. feature: POS labels Jul 1, 2024
@dangermattic
Copy link
Collaborator

dangermattic commented Jul 1, 2024

2 Warnings
⚠️ View files have been modified, but no screenshot or video is included in the pull request. Consider adding some for clarity.
⚠️ This PR is larger than 500 lines of changes. Please consider splitting it into smaller PRs for easier and faster reviews.
1 Message
📖 This PR is still a Draft: some checks will be skipped.

Generated by 🚫 Danger

@wpmobilebot
Copy link
Collaborator

wpmobilebot commented Jul 1, 2024

WooCommerce iOS📲 You can test the changes from this Pull Request in WooCommerce iOS by scanning the QR code below to install the corresponding build.

App NameWooCommerce iOS WooCommerce iOS
Build Numberpr13211-2e8b444
Version19.3
Bundle IDcom.automattic.alpha.woocommerce
Commit2e8b444
App Center BuildWooCommerce - Prototype Builds #9830
Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.

Base automatically changed from task/12998-pos-extract-cart-vm to trunk July 1, 2024 15:01
* 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
Comment on lines +58 to +68
var isShimmering: Bool {
isSyncingOrder
}

var isPriceFieldRedacted: Bool {
formattedOrderTotalTaxPrice == nil || isSyncingOrder
}

var isTotalPriceFieldRedacted: Bool {
formattedOrderTotalPrice == nil || isSyncingOrder
}
Copy link
Contributor

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 {
Copy link
Contributor

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 {
Copy link
Contributor

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?

Copy link
Contributor Author

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

@jaclync jaclync added this to the 19.4 milestone Jul 1, 2024
allProducts: allItems)
self.order = order
isSyncingOrder = false
// TODO: this is temporary solution
Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@bozidarsevo bozidarsevo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! :)

Copy link
Collaborator

@staskus staskus left a 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 👍

@iamgabrielma iamgabrielma merged commit 1d36ce4 into trunk Jul 2, 2024
23 checks passed
@iamgabrielma iamgabrielma deleted the task/12998-pos-extract-totals-vm branch July 2, 2024 08:45
@@ -39,19 +39,6 @@ struct PointOfSaleDashboardView: View {
}
.toolbarBackground(Color.toolbarBackground, for: .bottomBar)
.toolbarBackground(.visible, for: .bottomBar)
.sheet(isPresented: $viewModel.showsCardReaderSheet, content: {
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature: POS type: task An internally driven task.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants