Skip to content

Commit 7c8adf7

Browse files
authored
Merge branch 'trunk' into issue/bring-old-editing-back
2 parents cd526b5 + 338b94a commit 7c8adf7

12 files changed

+214
-1
lines changed

Fakes/Fakes/Networking.generated.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,19 @@ extension DotcomError {
188188
.empty
189189
}
190190
}
191+
extension DotcomUser {
192+
/// Returns a "ready to use" type filled with fake values.
193+
///
194+
public static func fake() -> DotcomUser {
195+
.init(
196+
id: .fake(),
197+
username: .fake(),
198+
email: .fake(),
199+
displayName: .fake(),
200+
avatar: .fake()
201+
)
202+
}
203+
}
191204
extension InboxAction {
192205
/// Returns a "ready to use" type filled with fake values.
193206
///
@@ -220,6 +233,19 @@ extension InboxNote {
220233
)
221234
}
222235
}
236+
extension JetpackUser {
237+
/// Returns a "ready to use" type filled with fake values.
238+
///
239+
public static func fake() -> JetpackUser {
240+
.init(
241+
isConnected: .fake(),
242+
isPrimary: .fake(),
243+
username: .fake(),
244+
wpcomUser: .fake(),
245+
gravatar: .fake()
246+
)
247+
}
248+
}
223249
extension Leaderboard {
224250
/// Returns a "ready to use" type filled with fake values.
225251
///

RELEASE-NOTES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
-----
55
- [**] Products: Now you can duplicate products from the More menu of the product detail screen. [https://github.com/woocommerce/woocommerce-ios/pull/7727]
66
- [*] Orders: We are bringing back the ability to add/edit customer notes and addresses from the main order screen [https://github.com/woocommerce/woocommerce-ios/pull/7750]
7+
- [*] Help center: Added help center web page with FAQs for "Wrong WordPress.com account error" screen. [https://github.com/woocommerce/woocommerce-ios/pull/7747]
78

89
10.4
910
-----

WooCommerce/Classes/Authentication/Navigation Exceptions/ULAccountMismatchViewController.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ final class ULAccountMismatchViewController: UIViewController {
5252
super.viewDidLoad()
5353

5454
configureAccountHeader()
55+
configureRightBarButtonItem()
5556
configureImageView()
5657
configureErrorMessage()
5758
configureExtraInfoButton()
@@ -75,6 +76,16 @@ final class ULAccountMismatchViewController: UIViewController {
7576

7677
// MARK: - View configuration
7778
private extension ULAccountMismatchViewController {
79+
func configureRightBarButtonItem() {
80+
guard let rightBarButtonTitle = viewModel.rightBarButtonItemTitle else {
81+
return
82+
}
83+
navigationItem.rightBarButtonItem = UIBarButtonItem(title: rightBarButtonTitle,
84+
style: .plain,
85+
target: self,
86+
action: #selector(didTapRightBarButtonItem))
87+
}
88+
7889
func configureAccountHeader() {
7990
configureGravatar()
8091
configureUserNameLabel()
@@ -184,6 +195,10 @@ private extension ULAccountMismatchViewController {
184195
func didTapLogOutButton() {
185196
viewModel.didTapLogOutButton(in: self)
186197
}
198+
199+
@objc func didTapRightBarButtonItem() {
200+
viewModel.didTapRightBarButtonItem(in: self)
201+
}
187202
}
188203

189204

WooCommerce/Classes/Authentication/Navigation Exceptions/ULAccountMismatchViewModel.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,27 @@ protocol ULAccountMismatchViewModel {
4444
/// Executes action associated to a tap in the view controller auxiliary button
4545
/// - Parameter viewController: usually the view controller sending the tap
4646
func didTapAuxiliaryButton(in viewController: UIViewController?)
47+
48+
// MARK: Navigation bar - right bar button item
49+
//
50+
51+
/// Title of the right bar button item in the navigation bar
52+
/// return `nil` if you don't want a `rightBarButtonItem`
53+
///
54+
var rightBarButtonItemTitle: String? { get }
55+
56+
/// Executes action associated to a tap on the right bar button item in the navigation bar
57+
/// - Parameter viewController: usually the view controller sending the tap
58+
///
59+
func didTapRightBarButtonItem(in viewController: UIViewController?)
60+
}
61+
62+
// MARK: Default implementation for optional right bar button item
63+
//
64+
extension ULAccountMismatchViewModel {
65+
var rightBarButtonItemTitle: String? { nil }
66+
67+
func didTapRightBarButtonItem(in viewController: UIViewController?) {
68+
// NO-OP
69+
}
4770
}

WooCommerce/Classes/Authentication/Navigation Exceptions/WrongAccountErrorViewModel.swift

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,20 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
1111
private let showsConnectedStores: Bool
1212
private let defaultAccount: Account?
1313
private let storesManager: StoresManager
14+
private let authentication: Authentication
1415

1516
private var storePickerCoordinator: StorePickerCoordinator?
1617

1718
init(siteURL: String?,
1819
showsConnectedStores: Bool,
1920
sessionManager: SessionManagerProtocol = ServiceLocator.stores.sessionManager,
20-
storesManager: StoresManager = ServiceLocator.stores) {
21+
storesManager: StoresManager = ServiceLocator.stores,
22+
authentication: Authentication = ServiceLocator.authenticationManager) {
2123
self.siteURL = siteURL ?? Localization.yourSite
2224
self.showsConnectedStores = showsConnectedStores
2325
self.defaultAccount = sessionManager.defaultAccount
2426
self.storesManager = storesManager
27+
self.authentication = authentication
2528
}
2629

2730
// MARK: - Data and configuration
@@ -82,6 +85,11 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
8285

8386
var isPrimaryButtonHidden: Bool { !showsConnectedStores }
8487

88+
// Configures `Help` button title
89+
var rightBarButtonItemTitle: String? {
90+
Localization.helpBarButtonItemTitle
91+
}
92+
8593
// MARK: - Actions
8694
func didTapPrimaryButton(in viewController: UIViewController?) {
8795
guard let navigationController = viewController?.navigationController else {
@@ -104,6 +112,13 @@ final class WrongAccountErrorViewModel: ULAccountMismatchViewModel {
104112
storesManager.deauthenticate()
105113
viewController?.navigationController?.popToRootViewController(animated: true)
106114
}
115+
116+
func didTapRightBarButtonItem(in viewController: UIViewController?) {
117+
guard let viewController = viewController else {
118+
return
119+
}
120+
authentication.presentSupport(from: viewController, screen: .wrongAccountError)
121+
}
107122
}
108123

109124

@@ -139,6 +154,8 @@ private extension WrongAccountErrorViewModel {
139154
comment: "Prompt asking users if the logged in to the wrong account."
140155
+ "Presented when logging in with a store address that does not match the account entered.")
141156

157+
static let helpBarButtonItemTitle = NSLocalizedString("Help",
158+
comment: "Help button on account mismatch error screen.")
142159
}
143160

144161
enum Strings {

WooCommerce/Classes/Model/CustomHelpCenterContent.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ extension CustomHelpCenterContent {
6969
/// Store picker screen - `StorePickerViewController`
7070
///
7171
case storePicker
72+
73+
/// Account mismatch / Wrong WordPress.com account screen - `WrongAccountErrorViewModel`
74+
///
75+
case wrongAccountError
7276
}
7377

7478
init(screen: Screen, flow: AuthenticatorAnalyticsTracker.Flow) {
@@ -80,6 +84,9 @@ extension CustomHelpCenterContent {
8084
case .storePicker:
8185
step = "site_list" // Matching Android `Step` value
8286
url = WooConstants.URLs.helpCenterForStorePicker.asURL()
87+
case .wrongAccountError:
88+
step = "wrong_wordpress_account" // Matching Android `Step` value
89+
url = WooConstants.URLs.helpCenterForWrongAccountError.asURL()
8390
}
8491

8592
trackingProperties = [

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ extension WooConstants {
123123
///
124124
case helpCenterForJetpackRequiredError = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#jetpack-required"
125125

126+
/// Help Center for "Wrong Account error" screen
127+
///
128+
case helpCenterForWrongAccountError = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#wrong-account"
129+
126130
/// Help Center for "Store picker" screen
127131
///
128132
case helpCenterForStorePicker = "https://woocommerce.com/document/android-ios-apps-login-help-faq/#pick-store-after-entering-password"

WooCommerce/WooCommerceTests/Authentication/JetpackErrorViewModelTests.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,18 @@ final class JetpackErrorViewModelTests: XCTestCase {
136136
// Then
137137
XCTAssertTrue(mockAuthentication.presentSupportFromScreenInvoked)
138138
}
139+
140+
func test_viewModel_sends_correct_screen_value_in_present_support_method() throws {
141+
// Given
142+
let mockAuthentication = MockAuthentication()
143+
let viewModel = JetpackErrorViewModel(siteURL: Expectations.url, authentication: mockAuthentication) { _ in }
144+
145+
// When
146+
viewModel.didTapRightBarButtonItem(in: UIViewController())
147+
148+
// Then
149+
XCTAssertEqual(mockAuthentication.presentSupportFromScreen, .jetpackRequired)
150+
}
139151
}
140152

141153

WooCommerce/WooCommerceTests/Authentication/ULAccountMismatchViewControllerTests.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,50 @@ final class ULAccountMismatchViewControllerTests: XCTestCase {
150150
// Then
151151
XCTAssertEqual(primaryButton.isHidden, viewModel.isPrimaryButtonHidden)
152152
}
153+
154+
func test_viewcontroller_does_not_have_right_bar_button_item_when_rightBarButtonItemTitle_is_nil_in_viewmodel() throws {
155+
// Given
156+
let viewModel = MismatchViewModel()
157+
viewModel.rightBarButtonItemTitle = nil
158+
let viewController = ULAccountMismatchViewController(viewModel: viewModel)
159+
160+
// When
161+
_ = try XCTUnwrap(viewController.view)
162+
163+
// Then
164+
XCTAssertNil(viewController.navigationItem.rightBarButtonItem)
165+
}
166+
167+
func test_viewcontroller_shows_right_bar_button_item_when_rightBarButtonItemTitle_provided_by_viewmodel() throws {
168+
// Given
169+
let title = "Title"
170+
let viewModel = MismatchViewModel()
171+
viewModel.rightBarButtonItemTitle = title
172+
let viewController = ULAccountMismatchViewController(viewModel: viewModel)
173+
174+
// When
175+
_ = try XCTUnwrap(viewController.view)
176+
let rightBarButtonItem = try XCTUnwrap(viewController.navigationItem.rightBarButtonItem)
177+
178+
// Then
179+
XCTAssertEqual(rightBarButtonItem.title, title)
180+
}
181+
182+
func test_viewcontroller_hits_viewmodel_when_right_bar_button_item_is_tapped() throws {
183+
// Given
184+
let viewModel = MismatchViewModel()
185+
viewModel.rightBarButtonItemTitle = "Button"
186+
let viewController = ULAccountMismatchViewController(viewModel: viewModel)
187+
188+
// When
189+
_ = try XCTUnwrap(viewController.view)
190+
let rightBarButtonItem = try XCTUnwrap(viewController.navigationItem.rightBarButtonItem)
191+
192+
_ = rightBarButtonItem.target?.perform(rightBarButtonItem.action)
193+
194+
// Then
195+
XCTAssertTrue(viewModel.rightBarButtonItemTapped)
196+
}
153197
}
154198

155199

@@ -172,10 +216,13 @@ private final class MismatchViewModel: ULAccountMismatchViewModel {
172216

173217
let primaryButtonTitle: String = "Primary"
174218

219+
var rightBarButtonItemTitle: String?
220+
175221
let isPrimaryButtonHidden: Bool = false
176222
var primaryButtonTapped: Bool = false
177223
var logOutButtonTapped: Bool = false
178224
var auxiliaryButtonTapped: Bool = false
225+
var rightBarButtonItemTapped = false
179226

180227
func didTapPrimaryButton(in viewController: UIViewController?) {
181228
primaryButtonTapped = true
@@ -188,4 +235,8 @@ private final class MismatchViewModel: ULAccountMismatchViewModel {
188235
func didTapAuxiliaryButton(in viewController: UIViewController?) {
189236
auxiliaryButtonTapped = true
190237
}
238+
239+
func didTapRightBarButtonItem(in viewController: UIViewController?) {
240+
rightBarButtonItemTapped = true
241+
}
191242
}

WooCommerce/WooCommerceTests/Authentication/WrongAccountErrorViewModelTests.swift

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ final class WrongAccountErrorViewModelTests: XCTestCase {
3636
XCTAssertEqual(primaryButtonTitle, Expectations.primaryButtonTitle)
3737
}
3838

39+
func test_viewmodel_provides_expected_title_for_right_bar_button_item() {
40+
// Given
41+
let viewModel = WrongAccountErrorViewModel(siteURL: Expectations.url, showsConnectedStores: false)
42+
43+
// Then
44+
XCTAssertEqual(viewModel.rightBarButtonItemTitle, Expectations.helpBarButtonItemTitle)
45+
}
46+
3947
func test_viewmodel_provides_expected_title_for_log_out_button() {
4048
// Given
4149
let viewModel = WrongAccountErrorViewModel(siteURL: Expectations.url, showsConnectedStores: false)
@@ -57,6 +65,30 @@ final class WrongAccountErrorViewModelTests: XCTestCase {
5765
// Then
5866
XCTAssertTrue(visibility)
5967
}
68+
69+
func test_viewModel_invokes_present_support_when_the_help_button_is_tapped() throws {
70+
// Given
71+
let mockAuthentication = MockAuthentication()
72+
let viewModel = WrongAccountErrorViewModel(siteURL: Expectations.url, showsConnectedStores: false, authentication: mockAuthentication)
73+
74+
// When
75+
viewModel.didTapRightBarButtonItem(in: UIViewController())
76+
77+
// Then
78+
XCTAssertTrue(mockAuthentication.presentSupportFromScreenInvoked)
79+
}
80+
81+
func test_viewModel_sends_correct_screen_value_in_present_support_method() throws {
82+
// Given
83+
let mockAuthentication = MockAuthentication()
84+
let viewModel = WrongAccountErrorViewModel(siteURL: Expectations.url, showsConnectedStores: false, authentication: mockAuthentication)
85+
86+
// When
87+
viewModel.didTapRightBarButtonItem(in: UIViewController())
88+
89+
// Then
90+
XCTAssertEqual(mockAuthentication.presentSupportFromScreen, .wrongAccountError)
91+
}
6092
}
6193

6294

@@ -76,5 +108,8 @@ private extension WrongAccountErrorViewModelTests {
76108
static let findYourConnectedEmail = NSLocalizedString("Find your connected email",
77109
comment: "Button linking to webview explaining how to find your connected email"
78110
+ "Presented when logging in with a store address that does not match the account entered")
111+
112+
static let helpBarButtonItemTitle = NSLocalizedString("Help",
113+
comment: "Help button on account mismatch error screen.")
79114
}
80115
}

0 commit comments

Comments
 (0)