Skip to content

Commit bbe5e2a

Browse files
authored
Merge pull request #5901 from woocommerce/issue/5886-reactive-settings
Jetpack CP: Reload Settings sections when dismissing Install Jetpack screen
2 parents ef8776b + a0c9a1c commit bbe5e2a

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,7 @@ private extension SettingsViewController {
307307
let installJetpackController = JetpackInstallHostingController(siteID: site.siteID, siteURL: site.url, siteAdminURL: site.adminURL)
308308
installJetpackController.setDismissAction { [weak self] in
309309
self?.dismiss(animated: true, completion: nil)
310+
self?.viewModel.onJetpackInstallDismiss()
310311
}
311312
present(installJetpackController, animated: true, completion: nil)
312313
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ protocol SettingsViewModelActionsHandler {
3838
/// Presenter (SettingsViewController in this case) is responsible for calling this method when store picker is dismissed.
3939
///
4040
func onStorePickerDismiss()
41+
42+
/// Reloads settings if the site is no longer Jetpack CP.
43+
///
44+
func onJetpackInstallDismiss()
4145
}
4246

4347
protocol SettingsViewModelInput: AnyObject {
@@ -140,6 +144,15 @@ final class SettingsViewModel: SettingsViewModelOutput, SettingsViewModelActions
140144
loadSites()
141145
reloadSettings()
142146
}
147+
148+
/// Reloads settings if the site is no longer Jetpack CP.
149+
///
150+
func onJetpackInstallDismiss() {
151+
guard stores.sessionManager.defaultSite?.isJetpackCPConnected == false else {
152+
return
153+
}
154+
reloadSettings()
155+
}
143156
}
144157

145158
private extension SettingsViewModel {

WooCommerce/WooCommerceTests/ViewRelated/Settings/SettingsViewModelTests.swift

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,28 @@ final class SettingsViewModelTests: XCTestCase {
151151
// Then
152152
XCTAssertTrue(presenter.refreshViewContentCalled)
153153
}
154+
155+
func test_onJetpackInstallDismiss_updates_sections_correctly() {
156+
// Given
157+
let featureFlagService = MockFeatureFlagService(isJetpackConnectionPackageSupportOn: true)
158+
let site = Site.fake().copy(isJetpackThePluginInstalled: false, isJetpackConnected: true)
159+
sessionManager.defaultSite = site
160+
let viewModel = SettingsViewModel(
161+
stores: stores,
162+
storageManager: storageManager,
163+
featureFlagService: featureFlagService)
164+
165+
viewModel.onViewDidLoad()
166+
XCTAssertTrue(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.installJetpack) })
167+
168+
// When
169+
let updatedSite = site.copy(isJetpackThePluginInstalled: true, isJetpackConnected: false)
170+
sessionManager.defaultSite = updatedSite
171+
viewModel.onJetpackInstallDismiss()
172+
173+
// Then
174+
XCTAssertFalse(viewModel.sections.contains { $0.rows.contains(SettingsViewController.Row.installJetpack) })
175+
}
154176
}
155177

156178
private final class MockSettingsPresenter: SettingsViewPresenter {

0 commit comments

Comments
 (0)