Skip to content

Commit 4ce27da

Browse files
authored
HACK Week: Add entry point to connectivity tool from Settings (#15391)
2 parents 1a88dd9 + 4db33a6 commit 4ce27da

File tree

7 files changed

+80
-2
lines changed

7 files changed

+80
-2
lines changed

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- [*] Product Form: Fix crash related to picking photos [https://github.com/woocommerce/woocommerce-ios/pull/15275]
88
- [internal] Assign `siteID` and `productID` to image product upload statuses. [https://github.com/woocommerce/woocommerce-ios/pull/15196]
99
- [*] Payments: Improved payment views' adaptability to larger accessibility font sizes [https://github.com/woocommerce/woocommerce-ios/pull/15328].
10+
- [*] Added an entry point to Troubleshoot Connection from the Settings screen. [https://github.com/woocommerce/woocommerce-ios/pull/15391]
1011
- [**] Filters in Orders and Products lists are now persisted. [https://github.com/woocommerce/woocommerce-ios/issues/14791]
1112
- [internal] Add site related properties to crowdsignal surveys. [https://github.com/woocommerce/woocommerce-ios/pull/15353]
1213

WooCommerce/Classes/Analytics/WooAnalyticsEvent+ConnectivityTool.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ extension WooAnalyticsEvent {
2020
.init(statName: .ordersListTopBannerTroubleshootTapped, properties: [:])
2121
}
2222

23+
static func settingsTroubleshootTapped() -> WooAnalyticsEvent {
24+
.init(statName: .settingsTroubleshootConnectionTapped, properties: [:])
25+
}
26+
2327
static func requestResponse(test: Test, success: Bool, timeTaken: Double) -> WooAnalyticsEvent {
2428
.init(statName: .connectivityToolRequestResponse,
2529
properties: [

WooCommerce/Classes/Analytics/WooAnalyticsStat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ enum WooAnalyticsStat: String {
321321
case settingsSelectedStoreTapped = "settings_selected_site_tapped"
322322
case settingsContactSupportTapped = "main_menu_contact_support_tapped"
323323
case settingsDomainsTapped = "settings_domains_tapped"
324+
case settingsTroubleshootConnectionTapped = "settings_troubleshoot_connection_tapped"
324325

325326
case settingsBetaFeaturesButtonTapped = "settings_beta_features_button_tapped"
326327
case settingsBetaFeaturesProductsToggled = "settings_beta_features_products_toggled"

WooCommerce/Classes/ViewRelated/Connectivity Tool/ConnectivityTool.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ struct ConnectivityTool: View {
103103
.padding()
104104
}
105105
.background(Color(uiColor: .listBackground))
106+
.navigationTitle(Localization.title)
107+
.navigationBarTitleDisplayMode(.inline)
106108
}
107109
}
108110

@@ -112,6 +114,11 @@ private extension ConnectivityTool {
112114
comment: "Subtitle on the connectivity tool screen")
113115
static let contactSupport = NSLocalizedString("Contact Support",
114116
comment: "Contact support button in the connectivity tool screen")
117+
static let title = NSLocalizedString(
118+
"connectivityTool.title",
119+
value: "Troubleshoot Connection",
120+
comment: "Screen title for the connectivity tool"
121+
)
115122
}
116123
}
117124

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewController.swift

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ private extension SettingsViewController {
144144
configureWooCommmerceDetails(cell: cell)
145145
case let cell as BasicTableViewCell where row == .domain:
146146
configureDomain(cell: cell)
147+
case let cell as BasicTableViewCell where row == .connectivity:
148+
configureConnectivity(cell: cell)
147149
case let cell as BasicTableViewCell where row == .installJetpack:
148150
configureInstallJetpack(cell: cell)
149151
case let cell as BasicTableViewCell where row == .themes:
@@ -213,6 +215,12 @@ private extension SettingsViewController {
213215
cell.textLabel?.text = Localization.domain
214216
}
215217

218+
func configureConnectivity(cell: BasicTableViewCell) {
219+
cell.accessoryType = .disclosureIndicator
220+
cell.selectionStyle = .default
221+
cell.textLabel?.text = Localization.connectivity
222+
}
223+
216224
func configureInstallJetpack(cell: BasicTableViewCell) {
217225
cell.accessoryType = .disclosureIndicator
218226
cell.selectionStyle = .default
@@ -489,6 +497,12 @@ private extension SettingsViewController {
489497
show(controller, sender: self)
490498
}
491499

500+
func showConnectivityTool() {
501+
ServiceLocator.analytics.track(event: .ConnectivityTool.settingsTroubleshootTapped())
502+
let controller = ConnectivityToolViewController()
503+
show(controller, sender: self)
504+
}
505+
492506
func deviceSettingsWasPressed() {
493507
guard let targetURL = URL(string: UIApplication.openSettingsURLString) else {
494508
return
@@ -668,6 +682,8 @@ extension SettingsViewController: UITableViewDelegate {
668682
showThemeSettings()
669683
case .notifications:
670684
showNotificationSettings()
685+
case .connectivity:
686+
showConnectivityTool()
671687
default:
672688
break
673689
}
@@ -727,6 +743,7 @@ extension SettingsViewController {
727743
case installJetpack
728744
case storeName
729745
case themes
746+
case connectivity
730747

731748
// Help & Feedback
732749
case support
@@ -772,7 +789,7 @@ extension SettingsViewController {
772789
return HostingTableViewCell<PluginDetailsRowContent>.self
773790
case .support:
774791
return BasicTableViewCell.self
775-
case .domain:
792+
case .domain, .connectivity:
776793
return BasicTableViewCell.self
777794
case .installJetpack:
778795
return BasicTableViewCell.self
@@ -848,6 +865,12 @@ private extension SettingsViewController {
848865
comment: "Navigates to domain settings screen."
849866
)
850867

868+
static let connectivity = NSLocalizedString(
869+
"settingsViewController.connectivity",
870+
value: "Troubleshoot Connection",
871+
comment: "Navigates to connectivity test screen."
872+
)
873+
851874
static let installJetpack = NSLocalizedString(
852875
"Install Jetpack",
853876
comment: "Navigates to Install Jetpack screen."

WooCommerce/Classes/ViewRelated/Dashboard/Settings/Settings/SettingsViewModel.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ private extension SettingsViewModel {
214214
rows.append(.domain)
215215
}
216216

217+
if stores.isAuthenticated,
218+
stores.isAuthenticatedWithoutWPCom == false,
219+
stores.sessionManager.defaultSite?.isWordPressComStore == false {
220+
rows.append(.connectivity)
221+
}
222+
217223
guard rows.isNotEmpty else {
218224
return nil
219225
}

WooCommerce/WooCommerceTests/ViewRelated/Settings/SettingsViewModelTests.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ final class SettingsViewModelTests: XCTestCase {
355355
XCTAssertFalse(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.notifications) })
356356
}
357357

358-
func test_sections_does_not_contain_notifications_row_for_Jetpack_site_and_user_is_authenticated_with_WPCom() {
358+
func test_sections_contains_notifications_row_for_Jetpack_site_and_user_is_authenticated_with_WPCom() {
359359
// Given
360360
let featureFlagService = MockFeatureFlagService(notificationSettings: true)
361361
let testSite = Site.fake().copy(siteID: 123, isJetpackThePluginInstalled: true, isJetpackConnected: true)
@@ -368,6 +368,42 @@ final class SettingsViewModelTests: XCTestCase {
368368
// Then
369369
XCTAssertTrue(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.notifications) })
370370
}
371+
372+
func test_sections_does_not_contain_connectivity_row_for_wpcom_site() {
373+
let testSite = Site.fake().copy(siteID: 123, isJetpackThePluginInstalled: true, isJetpackConnected: true, isWordPressComStore: true)
374+
let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: true, defaultSite: testSite))
375+
let viewModel = SettingsViewModel(stores: stores)
376+
377+
// When
378+
viewModel.onViewDidLoad()
379+
380+
// Then
381+
XCTAssertFalse(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.connectivity) })
382+
}
383+
384+
func test_sections_does_not_contain_connectivity_row_if_user_authenticated_without_wpcom() {
385+
let testSite = Site.fake().copy(siteID: 123, isJetpackThePluginInstalled: true, isJetpackConnected: true, isWordPressComStore: false)
386+
let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: false, defaultSite: testSite))
387+
let viewModel = SettingsViewModel(stores: stores)
388+
389+
// When
390+
viewModel.onViewDidLoad()
391+
392+
// Then
393+
XCTAssertFalse(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.connectivity) })
394+
}
395+
396+
func test_sections_contains_connectivity_row_if_user_authenticated_with_wpcom_to_non_wpcom_site() {
397+
let testSite = Site.fake().copy(siteID: 123, isJetpackThePluginInstalled: true, isJetpackConnected: true, isWordPressComStore: false)
398+
let stores = MockStoresManager(sessionManager: .makeForTesting(authenticated: true, isWPCom: true, defaultSite: testSite))
399+
let viewModel = SettingsViewModel(stores: stores)
400+
401+
// When
402+
viewModel.onViewDidLoad()
403+
404+
// Then
405+
XCTAssertTrue(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.connectivity) })
406+
}
371407
}
372408

373409
private final class MockSettingsPresenter: SettingsViewPresenter {

0 commit comments

Comments
 (0)