Skip to content

Commit 14a544b

Browse files
committed
Revert "Apply new changes to NotWPAccountViewModel and update tests"
This reverts commit 91848c4.
1 parent 91848c4 commit 14a544b

File tree

2 files changed

+112
-17
lines changed

2 files changed

+112
-17
lines changed

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ final class NotWPAccountViewModel: ULErrorViewModel {
2121

2222
let isPrimaryButtonHidden: Bool
2323

24-
let secondaryButtonTitle = Localization.tryAnotherAddress
24+
var secondaryButtonTitle: String {
25+
isSimplifiedLoginI1Enabled ? Localization.tryAnotherAddress : Localization.restartLogin
26+
}
2527
let isSecondaryButtonHidden: Bool
2628

2729
private weak var viewController: UIViewController?
@@ -40,13 +42,15 @@ final class NotWPAccountViewModel: ULErrorViewModel {
4042
return button
4143
}()
4244

45+
private let isSimplifiedLoginI1Enabled: Bool
4346
private let analytics: Analytics
4447
private var storePickerCoordinator: StorePickerCoordinator?
4548

4649
init(error: Error,
4750
analytics: Analytics = ServiceLocator.analytics,
4851
featureFlagService: FeatureFlagService = ServiceLocator.featureFlagService) {
4952
self.analytics = analytics
53+
self.isSimplifiedLoginI1Enabled = ABTest.abTestLoginWithWPComOnly.variation != .control
5054
if let error = error as? SignInError,
5155
case let .invalidWPComEmail(source) = error,
5256
source == .wpComSiteAddress {
@@ -56,14 +60,23 @@ final class NotWPAccountViewModel: ULErrorViewModel {
5660
} else {
5761
isSecondaryButtonHidden = false
5862

59-
primaryButtonTitle = Localization.createAnAccount
60-
isPrimaryButtonHidden = !featureFlagService.isFeatureFlagEnabled(.storeCreationMVP)
63+
if isSimplifiedLoginI1Enabled {
64+
primaryButtonTitle = Localization.createAnAccount
65+
isPrimaryButtonHidden = !featureFlagService.isFeatureFlagEnabled(.storeCreationMVP)
66+
} else {
67+
primaryButtonTitle = Localization.loginWithSiteAddress
68+
isPrimaryButtonHidden = false
69+
}
6170
}
6271
}
6372

6473
// MARK: - Actions
6574
func didTapPrimaryButton(in viewController: UIViewController?) {
66-
createAnAccountButtonTapped(in: viewController)
75+
if isSimplifiedLoginI1Enabled {
76+
createAnAccountButtonTapped(in: viewController)
77+
} else {
78+
loginWithSiteAddressButtonTapped()
79+
}
6780
}
6881

6982
func didTapSecondaryButton(in viewController: UIViewController?) {
@@ -97,6 +110,11 @@ private extension NotWPAccountViewModel {
97110
viewController?.present(fancyAlert, animated: true)
98111
}
99112

113+
func loginWithSiteAddressButtonTapped() {
114+
let popCommand = NavigateToEnterSite()
115+
popCommand.execute(from: viewController)
116+
}
117+
100118
func createAnAccountButtonTapped(in viewController: UIViewController?) {
101119
analytics.track(.createAccountOnInvalidEmailScreenTapped)
102120
guard let viewController,
@@ -123,6 +141,10 @@ private extension NotWPAccountViewModel {
123141
comment: "Button linking to webview that explains what Jetpack is"
124142
+ "Presented when logging in with a site address that does not have a valid Jetpack installation")
125143

144+
static let loginWithSiteAddress = NSLocalizedString("Log in with your store address",
145+
comment: "Action button linking to instructions for enter another store."
146+
+ "Presented when logging in with an email address that is not a WordPress.com account")
147+
126148
static let createAnAccount = NSLocalizedString("Create An Account",
127149
comment: "Action button linking to create WooCommerce store flow."
128150
+ "Presented when logging in with an email address that is not a WordPress.com account")

WooCommerce/WooCommerceTests/Authentication/NotWPAccountViewModelTests.swift

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,24 @@ final class NotWPAccountViewModelTests: XCTestCase {
6767
XCTAssertEqual(auxiliaryButtonTitle, AuthenticationConstants.whatIsWPComLinkTitle)
6868
}
6969

70-
func test_viewmodel_provides_expected_title_for_primary_button() {
70+
func test_viewmodel_provides_expected_title_for_primary_button_when_simplified_login_feature_flag_is_off() {
7171
// Given
72-
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom))
72+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: false)
73+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
74+
featureFlagService: featureFlagService)
75+
76+
// When
77+
let primaryButtonTitle = viewModel.primaryButtonTitle
78+
79+
// Then
80+
XCTAssertEqual(primaryButtonTitle, Expectations.loginWithSiteAddressTitle)
81+
}
82+
83+
func test_viewmodel_provides_expected_title_for_primary_button_when_simplified_login_feature_flag_is_on() {
84+
// Given
85+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true)
86+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
87+
featureFlagService: featureFlagService)
7388
// When
7489
let primaryButtonTitle = viewModel.primaryButtonTitle
7590

@@ -90,9 +105,23 @@ final class NotWPAccountViewModelTests: XCTestCase {
90105
XCTAssertEqual(primaryButtonTitle, Expectations.restartLoginTitle)
91106
}
92107

93-
func test_primary_button_title_is_create_an_account_for_invalidWPComEmail_from_wpCom_error() {
108+
func test_primary_button_title_is_login_with_site_address_for_invalidWPComEmail_from_wpCom_error_when_simplified_login_feature_flag_is_off() {
94109
// Given
95-
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom))
110+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: false)
111+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
112+
featureFlagService: featureFlagService)
113+
// When
114+
let primaryButtonTitle = viewModel.primaryButtonTitle
115+
116+
// Then
117+
XCTAssertEqual(primaryButtonTitle, Expectations.loginWithSiteAddressTitle)
118+
}
119+
120+
func test_primary_button_title_is_create_an_account_for_invalidWPComEmail_from_wpCom_error_when_simplified_login_feature_flag_is_on() {
121+
// Given
122+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true)
123+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
124+
featureFlagService: featureFlagService)
96125
// When
97126
let primaryButtonTitle = viewModel.primaryButtonTitle
98127

@@ -110,18 +139,29 @@ final class NotWPAccountViewModelTests: XCTestCase {
110139
XCTAssertFalse(viewModel.isPrimaryButtonHidden)
111140
}
112141

113-
func test_primary_button_is_not_hidden_for_invalidWPComEmail_from_wpCom_error_when_store_creation_is_on() {
142+
func test_primary_button_is_not_hidden_for_invalidWPComEmail_from_wpCom_error_when_simplified_login_feature_flag_is_off() {
114143
// Given
115-
let featureFlagService = MockFeatureFlagService(isStoreCreationMVPEnabled: true)
144+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: false)
116145
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
117146
featureFlagService: featureFlagService)
118147
// Then
119148
XCTAssertFalse(viewModel.isPrimaryButtonHidden)
120149
}
121150

122-
func test_primary_button_is_hidden_for_invalidWPComEmail_from_wpCom_error_when_store_creation_is_off() {
151+
func test_primary_button_is_not_hidden_for_invalidWPComEmail_from_wpCom_error_when_simplified_login_is_on_and_store_creation_is_on() {
123152
// Given
124-
let featureFlagService = MockFeatureFlagService(isStoreCreationMVPEnabled: false)
153+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true,
154+
isStoreCreationMVPEnabled: true)
155+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
156+
featureFlagService: featureFlagService)
157+
// Then
158+
XCTAssertFalse(viewModel.isPrimaryButtonHidden)
159+
}
160+
161+
func test_primary_button_is_hidden_for_invalidWPComEmail_from_wpCom_error_when_simplified_login_is_on_and_store_creation_is_off() {
162+
// Given
163+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true,
164+
isStoreCreationMVPEnabled: false)
125165
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
126166
featureFlagService: featureFlagService)
127167
// Then
@@ -148,9 +188,24 @@ final class NotWPAccountViewModelTests: XCTestCase {
148188

149189
// MARK: - `secondaryButtonTitle`
150190

151-
func test_viewmodel_provides_expected_title_for_secondary_button() {
191+
func test_viewmodel_provides_expected_title_for_secondary_button_when_simplified_login_feature_flag_is_off() {
152192
// Given
153-
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom))
193+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: false)
194+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
195+
featureFlagService: featureFlagService)
196+
197+
// When
198+
let secondaryButtonTitle = viewModel.secondaryButtonTitle
199+
200+
// Then
201+
XCTAssertEqual(secondaryButtonTitle, Expectations.restartLoginTitle)
202+
}
203+
204+
func test_viewmodel_provides_expected_title_for_secondary_button_when_simplified_login_feature_flag_is_on() {
205+
// Given
206+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true)
207+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
208+
featureFlagService: featureFlagService)
154209
// When
155210
let secondaryButtonTitle = viewModel.secondaryButtonTitle
156211

@@ -177,8 +232,10 @@ final class NotWPAccountViewModelTests: XCTestCase {
177232

178233
func test_tapping_auxiliary_button_tracks_what__is_wordpress_com_event() {
179234
// Given
235+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true)
180236
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
181-
analytics: analytics)
237+
analytics: analytics,
238+
featureFlagService: featureFlagService)
182239

183240
// When
184241
viewModel.didTapAuxiliaryButton(in: nil)
@@ -187,10 +244,26 @@ final class NotWPAccountViewModelTests: XCTestCase {
187244
XCTAssertNotNil(analyticsProvider.receivedEvents.first(where: { $0 == "what_is_wordpress_com_on_invalid_email_screen" }))
188245
}
189246

190-
func test_tapping_primary_button_tracks_create_account_event() {
247+
func test_tapping_primary_button_does_not_track_create_account_event_when_simplified_login_feature_flag_is_off() {
191248
// Given
249+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: false)
192250
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
193-
analytics: analytics)
251+
analytics: analytics,
252+
featureFlagService: featureFlagService)
253+
254+
// When
255+
viewModel.didTapPrimaryButton(in: nil)
256+
257+
// Then
258+
XCTAssertNil(analyticsProvider.receivedEvents.first(where: { $0 == "create_account_on_invalid_email_screen" }))
259+
}
260+
261+
func test_tapping_primary_button_tracks_create_account_event_when_simplified_login_feature_flag_is_on() {
262+
// Given
263+
let featureFlagService = MockFeatureFlagService(isSimplifiedLoginFlowI1Enabled: true)
264+
let viewModel = NotWPAccountViewModel(error: SignInError.invalidWPComEmail(source: .wpCom),
265+
analytics: analytics,
266+
featureFlagService: featureFlagService)
194267

195268
// When
196269
viewModel.didTapPrimaryButton(in: nil)

0 commit comments

Comments
 (0)