From a57403f730c87362b831b087a8fee933ea2c210a Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 3 Apr 2025 13:37:25 +0700 Subject: [PATCH 01/21] Add error type to POS error state --- .../POS/Models/PointOfSaleErrorState.swift | 63 ++++++++++++++----- 1 file changed, 46 insertions(+), 17 deletions(-) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift b/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift index d7e1bdc1c4a..edf185d4d1e 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift @@ -1,46 +1,75 @@ import Foundation struct PointOfSaleErrorState: Equatable { + enum ErrorType: Equatable { + case productsLoadError + case variationsLoadError + case productsNextPageError + case variationsNextPageError + case couponsNotFound + case couponsLoadError + case couponsDisabled + } + + let errorType: ErrorType let title: String let subtitle: String let buttonText: String static func errorOnLoadingProducts() -> Self { - PointOfSaleErrorState(title: Constants.failedToLoadProductsTitle, - subtitle: Constants.failedToLoadProductsSubtitle, - buttonText: Constants.failedToLoadProductsButtonTitle) + PointOfSaleErrorState( + errorType: .productsLoadError, + title: Constants.failedToLoadProductsTitle, + subtitle: Constants.failedToLoadProductsSubtitle, + buttonText: Constants.failedToLoadProductsButtonTitle) } static func errorOnLoadingVariations() -> Self { - PointOfSaleErrorState(title: Constants.failedToLoadVariationsTitle, - subtitle: Constants.failedToLoadVariationsSubtitle, - buttonText: Constants.failedToLoadVariationsButtonTitle) + PointOfSaleErrorState( + errorType: .variationsLoadError, + title: Constants.failedToLoadVariationsTitle, + subtitle: Constants.failedToLoadVariationsSubtitle, + buttonText: Constants.failedToLoadVariationsButtonTitle) } static func errorOnLoadingProductsNextPage() -> Self { - PointOfSaleErrorState(title: Constants.failedToLoadProductsNextPageTitle, - subtitle: Constants.failedToLoadProductsNextPageSubtitle, - buttonText: Constants.failedToLoadProductsNextPageButtonTitle) + PointOfSaleErrorState( + errorType: .productsNextPageError, + title: Constants.failedToLoadProductsNextPageTitle, + subtitle: Constants.failedToLoadProductsNextPageSubtitle, + buttonText: Constants.failedToLoadProductsNextPageButtonTitle) } static func errorOnLoadingVariationsNextPage() -> Self { - PointOfSaleErrorState(title: Constants.failedToLoadVariationsNextPageTitle, - subtitle: Constants.failedToLoadVariationsNextPageSubtitle, - buttonText: Constants.failedToLoadVariationsNextPageButtonTitle) + PointOfSaleErrorState( + errorType: .variationsNextPageError, + title: Constants.failedToLoadVariationsNextPageTitle, + subtitle: Constants.failedToLoadVariationsNextPageSubtitle, + buttonText: Constants.failedToLoadVariationsNextPageButtonTitle) } static func errorCouponsNotFound() -> Self { - PointOfSaleErrorState(title: Constants.noCouponsFoundTitle, - subtitle: Constants.noCouponsFoundSubtitle, - buttonText: Constants.noCouponsFoundButtonTitle) + PointOfSaleErrorState( + errorType: .couponsNotFound, + title: Constants.noCouponsFoundTitle, + subtitle: Constants.noCouponsFoundSubtitle, + buttonText: Constants.noCouponsFoundButtonTitle) } static func errorOnLoadingCoupons() -> Self { - PointOfSaleErrorState(title: "Error loading coupons", subtitle: "Error loading coupons", buttonText: "Retry") + PointOfSaleErrorState( + errorType: .couponsLoadError, + title: "Error loading coupons", + subtitle: "Error loading coupons", + buttonText: "Retry") } static func errorCouponsDisabled() -> Self { - PointOfSaleErrorState(title: "Error loading coupons", subtitle: "Please enable coupons in WooCommerce Settings, and tap Retry", buttonText: "Retry") + PointOfSaleErrorState( + errorType: .couponsDisabled, + title: "Error loading coupons", + subtitle: "Please enable the use of coupon codes in your store", + buttonText: "Enable") } enum Constants { From 9265da80ddf7544b0646c34d9b4d36779ced61cf Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 3 Apr 2025 13:41:06 +0700 Subject: [PATCH 02/21] adapt error view action to accept different callbacks --- .../UI States/PointOfSaleItemListErrorView.swift | 10 +++++----- .../PointOfSaleItemListFullscreenErrorView.swift | 10 +++++----- .../PointOfSaleItemListFullscreenView.swift | 2 +- .../Presentation/Item Selector/ChildItemList.swift | 2 +- .../Classes/POS/Presentation/ItemListView.swift | 2 +- .../Presentation/PointOfSaleDashboardView.swift | 14 +++++++++++--- 6 files changed, 24 insertions(+), 16 deletions(-) diff --git a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListErrorView.swift b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListErrorView.swift index b80c3121f76..f933a0019ee 100644 --- a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListErrorView.swift +++ b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListErrorView.swift @@ -3,11 +3,11 @@ import SwiftUI /// A view that displays an error message with a retry CTA when the list of POS items fails to load. struct PointOfSaleItemListErrorView: View { private let error: PointOfSaleErrorState - private let onRetry: (() -> Void)? + private let onAction: (() -> Void)? - init(error: PointOfSaleErrorState, onRetry: (() -> Void)? = nil) { + init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil) { self.error = error - self.onRetry = onRetry + self.onAction = onAction } var body: some View { @@ -33,7 +33,7 @@ struct PointOfSaleItemListErrorView: View { Spacer().frame(height: PointOfSaleCardPresentPaymentLayout.textAndButtonSpacing) Button(action: { - onRetry?() + onAction?() }, label: { Text(error.buttonText) }) @@ -47,5 +47,5 @@ struct PointOfSaleItemListErrorView: View { } #Preview { - PointOfSaleItemListErrorView(error: .errorOnLoadingProducts(), onRetry: nil) + PointOfSaleItemListErrorView(error: .errorOnLoadingProducts(), onAction: nil) } diff --git a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenErrorView.swift b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenErrorView.swift index b0841b26fce..03bed0e00f0 100644 --- a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenErrorView.swift +++ b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenErrorView.swift @@ -3,20 +3,20 @@ import SwiftUI /// A view that displays an error message with a retry CTA when the list of products fails to load. struct PointOfSaleItemListFullscreenErrorView: View { private let error: PointOfSaleErrorState - private let onRetry: (() -> Void)? + private let onAction: (() -> Void)? - init(error: PointOfSaleErrorState, onRetry: (() -> Void)? = nil) { + init(error: PointOfSaleErrorState, onAction: (() -> Void)? = nil) { self.error = error - self.onRetry = onRetry + self.onAction = onAction } var body: some View { PointOfSaleItemListFullscreenView { - PointOfSaleItemListErrorView(error: error, onRetry: onRetry) + PointOfSaleItemListErrorView(error: error, onAction: onAction) } } } #Preview { - PointOfSaleItemListFullscreenErrorView(error: .errorOnLoadingProducts(), onRetry: nil) + PointOfSaleItemListFullscreenErrorView(error: .errorOnLoadingProducts(), onAction: nil) } diff --git a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenView.swift b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenView.swift index 2fde1d52f32..6222f88d24e 100644 --- a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenView.swift +++ b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/PointOfSaleItemListFullscreenView.swift @@ -31,6 +31,6 @@ private enum Localization { PointOfSaleItemListFullscreenView( content: { PointOfSaleItemListErrorView( - error: .init(title: "Error", subtitle: "Something went wrong", buttonText: "Fix it")) + error: .init(errorType: .productsLoadError, title: "Error", subtitle: "Something went wrong", buttonText: "Fix it")) }) } diff --git a/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift b/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift index 38ad8e3df57..3c0c3002afc 100644 --- a/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift +++ b/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift @@ -83,7 +83,7 @@ private extension ChildItemList { Spacer() } - PointOfSaleItemListErrorView(error: error, onRetry: { + PointOfSaleItemListErrorView(error: error, onAction: { Task { await posModel.loadItems(base: .parent(parentItem)) } diff --git a/WooCommerce/Classes/POS/Presentation/ItemListView.swift b/WooCommerce/Classes/POS/Presentation/ItemListView.swift index 27b37b6eb5b..aa72b2818f4 100644 --- a/WooCommerce/Classes/POS/Presentation/ItemListView.swift +++ b/WooCommerce/Classes/POS/Presentation/ItemListView.swift @@ -62,7 +62,7 @@ struct ItemListView: View { listView(items) case .error(let errorState): if errorState == .errorCouponsNotFound() { - PointOfSaleItemListErrorView(error: .errorCouponsNotFound(), onRetry: { + PointOfSaleItemListErrorView(error: .errorCouponsNotFound(), onAction: { // TODO }) } else { diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index a0fe45a0d66..d354d9fc76a 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -25,9 +25,17 @@ struct PointOfSaleDashboardView: View { PointOfSaleItemListEmptyView(base: .root) } case .error(let errorContents): - PointOfSaleItemListFullscreenErrorView(error: errorContents, onRetry: { - Task { - await posModel.loadItems(base: .root) + PointOfSaleItemListFullscreenErrorView(error: errorContents, onAction: { + if errorContents.errorType == .couponsDisabled { + Task { + //TODO + // 1. Enable coupons + // 2. refreshItems + } + } else { + Task { + await posModel.loadItems(base: .root) + } } }) case .content: From 451bc5546a40054b034709e413a7f293558466a1 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 3 Apr 2025 13:59:15 +0700 Subject: [PATCH 03/21] enable coupons when tap on cta --- .../PointOfSaleDashboardView.swift | 34 +++++++++++++++---- .../PointOfSaleCouponService.swift | 4 +-- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index d354d9fc76a..09f7e7ed914 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -1,4 +1,5 @@ import SwiftUI +import enum Yosemite.SettingAction @available(iOS 17.0, *) struct PointOfSaleDashboardView: View { @@ -24,13 +25,12 @@ struct PointOfSaleDashboardView: View { PointOfSaleItemListFullscreenView { PointOfSaleItemListEmptyView(base: .root) } - case .error(let errorContents): - PointOfSaleItemListFullscreenErrorView(error: errorContents, onAction: { - if errorContents.errorType == .couponsDisabled { + case .error(let error): + PointOfSaleItemListFullscreenErrorView(error: error, onAction: { + if error.errorType == .couponsDisabled { Task { - //TODO - // 1. Enable coupons - // 2. refreshItems + await enableCoupons() + await posModel.loadItems(base: .root) } } else { Task { @@ -171,6 +171,28 @@ extension EnvironmentValues { } } +@available(iOS 17.0, *) +private extension PointOfSaleDashboardView { + func enableCoupons() async { + guard let siteID = ServiceLocator.stores.sessionManager.defaultStoreID else { + return + } + _ = await withCheckedContinuation { continuation in + let action = SettingAction.enableCouponSetting(siteID: siteID) { result in + switch result { + case .success: + continuation.resume(returning: true) + case let .failure(error): + continuation.resume(returning: false) + } + } + Task { @MainActor in + ServiceLocator.stores.dispatch(action) + } + } + } +} + @available(iOS 17.0, *) private extension PointOfSaleDashboardView { enum Constants { diff --git a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift index d040ec2c866..14e6d959ef7 100644 --- a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift +++ b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift @@ -125,10 +125,8 @@ private extension PointOfSaleCouponService { let action = SettingAction.retrieveCouponSetting(siteID: siteID) { result in switch result { case let .success(isEnabled): - debugPrint("Coupons enabled? \(isEnabled)") continuation.resume(returning: isEnabled) - case let .failure(error): - debugPrint("Coupons settings error: \(error)") + case .failure: continuation.resume(returning: false) } } From c1cc174e1ca2da5d46cd04f9e6cafe226962c274 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 3 Apr 2025 14:08:38 +0700 Subject: [PATCH 04/21] refactor for simplicity --- .../POS/Presentation/PointOfSaleDashboardView.swift | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 09f7e7ed914..76a5bf94570 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -27,15 +27,11 @@ struct PointOfSaleDashboardView: View { } case .error(let error): PointOfSaleItemListFullscreenErrorView(error: error, onAction: { - if error.errorType == .couponsDisabled { - Task { + Task { + if error.errorType == .couponsDisabled { await enableCoupons() - await posModel.loadItems(base: .root) - } - } else { - Task { - await posModel.loadItems(base: .root) } + await posModel.loadItems(base: .root) } }) case .content: From 1c84292a41f934a74e328853c15aed2ec55198cd Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Thu, 3 Apr 2025 14:22:50 +0700 Subject: [PATCH 05/21] make test compile --- .../POS/Controllers/PointOfSaleItemsControllerTests.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleItemsControllerTests.swift b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleItemsControllerTests.swift index 5fe971cc7d4..f847f3b801d 100644 --- a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleItemsControllerTests.swift +++ b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleItemsControllerTests.swift @@ -277,7 +277,8 @@ final class PointOfSaleItemsControllerTests { let sut = PointOfSaleItemsController(itemProvider: itemProvider) itemProvider.errorToThrow = MockError.requestFailed - let expectedError = PointOfSaleErrorState(title: "Error loading products", + let expectedError = PointOfSaleErrorState(errorType: .productsLoadError, + title: "Error loading products", subtitle: "Give it another go?", buttonText: "Retry") try #require(sut.itemsViewState.containerState == .loading) From 009c6218da9c5f782626d1dbdfc03bc6e9c4e879 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 14:17:13 +0700 Subject: [PATCH 06/21] moves enable coupons call to coupons controller --- .../PointOfSaleCouponsController.swift | 23 +++++++++++++++++ .../PointOfSaleItemsController.swift | 9 ++++++- .../Models/PointOfSaleAggregateModel.swift | 8 ++++++ .../PointOfSaleDashboardView.swift | 25 +------------------ 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index 3dea3aab94e..34c48e1c3a6 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -1,6 +1,7 @@ import Observation import enum Yosemite.POSItem import enum Yosemite.PointOfSaleCouponServiceError +import enum Yosemite.SettingAction import protocol Yosemite.PointOfSaleItemServiceProtocol import protocol Yosemite.PointOfSaleCouponServiceProtocol @@ -70,3 +71,25 @@ private extension PointOfSaleCouponsController { } } } + +@available(iOS 17.0, *) +extension PointOfSaleCouponsController { + func enableCoupons() async { + guard let siteID = ServiceLocator.stores.sessionManager.defaultStoreID else { + return + } + _ = await withCheckedContinuation { continuation in + let action = SettingAction.enableCouponSetting(siteID: siteID) { result in + switch result { + case .success: + continuation.resume(returning: true) + case let .failure(error): + continuation.resume(returning: false) + } + } + Task { @MainActor in + ServiceLocator.stores.dispatch(action) + } + } + } +} diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift index faf58ef0013..2f5689000d4 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift @@ -21,9 +21,16 @@ protocol PointOfSaleItemsControllerProtocol { func refreshItems(base: ItemListBaseItem) async /// Loads the next page of items for a given base item. func loadNextItems(base: ItemListBaseItem) async + /// Enables coupons in store settings, if needed + func enableCoupons() async } - +@available(iOS 17.0, *) +extension PointOfSaleItemsControllerProtocol { + func enableCoupons() async { + // Default: no-op + } +} @available(iOS 17.0, *) @Observable final class PointOfSaleItemsController: PointOfSaleItemsControllerProtocol { diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift index 48828299b67..423d1e61ed8 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift @@ -161,6 +161,14 @@ extension PointOfSaleAggregateModel { } } +// MARK: - Coupons +@available(iOS 17.0, *) +extension PointOfSaleAggregateModel { + func enableCoupons() async { + await currentController.enableCoupons() + } +} + // MARK: - Track events @available(iOS 17.0, *) private extension PointOfSaleAggregateModel { diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 76a5bf94570..fdb6c0b493d 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -1,5 +1,4 @@ import SwiftUI -import enum Yosemite.SettingAction @available(iOS 17.0, *) struct PointOfSaleDashboardView: View { @@ -29,7 +28,7 @@ struct PointOfSaleDashboardView: View { PointOfSaleItemListFullscreenErrorView(error: error, onAction: { Task { if error.errorType == .couponsDisabled { - await enableCoupons() + await posModel.enableCoupons() } await posModel.loadItems(base: .root) } @@ -167,28 +166,6 @@ extension EnvironmentValues { } } -@available(iOS 17.0, *) -private extension PointOfSaleDashboardView { - func enableCoupons() async { - guard let siteID = ServiceLocator.stores.sessionManager.defaultStoreID else { - return - } - _ = await withCheckedContinuation { continuation in - let action = SettingAction.enableCouponSetting(siteID: siteID) { result in - switch result { - case .success: - continuation.resume(returning: true) - case let .failure(error): - continuation.resume(returning: false) - } - } - Task { @MainActor in - ServiceLocator.stores.dispatch(action) - } - } - } -} - @available(iOS 17.0, *) private extension PointOfSaleDashboardView { enum Constants { From a2283f21c669864cb6044477a2ea0c49ff8ced9b Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 14:24:32 +0700 Subject: [PATCH 07/21] move enable coupons to service --- .../PointOfSaleCouponsController.swift | 27 ++++--------------- .../PointOfSaleCouponService.swift | 15 +++++++++++ 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index 34c48e1c3a6..e119d1ea78e 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -40,6 +40,11 @@ import protocol Yosemite.PointOfSaleCouponServiceProtocol // Pagination https://github.com/woocommerce/woocommerce-ios/issues/15343 await loadFirstPage() } + + @MainActor + func enableCoupons() async { + await couponProvider.enableCoupons() + } } @available(iOS 17.0, *) @@ -71,25 +76,3 @@ private extension PointOfSaleCouponsController { } } } - -@available(iOS 17.0, *) -extension PointOfSaleCouponsController { - func enableCoupons() async { - guard let siteID = ServiceLocator.stores.sessionManager.defaultStoreID else { - return - } - _ = await withCheckedContinuation { continuation in - let action = SettingAction.enableCouponSetting(siteID: siteID) { result in - switch result { - case .success: - continuation.resume(returning: true) - case let .failure(error): - continuation.resume(returning: false) - } - } - Task { @MainActor in - ServiceLocator.stores.dispatch(action) - } - } - } -} diff --git a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift index 7e32f61daaf..2c39d022a7e 100644 --- a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift +++ b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift @@ -12,6 +12,7 @@ public enum PointOfSaleCouponServiceError: Error { public protocol PointOfSaleCouponServiceProtocol { func providePointOfSaleCoupons(pageNumber: Int) async throws -> PagedItems + func enableCoupons() async } public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol { @@ -68,6 +69,20 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol { return .init(items: refreshedCoupons, hasMorePages: false) } } + + @MainActor + public func enableCoupons() async { + _ = await withCheckedContinuation { continuation in + settingsStoreMethods.enableCouponSetting(siteID: siteID) { result in + switch result { + case .success(let success): + continuation.resume(returning: true) + case .failure(let failure): + continuation.resume(returning: false) + } + } + } + } } private extension PointOfSaleCouponService { From 0ffcc1072144a2a4cb451a165adbb9e6c6c6bea8 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 14:54:00 +0700 Subject: [PATCH 08/21] add follow-up issue reference --- .../Classes/POS/Controllers/PointOfSaleCouponsController.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index e119d1ea78e..9e82e9b30cf 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -43,6 +43,8 @@ import protocol Yosemite.PointOfSaleCouponServiceProtocol @MainActor func enableCoupons() async { + // TODO: WOOMOB-255 + // Handle loading state while coupons are being enabled, or error. await couponProvider.enableCoupons() } } From 1044f684e30766eb9c4ea1d00b6f3b348efd6084 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 14:55:14 +0700 Subject: [PATCH 09/21] remove unnecessary import --- .../Classes/POS/Controllers/PointOfSaleCouponsController.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index 9e82e9b30cf..9448faedc8c 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -1,7 +1,6 @@ import Observation import enum Yosemite.POSItem import enum Yosemite.PointOfSaleCouponServiceError -import enum Yosemite.SettingAction import protocol Yosemite.PointOfSaleItemServiceProtocol import protocol Yosemite.PointOfSaleCouponServiceProtocol From fac5a0715801707fc32f69fddf276200b8e48461 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 15:02:01 +0700 Subject: [PATCH 10/21] localizations --- .../POS/Models/PointOfSaleErrorState.swift | 42 ++++++++++++++++--- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift b/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift index edf185d4d1e..a6a4709c106 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleErrorState.swift @@ -59,20 +59,50 @@ struct PointOfSaleErrorState: Equatable { static func errorOnLoadingCoupons() -> Self { PointOfSaleErrorState( errorType: .couponsLoadError, - title: "Error loading coupons", - subtitle: "Error loading coupons", - buttonText: "Retry") + title: Constants.loadingCouponsErrorTitle, + subtitle: Constants.loadingCouponsErrorSubtitle, + buttonText: Constants.loadingCouponsErrorRetry) } static func errorCouponsDisabled() -> Self { PointOfSaleErrorState( errorType: .couponsDisabled, - title: "Error loading coupons", - subtitle: "Please enable the use of coupon codes in your store", - buttonText: "Enable") + title: Constants.loadingCouponsDisabledTitle, + subtitle: Constants.loadingCouponsDisabledSubtitle, + buttonText: Constants.loadingCouponsDisabledAction) } enum Constants { + static let loadingCouponsErrorTitle = NSLocalizedString( + "pos.itemList.loadingCouponsErrorTitle", + value: "Error loading coupons", + comment: "Title appearing on the coupon list screen when there's an error loading coupons." + ) + static let loadingCouponsErrorSubtitle = NSLocalizedString( + "pos.itemList.loadingCouponsErrorSubtitle", + value: "Error loading coupons", + comment: "Subtitle appearing on the coupon list screen when there's an error loading coupons." + ) + static let loadingCouponsErrorRetry = NSLocalizedString( + "pos.itemList.loadingCouponsErrorRetry", + value: "Retry", + comment: "Text of the button appearing on the coupon list screen when there's an error loading coupons." + ) + static let loadingCouponsDisabledTitle = NSLocalizedString( + "pos.itemList.loadingCouponsDisabledTitle", + value: "Error loading coupons", + comment: "Title appearing on the coupon list screen when coupons are disabled." + ) + static let loadingCouponsDisabledSubtitle = NSLocalizedString( + "pos.itemList.loadingCouponsDisabledSubtitle", + value: "Please enable the use of coupon codes in your store.", + comment: "Subtitle appearing on the coupon list screen when coupons are disabled." + ) + static let loadingCouponsDisabledAction = NSLocalizedString( + "pos.itemList.loadingCouponsDisabledAction", + value: "Enable", + comment: "Text of the button appearing on the coupon list screen when coupons are disabled." + ) static let noCouponsFoundTitle = NSLocalizedString( "pos.itemList.noCouponsFoundTitle", value: "No coupons found", From 85aef17d6501823ccfac9289c0ac7f27eee3512f Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Fri, 4 Apr 2025 15:17:22 +0700 Subject: [PATCH 11/21] make test compile --- .../POS/Controllers/PointOfSaleCouponsControllerTests.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift index bf66cbe81b2..cf8c8fffb3d 100644 --- a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift +++ b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift @@ -27,6 +27,10 @@ final class MockPointOfSaleCouponService: PointOfSaleCouponServiceProtocol { let coupon3 = POSItem.coupon(POSCoupon(id: UUID(uuidString: ("DC55E3B9-9D83-4C07-82A7-4C300A50E84C")) ?? UUID(), code: "VALID3")) return [coupon1, coupon2, coupon3] } + + func enableCoupons() async { + // no-op + } } struct PointOfSaleCouponsControllerTests { From 15b65684b1a9f21f43fa792134e86a93d2863610 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Mon, 7 Apr 2025 11:49:48 +0700 Subject: [PATCH 12/21] make compile. ammend merge conflict --- WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift index 796100bc3d8..e7ca7541c85 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift @@ -161,7 +161,7 @@ extension PointOfSaleAggregateModel { @available(iOS 17.0, *) extension PointOfSaleAggregateModel { func enableCoupons() async { - await currentController.enableCoupons() + await couponsController.enableCoupons() } } From 562c1c14a828e289d84a297e116061009e7f610d Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Mon, 7 Apr 2025 15:15:38 +0700 Subject: [PATCH 13/21] Add a shared current item view state based on item type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When view state changed, driven by changes in coupons, these were never propagated to the dashboard view since we only switched in “itemsViewState” which only covered the products controller. --- .../Models/PointOfSaleAggregateModel.swift | 20 +++++++++++++++++-- .../POS/Presentation/ItemListView.swift | 4 ++-- .../PointOfSaleDashboardView.swift | 6 +++--- .../Mocks/MockPointOfSaleAggregateModel.swift | 5 +++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift index e7ca7541c85..095a19a7d85 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift @@ -24,7 +24,8 @@ protocol PointOfSaleAggregateModelProtocol { func cancelCardPaymentsOnboarding() func trackCardPaymentsOnboardingShown() - var itemsViewState: ItemsViewState { get } + var productsViewState: ItemsViewState { get } + func loadItems(base: ItemListBaseItem) async func loadNextItems(base: ItemListBaseItem) async @@ -54,8 +55,9 @@ protocol PointOfSaleAggregateModelProtocol { var cardPresentPaymentOnboardingViewModel: CardPresentPaymentsOnboardingViewModel? private var onOnboardingCancellation: (() -> Void)? - var itemsViewState: ItemsViewState { itemsController.itemsViewState } + var productsViewState: ItemsViewState { itemsController.itemsViewState } var couponsViewState: ItemsViewState { couponsController.itemsViewState } + var currentViewState: ItemsViewState private(set) var cart: Cart = .init() @@ -89,6 +91,9 @@ protocol PointOfSaleAggregateModelProtocol { self.analytics = analytics self.collectOrderPaymentAnalyticsTracker = collectOrderPaymentAnalyticsTracker self.paymentState = paymentState + // Initial, set to items (products) + self.currentViewState = itemsController.itemsViewState + publishCardReaderConnectionStatus() publishPaymentMessages() setupReaderReconnectionObservation() @@ -98,22 +103,33 @@ protocol PointOfSaleAggregateModelProtocol { // MARK: - ItemList @available(iOS 17.0, *) extension PointOfSaleAggregateModel { + func updateCurrentViewState(base: ItemListBaseItem) { + let viewState = base.itemType == .products ? productsViewState : couponsViewState + currentViewState = viewState + } + @MainActor func loadItems(base: ItemListBaseItem) async { let controller = base.itemType == .products ? itemsController : couponsController + await controller.loadItems(base: base) + updateCurrentViewState(base: base) } @MainActor func refreshItems(base: ItemListBaseItem) async { let controller = base.itemType == .products ? itemsController : couponsController + await controller.refreshItems(base: base) + updateCurrentViewState(base: base) } @MainActor func loadNextItems(base: ItemListBaseItem) async { let controller = base.itemType == .products ? itemsController : couponsController + await controller.loadNextItems(base: base) + updateCurrentViewState(base: base) } } diff --git a/WooCommerce/Classes/POS/Presentation/ItemListView.swift b/WooCommerce/Classes/POS/Presentation/ItemListView.swift index d16123c4bc2..291c28bc6f9 100644 --- a/WooCommerce/Classes/POS/Presentation/ItemListView.swift +++ b/WooCommerce/Classes/POS/Presentation/ItemListView.swift @@ -16,7 +16,7 @@ struct ItemListView: View { private var itemsStack: ItemsStackState { switch selectedItemType { case .products: - return posModel.itemsViewState.itemsStack + return posModel.productsViewState.itemsStack case .coupons: return posModel.couponsViewState.itemsStack } @@ -181,7 +181,7 @@ private extension ItemListView { // Note that navigation is handled by the ItemList in iOS 17, so any changes to this should be reflected in ItemListRow. switch parentItem { case let .variableParentProduct(parentProduct): - let itemsStack = selectedItemType == .products ? posModel.itemsViewState.itemsStack : posModel.couponsViewState.itemsStack + let itemsStack = selectedItemType == .products ? posModel.productsViewState.itemsStack : posModel.couponsViewState.itemsStack ChildItemList(parentItem: parentItem, title: parentProduct.name, itemsStack: itemsStack) default: EmptyView() diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 94ae8ce89f0..7798ab98046 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -15,7 +15,7 @@ struct PointOfSaleDashboardView: View { @Bindable var posModel = posModel ZStack(alignment: .bottomLeading) { if case .regular = horizontalSizeClass { - switch posModel.itemsViewState.containerState { + switch posModel.currentViewState.containerState { case .loading: PointOfSaleLoadingView() .transition(.opacity) @@ -50,7 +50,7 @@ struct PointOfSaleDashboardView: View { .padding(.bottom, Constants.floatingControlBottomPadding) .trackSize(size: $floatingSize) .accessibilitySortPriority(1) - .renderedIf(posModel.itemsViewState.containerState != .loading) + .renderedIf(posModel.currentViewState.containerState != .loading) POSConnectivityView() } @@ -58,7 +58,7 @@ struct PointOfSaleDashboardView: View { CGSizeMake(floatingSize.width + Constants.floatingControlHorizontalOffset, floatingSize.height + Constants.floatingControlVerticalOffset)) .environment(\.posBackgroundAppearance, posModel.paymentState != .card(.processingPayment) ? .primary : .secondary) - .animation(.easeInOut, value: posModel.itemsViewState.containerState == .loading) + .animation(.easeInOut, value: posModel.currentViewState.containerState == .loading) .background(Color.posSurface) .navigationBarBackButtonHidden(true) .posModal(item: $posModel.cardPresentPaymentOnboardingViewModel, onDismiss: { diff --git a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift index 6a4c4729be1..98c0e7eec15 100644 --- a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift +++ b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift @@ -27,7 +27,8 @@ final class MockPointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol { var orderState: WooCommerce.PointOfSaleOrderState - var itemsViewState: ItemsViewState + var productsViewState: ItemsViewState + var blockReturnToItemSelection: Bool = false init(cardReaderConnectionStatus: CardPresentPaymentReaderConnectionStatus = .disconnected, @@ -37,7 +38,7 @@ final class MockPointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol { orderState: PointOfSaleOrderState = .idle, paymentState: PointOfSalePaymentState = .card(.idle)) { self.cardReaderConnectionStatus = cardReaderConnectionStatus - self.itemsViewState = itemsViewState + self.productsViewState = itemsViewState self.orderStage = orderStage self.orderState = orderState self.paymentState = paymentState From 093fc72560c2fc56deada201f7ab946fb2e3e522 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Mon, 7 Apr 2025 15:51:05 +0700 Subject: [PATCH 14/21] remove unnecessary associated values --- Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift index 2c39d022a7e..653f42370a5 100644 --- a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift +++ b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift @@ -75,9 +75,9 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol { _ = await withCheckedContinuation { continuation in settingsStoreMethods.enableCouponSetting(siteID: siteID) { result in switch result { - case .success(let success): + case .success: continuation.resume(returning: true) - case .failure(let failure): + case .failure: continuation.resume(returning: false) } } From fb126bc37fc221c755e838f16faf849f0a07b5a0 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Mon, 7 Apr 2025 15:55:18 +0700 Subject: [PATCH 15/21] update enableCoupons signature to be throwable --- .../POS/Controllers/PointOfSaleCouponsController.swift | 6 +++++- .../POS/Controllers/PointOfSaleCouponsControllerTests.swift | 2 +- .../Yosemite/PointOfSale/PointOfSaleCouponService.swift | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index 9448faedc8c..6555dd9e923 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -44,7 +44,11 @@ import protocol Yosemite.PointOfSaleCouponServiceProtocol func enableCoupons() async { // TODO: WOOMOB-255 // Handle loading state while coupons are being enabled, or error. - await couponProvider.enableCoupons() + do { + try await couponProvider.enableCoupons() + } catch { + debugPrint(error) + } } } diff --git a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift index 6cabc4330aa..f7d3ab972f4 100644 --- a/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift +++ b/WooCommerce/WooCommerceTests/POS/Controllers/PointOfSaleCouponsControllerTests.swift @@ -28,7 +28,7 @@ final class MockPointOfSaleCouponService: PointOfSaleCouponServiceProtocol { return [coupon1, coupon2, coupon3] } - func enableCoupons() async { + func enableCoupons() async throws { // no-op } } diff --git a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift index 653f42370a5..537806d202f 100644 --- a/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift +++ b/Yosemite/Yosemite/PointOfSale/PointOfSaleCouponService.swift @@ -12,7 +12,7 @@ public enum PointOfSaleCouponServiceError: Error { public protocol PointOfSaleCouponServiceProtocol { func providePointOfSaleCoupons(pageNumber: Int) async throws -> PagedItems - func enableCoupons() async + func enableCoupons() async throws } public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol { @@ -71,7 +71,7 @@ public final class PointOfSaleCouponService: PointOfSaleCouponServiceProtocol { } @MainActor - public func enableCoupons() async { + public func enableCoupons() async throws { _ = await withCheckedContinuation { continuation in settingsStoreMethods.enableCouponSetting(siteID: siteID) { result in switch result { From b24831002812463a15d4d8f9a1e8135d5bca1838 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 17:00:08 +0700 Subject: [PATCH 16/21] update issue references --- .../POS/Controllers/PointOfSaleCouponsController.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index 6555dd9e923..a0499870199 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -43,10 +43,12 @@ import protocol Yosemite.PointOfSaleCouponServiceProtocol @MainActor func enableCoupons() async { // TODO: WOOMOB-255 - // Handle loading state while coupons are being enabled, or error. + // Handle loading state while coupons are being enabled do { try await couponProvider.enableCoupons() } catch { + // TODO: WOOMOB-267 + // Handle error when failed to enable, and allow retry action debugPrint(error) } } From e1979c9eaa8f159780486885a34f7159288b2b90 Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 17:03:04 +0700 Subject: [PATCH 17/21] revert itemsViewState rename --- .../Classes/POS/Models/PointOfSaleAggregateModel.swift | 6 +++--- WooCommerce/Classes/POS/Presentation/ItemListView.swift | 4 ++-- .../POS/Mocks/MockPointOfSaleAggregateModel.swift | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift index 095a19a7d85..0e2f2bd28ad 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift @@ -24,7 +24,7 @@ protocol PointOfSaleAggregateModelProtocol { func cancelCardPaymentsOnboarding() func trackCardPaymentsOnboardingShown() - var productsViewState: ItemsViewState { get } + var itemsViewState: ItemsViewState { get } func loadItems(base: ItemListBaseItem) async func loadNextItems(base: ItemListBaseItem) async @@ -55,7 +55,7 @@ protocol PointOfSaleAggregateModelProtocol { var cardPresentPaymentOnboardingViewModel: CardPresentPaymentsOnboardingViewModel? private var onOnboardingCancellation: (() -> Void)? - var productsViewState: ItemsViewState { itemsController.itemsViewState } + var itemsViewState: ItemsViewState { itemsController.itemsViewState } var couponsViewState: ItemsViewState { couponsController.itemsViewState } var currentViewState: ItemsViewState @@ -104,7 +104,7 @@ protocol PointOfSaleAggregateModelProtocol { @available(iOS 17.0, *) extension PointOfSaleAggregateModel { func updateCurrentViewState(base: ItemListBaseItem) { - let viewState = base.itemType == .products ? productsViewState : couponsViewState + let viewState = base.itemType == .products ? itemsViewState : couponsViewState currentViewState = viewState } diff --git a/WooCommerce/Classes/POS/Presentation/ItemListView.swift b/WooCommerce/Classes/POS/Presentation/ItemListView.swift index 291c28bc6f9..d16123c4bc2 100644 --- a/WooCommerce/Classes/POS/Presentation/ItemListView.swift +++ b/WooCommerce/Classes/POS/Presentation/ItemListView.swift @@ -16,7 +16,7 @@ struct ItemListView: View { private var itemsStack: ItemsStackState { switch selectedItemType { case .products: - return posModel.productsViewState.itemsStack + return posModel.itemsViewState.itemsStack case .coupons: return posModel.couponsViewState.itemsStack } @@ -181,7 +181,7 @@ private extension ItemListView { // Note that navigation is handled by the ItemList in iOS 17, so any changes to this should be reflected in ItemListRow. switch parentItem { case let .variableParentProduct(parentProduct): - let itemsStack = selectedItemType == .products ? posModel.productsViewState.itemsStack : posModel.couponsViewState.itemsStack + let itemsStack = selectedItemType == .products ? posModel.itemsViewState.itemsStack : posModel.couponsViewState.itemsStack ChildItemList(parentItem: parentItem, title: parentProduct.name, itemsStack: itemsStack) default: EmptyView() diff --git a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift index 98c0e7eec15..7fccf331233 100644 --- a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift +++ b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleAggregateModel.swift @@ -27,7 +27,7 @@ final class MockPointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol { var orderState: WooCommerce.PointOfSaleOrderState - var productsViewState: ItemsViewState + var itemsViewState: ItemsViewState var blockReturnToItemSelection: Bool = false @@ -38,7 +38,7 @@ final class MockPointOfSaleAggregateModel: PointOfSaleAggregateModelProtocol { orderState: PointOfSaleOrderState = .idle, paymentState: PointOfSalePaymentState = .card(.idle)) { self.cardReaderConnectionStatus = cardReaderConnectionStatus - self.productsViewState = itemsViewState + self.itemsViewState = itemsViewState self.orderStage = orderStage self.orderState = orderState self.paymentState = paymentState From f7db770c54c9af7d714c0c62a026c553683f0fee Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 17:05:16 +0700 Subject: [PATCH 18/21] remove duplicated conformance --- .../Classes/POS/Controllers/PointOfSaleItemsController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift index 781c3742ed7..8bcfdf08ca5 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift @@ -43,7 +43,7 @@ protocol PointOfSaleSearchingItemsControllerProtocol: PointOfSaleItemsController @available(iOS 17.0, *) -@Observable final class PointOfSaleItemsController: PointOfSaleItemsControllerProtocol, PointOfSaleSearchingItemsControllerProtocol { +@Observable final class PointOfSaleItemsController: PointOfSaleSearchingItemsControllerProtocol { var itemsViewState: ItemsViewState = ItemsViewState(containerState: .loading, itemsStack: ItemsStackState(root: .loading([]), itemStates: [:])) From 0abe0bb008e1450d586cf225f6e46b55421ea8ef Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 17:27:45 +0700 Subject: [PATCH 19/21] make PointOfSaleCouponsControllerProtocol --- .../Controllers/PointOfSaleCouponsController.swift | 2 +- .../POS/Controllers/PointOfSaleItemsController.swift | 9 +++------ .../POS/Models/PointOfSaleAggregateModel.swift | 4 ++-- .../CardReaderConnectionStatusView.swift | 2 +- .../PointOfSalePaymentSuccessView.swift | 2 +- WooCommerce/Classes/POS/Presentation/CartView.swift | 4 ++-- .../Presentation/Item Selector/ChildItemList.swift | 4 ++-- .../POS/Presentation/Item Selector/ItemList.swift | 2 +- .../Classes/POS/Presentation/ItemListView.swift | 4 ++-- .../POS/Presentation/POSFloatingControlView.swift | 6 +++--- .../Classes/POS/Presentation/PaymentButtons.swift | 2 +- .../POS/Presentation/PointOfSaleCollectCashView.swift | 2 +- .../POS/Presentation/PointOfSaleDashboardView.swift | 4 ++-- .../POS/Presentation/PointOfSaleEntryPointView.swift | 6 +++--- .../Reusable Views/POSSendReceiptView.swift | 2 +- WooCommerce/Classes/POS/Presentation/TotalsView.swift | 2 +- WooCommerce/Classes/POS/Utils/PreviewHelpers.swift | 11 +++++++++++ 17 files changed, 38 insertions(+), 30 deletions(-) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift index a0499870199..4d1b5c96cbe 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleCouponsController.swift @@ -5,7 +5,7 @@ import protocol Yosemite.PointOfSaleItemServiceProtocol import protocol Yosemite.PointOfSaleCouponServiceProtocol @available(iOS 17.0, *) -@Observable final class PointOfSaleCouponsController: PointOfSaleItemsControllerProtocol { +@Observable final class PointOfSaleCouponsController: PointOfSaleCouponsControllerProtocol { var itemsViewState: ItemsViewState = ItemsViewState(containerState: .loading, itemsStack: ItemsStackState(root: .loading([]), itemStates: [:])) diff --git a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift index 8bcfdf08ca5..e64dc0052fe 100644 --- a/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift +++ b/WooCommerce/Classes/POS/Controllers/PointOfSaleItemsController.swift @@ -24,15 +24,12 @@ protocol PointOfSaleItemsControllerProtocol { func refreshItems(base: ItemListBaseItem) async /// Loads the next page of items for a given base item. func loadNextItems(base: ItemListBaseItem) async - /// Enables coupons in store settings, if needed - func enableCoupons() async } @available(iOS 17.0, *) -extension PointOfSaleItemsControllerProtocol { - func enableCoupons() async { - // Default: no-op - } +protocol PointOfSaleCouponsControllerProtocol: PointOfSaleItemsControllerProtocol { + /// Enables coupons in store settings, if needed + func enableCoupons() async } @available(iOS 17.0, *) diff --git a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift index 0e2f2bd28ad..6ef9b1ba0cf 100644 --- a/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift +++ b/WooCommerce/Classes/POS/Models/PointOfSaleAggregateModel.swift @@ -65,7 +65,7 @@ protocol PointOfSaleAggregateModelProtocol { private var internalOrderState: PointOfSaleInternalOrderState { orderController.orderState } private let itemsController: PointOfSaleItemsControllerProtocol - private let couponsController: PointOfSaleItemsControllerProtocol + private let couponsController: PointOfSaleCouponsControllerProtocol private let cardPresentPaymentService: CardPresentPaymentFacade private let orderController: PointOfSaleOrderControllerProtocol @@ -78,7 +78,7 @@ protocol PointOfSaleAggregateModelProtocol { private var cancellables: Set = [] init(itemsController: PointOfSaleItemsControllerProtocol, - couponsController: PointOfSaleItemsControllerProtocol, + couponsController: PointOfSaleCouponsControllerProtocol, cardPresentPaymentService: CardPresentPaymentFacade, orderController: PointOfSaleOrderControllerProtocol, analytics: Analytics = ServiceLocator.analytics, diff --git a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/CardReaderConnectionStatusView.swift b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/CardReaderConnectionStatusView.swift index 3995afdc807..c77e4aba577 100644 --- a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/CardReaderConnectionStatusView.swift +++ b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/CardReaderConnectionStatusView.swift @@ -171,7 +171,7 @@ private extension CardReaderConnectionStatusView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics() diff --git a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSalePaymentSuccessView.swift b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSalePaymentSuccessView.swift index 4badbe5dd11..ee4220e2e85 100644 --- a/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSalePaymentSuccessView.swift +++ b/WooCommerce/Classes/POS/Presentation/CardReaderConnection/UI States/Reader Messages/PointOfSalePaymentSuccessView.swift @@ -125,7 +125,7 @@ private extension PointOfSalePaymentSuccessView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/CartView.swift b/WooCommerce/Classes/POS/Presentation/CartView.swift index 4e5d604993c..9b4060b412f 100644 --- a/WooCommerce/Classes/POS/Presentation/CartView.swift +++ b/WooCommerce/Classes/POS/Presentation/CartView.swift @@ -351,7 +351,7 @@ private extension CartView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -363,7 +363,7 @@ private extension CartView { #Preview("Cart with one item") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift b/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift index b6211a8ec5a..f8412350f78 100644 --- a/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift +++ b/WooCommerce/Classes/POS/Presentation/Item Selector/ChildItemList.swift @@ -152,7 +152,7 @@ private extension ChildItemList { ], hasMoreItems: false)]) let posModel = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -177,7 +177,7 @@ private extension ChildItemList { ]) let posModel = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/Item Selector/ItemList.swift b/WooCommerce/Classes/POS/Presentation/Item Selector/ItemList.swift index be989a78642..0ab7f2d53e9 100644 --- a/WooCommerce/Classes/POS/Presentation/Item Selector/ItemList.swift +++ b/WooCommerce/Classes/POS/Presentation/Item Selector/ItemList.swift @@ -207,7 +207,7 @@ private extension ItemListRow { #Preview("Loading") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/ItemListView.swift b/WooCommerce/Classes/POS/Presentation/ItemListView.swift index d16123c4bc2..f0a5ea6b3f6 100644 --- a/WooCommerce/Classes/POS/Presentation/ItemListView.swift +++ b/WooCommerce/Classes/POS/Presentation/ItemListView.swift @@ -285,7 +285,7 @@ private extension ItemListView { } let posModel = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -297,7 +297,7 @@ private extension ItemListView { #Preview("Loading") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift b/WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift index aee962956d1..009eee10c52 100644 --- a/WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift +++ b/WooCommerce/Classes/POS/Presentation/POSFloatingControlView.swift @@ -139,7 +139,7 @@ private extension POSFloatingControlView { #Preview("Reader Disconnected") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -153,7 +153,7 @@ private extension POSFloatingControlView { let paymentService = CardPresentPaymentPreviewService() let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -167,7 +167,7 @@ private extension POSFloatingControlView { #Preview("Secondary/disabled Background") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/PaymentButtons.swift b/WooCommerce/Classes/POS/Presentation/PaymentButtons.swift index dd454101a62..4e6fabc7fa4 100644 --- a/WooCommerce/Classes/POS/Presentation/PaymentButtons.swift +++ b/WooCommerce/Classes/POS/Presentation/PaymentButtons.swift @@ -90,7 +90,7 @@ private extension PaymentsActionButtons { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift index d674bc9875c..6d6293bbc53 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleCollectCashView.swift @@ -199,7 +199,7 @@ private extension PointOfSaleCollectCashView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift index 7798ab98046..e0bf21fea39 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleDashboardView.swift @@ -194,7 +194,7 @@ private extension PointOfSaleDashboardView { #Preview("Container loading state") { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) @@ -210,7 +210,7 @@ private extension PointOfSaleDashboardView { let itemsController = PointOfSalePreviewItemsController() let posModel = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/PointOfSaleEntryPointView.swift b/WooCommerce/Classes/POS/Presentation/PointOfSaleEntryPointView.swift index d7365c2677a..f56ba7cf65b 100644 --- a/WooCommerce/Classes/POS/Presentation/PointOfSaleEntryPointView.swift +++ b/WooCommerce/Classes/POS/Presentation/PointOfSaleEntryPointView.swift @@ -8,13 +8,13 @@ struct PointOfSaleEntryPointView: View { private let onPointOfSaleModeActiveStateChange: ((Bool) -> Void) private let itemsController: PointOfSaleItemsControllerProtocol - private let couponsController: PointOfSaleItemsControllerProtocol + private let couponsController: PointOfSaleCouponsControllerProtocol private let cardPresentPaymentService: CardPresentPaymentFacade private let orderController: PointOfSaleOrderControllerProtocol private let collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalyticsTracking init(itemsController: PointOfSaleItemsControllerProtocol, - couponsController: PointOfSaleItemsControllerProtocol, + couponsController: PointOfSaleCouponsControllerProtocol, onPointOfSaleModeActiveStateChange: @escaping ((Bool) -> Void), cardPresentPaymentService: CardPresentPaymentFacade, orderController: PointOfSaleOrderControllerProtocol, @@ -64,7 +64,7 @@ struct PointOfSaleEntryPointView: View { @available(iOS 17.0, *) #Preview { PointOfSaleEntryPointView(itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), onPointOfSaleModeActiveStateChange: { _ in }, cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), diff --git a/WooCommerce/Classes/POS/Presentation/Reusable Views/POSSendReceiptView.swift b/WooCommerce/Classes/POS/Presentation/Reusable Views/POSSendReceiptView.swift index 899d7c43cce..f3f926adced 100644 --- a/WooCommerce/Classes/POS/Presentation/Reusable Views/POSSendReceiptView.swift +++ b/WooCommerce/Classes/POS/Presentation/Reusable Views/POSSendReceiptView.swift @@ -160,7 +160,7 @@ private extension POSSendReceiptView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Presentation/TotalsView.swift b/WooCommerce/Classes/POS/Presentation/TotalsView.swift index 136493f2fc7..0d8515d8e70 100644 --- a/WooCommerce/Classes/POS/Presentation/TotalsView.swift +++ b/WooCommerce/Classes/POS/Presentation/TotalsView.swift @@ -457,7 +457,7 @@ private extension TotalsView { #Preview { let posModel = PointOfSaleAggregateModel( itemsController: PointOfSalePreviewItemsController(), - couponsController: PointOfSalePreviewItemsController(), + couponsController: PointOfSalePreviewCouponsController(), cardPresentPaymentService: CardPresentPaymentPreviewService(), orderController: PointOfSalePreviewOrderController(), collectOrderPaymentAnalyticsTracker: POSCollectOrderPaymentAnalytics()) diff --git a/WooCommerce/Classes/POS/Utils/PreviewHelpers.swift b/WooCommerce/Classes/POS/Utils/PreviewHelpers.swift index 632229ab5bb..142b6e7d337 100644 --- a/WooCommerce/Classes/POS/Utils/PreviewHelpers.swift +++ b/WooCommerce/Classes/POS/Utils/PreviewHelpers.swift @@ -76,6 +76,17 @@ struct PointOfSalePreviewPurchasableItemFetchStrategy: PointOfSalePurchasableIte } } +@available(iOS 17.0, *) +final class PointOfSalePreviewCouponsController: PointOfSaleCouponsControllerProtocol { + @Published var itemsViewState: ItemsViewState = ItemsViewState(containerState: .loading, + itemsStack: ItemsStackState(root: .loading([]), + itemStates: [:])) + func enableCoupons() async { } + func loadItems(base: ItemListBaseItem) async { } + func refreshItems(base: ItemListBaseItem) async { } + func loadNextItems(base: ItemListBaseItem) async { } +} + @available(iOS 17.0, *) final class PointOfSalePreviewItemsController: PointOfSaleItemsControllerProtocol { @Published var itemsViewState: ItemsViewState = ItemsViewState(containerState: .loading, From 342f88720e85767cd96af6c0f85397b4db6ac8fd Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 18:25:13 +0700 Subject: [PATCH 20/21] update tests with new mock --- .../WooCommerce.xcodeproj/project.pbxproj | 4 + .../MockPointOfSaleCouponsController.swift | 16 ++++ .../PointOfSaleAggregateModelTests.swift | 82 +++++++++---------- 3 files changed, 61 insertions(+), 41 deletions(-) create mode 100644 WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift diff --git a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj index edb68b001fe..b115c408cab 100644 --- a/WooCommerce/WooCommerce.xcodeproj/project.pbxproj +++ b/WooCommerce/WooCommerce.xcodeproj/project.pbxproj @@ -1583,6 +1583,7 @@ 683DF5FF2C6AF46500A5CDC6 /* POSHeaderTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 683DF5FE2C6AF46500A5CDC6 /* POSHeaderTitleView.swift */; }; 684AB83A2870677F003DFDD1 /* CardReaderManualsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 684AB8392870677F003DFDD1 /* CardReaderManualsView.swift */; }; 684AB83C2873DF04003DFDD1 /* CardReaderManualsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 684AB83B2873DF04003DFDD1 /* CardReaderManualsViewModel.swift */; }; + 68503C362DA53E0A00C07909 /* MockPointOfSaleCouponsController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 68503C352DA53E0800C07909 /* MockPointOfSaleCouponsController.swift */; }; 6850C5EE2B69E6580026A93B /* ReceiptViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6850C5ED2B69E6580026A93B /* ReceiptViewModel.swift */; }; 6850C5F12B69E74D0026A93B /* ReceiptViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6850C5F02B69E74D0026A93B /* ReceiptViewController.swift */; }; 6850C5F42B6A11CA0026A93B /* ReceiptViewModelTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6850C5F32B6A11CA0026A93B /* ReceiptViewModelTests.swift */; }; @@ -4770,6 +4771,7 @@ 683DF5FE2C6AF46500A5CDC6 /* POSHeaderTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = POSHeaderTitleView.swift; sourceTree = ""; }; 684AB8392870677F003DFDD1 /* CardReaderManualsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardReaderManualsView.swift; sourceTree = ""; }; 684AB83B2873DF04003DFDD1 /* CardReaderManualsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CardReaderManualsViewModel.swift; sourceTree = ""; }; + 68503C352DA53E0800C07909 /* MockPointOfSaleCouponsController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MockPointOfSaleCouponsController.swift; sourceTree = ""; }; 6850C5ED2B69E6580026A93B /* ReceiptViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewModel.swift; sourceTree = ""; }; 6850C5F02B69E74D0026A93B /* ReceiptViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewController.swift; sourceTree = ""; }; 6850C5F32B6A11CA0026A93B /* ReceiptViewModelTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReceiptViewModelTests.swift; sourceTree = ""; }; @@ -7800,6 +7802,7 @@ 02CD3BFC2C35D01600E575C4 /* Mocks */ = { isa = PBXGroup; children = ( + 68503C352DA53E0800C07909 /* MockPointOfSaleCouponsController.swift */, 02CD3BFD2C35D04C00E575C4 /* MockCardPresentPaymentService.swift */, 6801E4162D0FFF0100F9DF46 /* MockReceiptService.swift */, 207E71CA2C60F765008540FC /* MockPOSOrderService.swift */, @@ -17718,6 +17721,7 @@ CE29FEF62C009F5F007679C2 /* ShippingLineRowViewModelTests.swift in Sources */, 20CCBF212B0E15C0003102E6 /* WooPaymentsPayoutsCurrencyOverviewViewModelTests.swift in Sources */, 2602A64227BD89CE00B347F1 /* NewOrderInitialStatusResolverTests.swift in Sources */, + 68503C362DA53E0A00C07909 /* MockPointOfSaleCouponsController.swift in Sources */, DE6D84A52C3B8C9C0014FBFF /* GoogleAdsDashboardCardViewModelTests.swift in Sources */, 0235354E2999D17A00BF77D3 /* DomainSettingsViewModelTests.swift in Sources */, 4535EE80281BE4E0004212B4 /* CouponAmountInputFormatterTests.swift in Sources */, diff --git a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift new file mode 100644 index 00000000000..53faf38d068 --- /dev/null +++ b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift @@ -0,0 +1,16 @@ +@testable import WooCommerce + +@available(iOS 17.0, *) +final class MockPointOfSaleCouponsController: PointOfSaleCouponsControllerProtocol { + func enableCoupons() async { } + + var itemsViewState: ItemsViewState = .init(containerState: .empty, + itemsStack: .init(root: .loaded([], hasMoreItems: false), + itemStates: [:])) + + func loadItems(base: ItemListBaseItem) async { } + + func refreshItems(base: ItemListBaseItem) async { } + + func loadNextItems(base: ItemListBaseItem) async { } +} diff --git a/WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift b/WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift index a3eb5a1142d..9196ec51682 100644 --- a/WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift +++ b/WooCommerce/WooCommerceTests/POS/Models/PointOfSaleAggregateModelTests.swift @@ -13,7 +13,7 @@ struct PointOfSaleAggregateModelTests { @Test func inits_with_building_order_stage() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -26,7 +26,7 @@ struct PointOfSaleAggregateModelTests { @Test func startNewCart_removes_all_items_from_cart_and_moves_back_to_building() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -48,7 +48,7 @@ struct PointOfSaleAggregateModelTests { @Test func checkOut_moves_to_finalizing_order_stage() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -66,7 +66,7 @@ struct PointOfSaleAggregateModelTests { @Test func addMoreToCart_moves_to_building_order_stage() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -97,7 +97,7 @@ struct PointOfSaleAggregateModelTests { @Test func addItem_results_in_a_non_empty_cart() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -116,7 +116,7 @@ struct PointOfSaleAggregateModelTests { @Test func addItem_puts_new_items_first_in_the_cart() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -134,7 +134,7 @@ struct PointOfSaleAggregateModelTests { @Test func removeItem_after_adding_two_items_removes_item_correctly() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -159,7 +159,7 @@ struct PointOfSaleAggregateModelTests { @Test func removeAllItemsFromCart_removes_everything() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -188,7 +188,7 @@ struct PointOfSaleAggregateModelTests { func addToCart_tracks_analytics_event() async throws { // Given let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -218,7 +218,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -239,7 +239,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -263,7 +263,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -286,7 +286,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -309,7 +309,7 @@ struct PointOfSaleAggregateModelTests { // Given let orderController = MockPointOfSaleOrderController() let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -330,7 +330,7 @@ struct PointOfSaleAggregateModelTests { let expectedError = NSError(domain: "some error", code: -1) let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -353,7 +353,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -381,7 +381,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -397,7 +397,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, collectOrderPaymentAnalyticsTracker: MockPOSCollectOrderPaymentAnalyticsTracker(), @@ -416,7 +416,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -438,7 +438,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, collectOrderPaymentAnalyticsTracker: MockPOSCollectOrderPaymentAnalyticsTracker(), @@ -457,7 +457,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -482,7 +482,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -502,7 +502,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -521,7 +521,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -542,7 +542,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -573,7 +573,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -596,7 +596,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -625,7 +625,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -657,7 +657,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -688,7 +688,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -709,7 +709,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -730,7 +730,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -762,7 +762,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -789,7 +789,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: WooAnalytics(analyticsProvider: MockAnalyticsProvider()), @@ -826,7 +826,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: analytics, @@ -856,7 +856,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: analytics, @@ -877,7 +877,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: analytics, @@ -896,7 +896,7 @@ struct PointOfSaleAggregateModelTests { let itemsController = MockPointOfSaleItemsController() let sut = PointOfSaleAggregateModel( itemsController: itemsController, - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, analytics: analytics, @@ -914,7 +914,7 @@ struct PointOfSaleAggregateModelTests { // Given let analyticsTracker = MockPOSCollectOrderPaymentAnalyticsTracker() let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: cardPresentPaymentService, orderController: orderController, collectOrderPaymentAnalyticsTracker: analyticsTracker) @@ -931,7 +931,7 @@ struct PointOfSaleAggregateModelTests { // Given let analyticsTracker = MockPOSCollectOrderPaymentAnalyticsTracker() let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: analytics, @@ -949,7 +949,7 @@ struct PointOfSaleAggregateModelTests { let mockAnalyticsProvider = MockAnalyticsProvider() let mockAnalytics = WooAnalytics(analyticsProvider: mockAnalyticsProvider) let sut = PointOfSaleAggregateModel(itemsController: MockPointOfSaleItemsController(), - couponsController: MockPointOfSaleItemsController(), + couponsController: MockPointOfSaleCouponsController(), cardPresentPaymentService: MockCardPresentPaymentService(), orderController: MockPointOfSaleOrderController(), analytics: mockAnalytics, From b85c7bcb0bfc5be382ddc06a1009fd49069eb0fc Mon Sep 17 00:00:00 2001 From: iamgabrielma Date: Tue, 8 Apr 2025 18:32:42 +0700 Subject: [PATCH 21/21] lint --- .../POS/Mocks/MockPointOfSaleCouponsController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift index 53faf38d068..60d43a66977 100644 --- a/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift +++ b/WooCommerce/WooCommerceTests/POS/Mocks/MockPointOfSaleCouponsController.swift @@ -3,7 +3,7 @@ @available(iOS 17.0, *) final class MockPointOfSaleCouponsController: PointOfSaleCouponsControllerProtocol { func enableCoupons() async { } - + var itemsViewState: ItemsViewState = .init(containerState: .empty, itemsStack: .init(root: .loaded([], hasMoreItems: false), itemStates: [:]))