From 8a98906f8d49b073cc6924842ec04e97f9d55690 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Fri, 6 Jan 2023 16:13:02 -0500 Subject: [PATCH 1/2] Present notice when the variation process finishes --- .../ProductVariationsViewController.swift | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift b/WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift index 92cfad4371f..5cfbb3576f2 100644 --- a/WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift +++ b/WooCommerce/Classes/ViewRelated/Products/Variations/ProductVariationsViewController.swift @@ -674,6 +674,20 @@ private extension ProductVariationsViewController { inProgressViewController.dismiss(animated: true) } } + + /// Informs the merchant that no variations were created. + /// + private func presentNoGenerationNotice() { + let notice = Notice(title: Localization.noVariationsCreatedTitle, message: Localization.noVariationsCreatedDescription) + noticePresenter.enqueue(notice: notice) + } + + /// Informs the merchant that some variations were created. + /// + private func presentVariationsCreatedNotice() { + let notice = Notice(title: Localization.variationsCreatedTitle) + noticePresenter.enqueue(notice: notice) + } } // MARK: - Placeholders @@ -762,7 +776,11 @@ extension ProductVariationsViewController: SyncingCoordinatorDelegate { self?.dismissBlockingIndicator() case .finished(let variationsCreated): self?.dismissBlockingIndicator() - // TODO: Inform about created variations + if variationsCreated { + self?.presentVariationsCreatedNotice() + } else { + self?.presentNoGenerationNotice() + } break case .error(let error): self?.dismissBlockingIndicator() @@ -889,6 +907,12 @@ private extension ProductVariationsViewController { comment: "Blocking indicator text when fetching existing variations prior generating them.") static let creatingVariations = NSLocalizedString("Creating Variations...", comment: "Blocking indicator text when creating multiple variations remotely.") + static let noVariationsCreatedTitle = NSLocalizedString("No variations to generate", + comment: "Title for the notice when there were no variations to generate") + static let noVariationsCreatedDescription = NSLocalizedString("All variations are already generated.", + comment: "Message for the notice when there were no variations to generate") + static let variationsCreatedTitle = NSLocalizedString("Variations created successfully", + comment: "Title for the notice when after variations were created") } From bbe076c60d0b3e8ba69ba2f1e903f15a0377ed7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Fri, 6 Jan 2023 16:38:06 -0500 Subject: [PATCH 2/2] Update unit tests --- .../ProductVariationsViewModelTests.swift | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/WooCommerce/WooCommerceTests/ViewRelated/Products/Variations/ProductVariationsViewModelTests.swift b/WooCommerce/WooCommerceTests/ViewRelated/Products/Variations/ProductVariationsViewModelTests.swift index 282cdb01baa..cd556dd6822 100644 --- a/WooCommerce/WooCommerceTests/ViewRelated/Products/Variations/ProductVariationsViewModelTests.swift +++ b/WooCommerce/WooCommerceTests/ViewRelated/Products/Variations/ProductVariationsViewModelTests.swift @@ -185,6 +185,37 @@ final class ProductVariationsViewModelTests: XCTestCase { XCTAssertTrue(succeeded) } + func test_generating_no_variations_sends_completed_state() { + // Given + let product = Product.fake().copy(attributes: [ProductAttribute.fake().copy(attributeID: 1, name: "Size", options: ["XS"])]) + let stores = MockStoresManager(sessionManager: SessionManager.makeForTesting()) + stores.whenReceivingAction(ofType: ProductVariationAction.self) { action in + switch action { + case .synchronizeAllProductVariations(_, _, let onCompletion): + let variation = ProductVariation.fake().copy(attributes: [.init(id: 1, name: "Size", option: "XS")]) + onCompletion(.success([variation])) + case .createProductVariations(_, _, _, let onCompletion): + onCompletion(.success([])) + default: + break + } + } + + let viewModel = ProductVariationsViewModel(stores: stores, formType: .edit) + + // When + let variationsGenerated = waitFor { promise in + viewModel.generateAllVariations(for: product) { state in + if case .finished(let variationsGenerated) = state { + promise(variationsGenerated) + } + } + } + + // Then + XCTAssertFalse(variationsGenerated) + } + func test_generating_less_than_100_variations_ask_for_confirmation_and_sends_cancel_state() { // Given let product = Product.fake().copy(attributes: [