Skip to content

Commit 0b5e1c1

Browse files
author
Sharma Elanthiriayan
committed
Settings - Install Jetpack row tests
- Test `installJetpack` row's presence in `SettingsViewModelTests` by mocking the `jetpackConnectionPackageSupport` feature flag.
1 parent ed1563b commit 0b5e1c1

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

WooCommerce/WooCommerceTests/Mocks/MockFeatureFlagService.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,22 @@ struct MockFeatureFlagService: FeatureFlagService {
88
private let isShippingLabelsPackageCreationOn: Bool
99
private let isShippingLabelsMultiPackageOn: Bool
1010
private let isPushNotificationsForAllStoresOn: Bool
11+
private let isJetpackConnectionPackageSupportOn: Bool
1112

1213
init(isShippingLabelsM2M3On: Bool = false,
1314
isInternationalShippingLabelsOn: Bool = false,
1415
isShippingLabelsPaymentMethodCreationOn: Bool = false,
1516
isShippingLabelsPackageCreationOn: Bool = false,
1617
isShippingLabelsMultiPackageOn: Bool = false,
17-
isPushNotificationsForAllStoresOn: Bool = false) {
18+
isPushNotificationsForAllStoresOn: Bool = false,
19+
isJetpackConnectionPackageSupportOn: Bool = false) {
1820
self.isShippingLabelsM2M3On = isShippingLabelsM2M3On
1921
self.isInternationalShippingLabelsOn = isInternationalShippingLabelsOn
2022
self.isShippingLabelsPaymentMethodCreationOn = isShippingLabelsPaymentMethodCreationOn
2123
self.isShippingLabelsPackageCreationOn = isShippingLabelsPackageCreationOn
2224
self.isShippingLabelsMultiPackageOn = isShippingLabelsMultiPackageOn
2325
self.isPushNotificationsForAllStoresOn = isPushNotificationsForAllStoresOn
26+
self.isJetpackConnectionPackageSupportOn = isJetpackConnectionPackageSupportOn
2427
}
2528

2629
func isFeatureFlagEnabled(_ featureFlag: FeatureFlag) -> Bool {
@@ -37,6 +40,8 @@ struct MockFeatureFlagService: FeatureFlagService {
3740
return isShippingLabelsMultiPackageOn
3841
case .pushNotificationsForAllStores:
3942
return isPushNotificationsForAllStoresOn
43+
case .jetpackConnectionPackageSupport:
44+
return isJetpackConnectionPackageSupportOn
4045
default:
4146
return false
4247
}

WooCommerce/WooCommerceTests/ViewRelated/Settings/SettingsViewModelTests.swift

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ final class SettingsViewModelTests: XCTestCase {
3838
XCTAssertTrue(viewModel.sections.count > 0)
3939
}
4040

41+
func test_sections_contain_install_jetpack_row_when_JCP_support_feature_flag_is_on() {
42+
// Given
43+
let featureFlagService = MockFeatureFlagService(isJetpackConnectionPackageSupportOn: true)
44+
let viewModel = SettingsViewModel(
45+
stores: stores,
46+
storageManager: storageManager,
47+
featureFlagService: featureFlagService)
48+
49+
// When
50+
viewModel.onViewDidLoad()
51+
52+
// Then
53+
XCTAssertTrue(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.installJetpack) })
54+
}
55+
56+
func test_sections_does_not_contain_install_jetpack_row_when_JCP_support_feature_flag_is_off() {
57+
// Given
58+
let featureFlagService = MockFeatureFlagService(isJetpackConnectionPackageSupportOn: false)
59+
let viewModel = SettingsViewModel(
60+
stores: stores,
61+
storageManager: storageManager,
62+
featureFlagService: featureFlagService)
63+
64+
// When
65+
viewModel.onViewDidLoad()
66+
67+
// Then
68+
XCTAssertFalse(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.installJetpack) })
69+
}
70+
4171
func test_refresh_view_content_method_is_invoked_after_view_did_load() {
4272
// Given
4373
let viewModel = SettingsViewModel(stores: stores, storageManager: storageManager)

0 commit comments

Comments
 (0)