Skip to content

Commit 9289da7

Browse files
committed
Try fixing test failures by DI'ing the value for UIImagePickerController.isSourceTypeAvailable(.camera).
1 parent bb38ed9 commit 9289da7

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

WooCommerce/Classes/ViewRelated/Products/ProductsListViewModel.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Yosemite
44
import Experiments
55

66
protocol ProductsListViewModelProtocol {
7-
func scanToUpdateInventoryButtonShouldBeVisible(completion: @escaping (Bool) -> (Void))
7+
func scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: Bool, completion: @escaping (Bool) -> (Void))
88
}
99

1010
/// View model for `ProductsViewController`. Has stores logic related to Bulk Editing and Woo Subscriptions.
@@ -201,14 +201,14 @@ final class ProductListViewModel: ProductsListViewModelProtocol {
201201
// The feature breaks if the Square plugin is active, since modifies inventory management logic
202202
// If the plugin is active, we'll hide the inventory scanner button
203203
// More details: https://wp.me/pdfdoF-2Nq
204-
func scanToUpdateInventoryButtonShouldBeVisible(completion: @escaping (Bool) -> (Void)) {
204+
func scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: Bool = UIImagePickerController.isSourceTypeAvailable(.camera),
205+
completion: @escaping (Bool) -> (Void)) {
205206
let isPluginActive = isPluginActive(.wooSquare)
206207
switch isPluginActive {
207208
case true:
208209
completion(false)
209210
case false:
210-
guard featureFlagService.isFeatureFlagEnabled(.scanToUpdateInventory),
211-
UIImagePickerController.isSourceTypeAvailable(.camera) else {
211+
guard featureFlagService.isFeatureFlagEnabled(.scanToUpdateInventory), isCameraAvailable else {
212212
return completion(false)
213213
}
214214
// If all conditions are met, scan to update inventory should be visible:

WooCommerce/WooCommerceTests/Mocks/MockProductListViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ final class MockProductListViewModel: ProductsListViewModelProtocol {
1111
self.featureFlagService = featureFlagService
1212
}
1313

14-
func scanToUpdateInventoryButtonShouldBeVisible(completion: @escaping (Bool) -> (Void)) {
14+
func scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: Bool = true, completion: @escaping (Bool) -> (Void)) {
1515
guard self.featureFlagService.isFeatureFlagEnabled(.scanToUpdateInventory) else {
1616
scanToUpdateInventoryShouldBeVisible = false
1717
return completion(false)

WooCommerce/WooCommerceTests/ViewRelated/Products/ProductListViewModelTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ final class ProductListViewModelTests: XCTestCase {
360360

361361
// When
362362
let result = waitFor { promise in
363-
viewModel.scanToUpdateInventoryButtonShouldBeVisible { result in
363+
viewModel.scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: true) { result in
364364
promise(result)
365365
}
366366
}
@@ -388,7 +388,7 @@ final class ProductListViewModelTests: XCTestCase {
388388

389389
// When
390390
let result = waitFor { promise in
391-
viewModel.scanToUpdateInventoryButtonShouldBeVisible { result in
391+
viewModel.scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: true) { result in
392392
promise(result)
393393
}
394394
}
@@ -412,7 +412,7 @@ final class ProductListViewModelTests: XCTestCase {
412412

413413
// When
414414
let result = waitFor { promise in
415-
viewModel.scanToUpdateInventoryButtonShouldBeVisible { result in
415+
viewModel.scanToUpdateInventoryButtonShouldBeVisible(isCameraAvailable: true) { result in
416416
promise(result)
417417
}
418418
}

0 commit comments

Comments
 (0)