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") } 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: [