Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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")

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down