Skip to content

Commit 1007e43

Browse files
authored
Merge pull request #7352 from woocommerce/feat/7318-login-wpcom-action
Login Reminder: add an action to log in with WP.com for site address error notiifcation
2 parents ae9c46e + aff921d commit 1007e43

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

WooCommerce/Classes/Notifications/LocalNotification.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,15 @@ struct LocalNotification {
2727
/// The action type in a local notification.
2828
enum Action: String {
2929
case contactSupport
30+
case loginWithWPCom
3031

3132
/// The title of the action in a local notification.
3233
var title: String {
3334
switch self {
3435
case .contactSupport:
3536
return NSLocalizedString("Contact support", comment: "Local notification action to contact support.")
37+
case .loginWithWPCom:
38+
return NSLocalizedString("Login with WordPress.com", comment: "Local notification action to log in with WordPress.com.")
3639
}
3740
}
3841
}
@@ -45,7 +48,7 @@ extension LocalNotification {
4548
self.init(title: Localization.errorLoggingInTitle,
4649
body: Localization.errorLoggingInBody,
4750
scenario: .loginSiteAddressError,
48-
actions: .init(category: .loginError, actions: [.contactSupport]))
51+
actions: .init(category: .loginError, actions: [.contactSupport, .loginWithWPCom]))
4952
}
5053
}
5154
}

WooCommerce/Classes/ViewRelated/AppCoordinator.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Combine
22
import Experiments
33
import UIKit
4+
import WordPressAuthenticator
45
import Yosemite
56
import class AutomatticTracks.CrashLogging
67

@@ -253,6 +254,17 @@ private extension AppCoordinator {
253254
"action": "contact_support",
254255
"type": response.notification.request.identifier
255256
])
257+
case LocalNotification.Action.loginWithWPCom.rawValue:
258+
guard let loginNavigationController = window.rootViewController as? LoginNavigationController,
259+
let viewController = loginNavigationController.topViewController else {
260+
return
261+
}
262+
let command = NavigateToEnterAccount()
263+
command.execute(from: viewController)
264+
analytics.track(.loginLocalNotificationTapped, withProperties: [
265+
"action": "login_with_wpcom",
266+
"type": response.notification.request.identifier
267+
])
256268
case UNNotificationDefaultActionIdentifier:
257269
// Triggered when the user taps on the notification itself instead of one of the actions.
258270
switch response.notification.request.identifier {

WooCommerce/WooCommerceTests/AppCoordinatorTests.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,30 @@ final class AppCoordinatorTests: XCTestCase {
230230
XCTAssertEqual(typePropertyValue, "site_address_error")
231231
}
232232

233+
func test_loginLocalNotificationTapped_is_tracked_after_notification_loginWithWPCom_action() throws {
234+
// Given
235+
let analytics = MockAnalyticsProvider()
236+
let pushNotesManager = MockPushNotificationsManager()
237+
let appCoordinator = makeCoordinator(window: window,
238+
stores: stores,
239+
authenticationManager: authenticationManager,
240+
analytics: WooAnalytics(analyticsProvider: analytics),
241+
pushNotesManager: pushNotesManager)
242+
appCoordinator.start()
243+
244+
// When
245+
let response = try XCTUnwrap(MockNotificationResponse(actionIdentifier: LocalNotification.Action.loginWithWPCom.rawValue,
246+
requestIdentifier: LocalNotification.Scenario.loginSiteAddressError.rawValue))
247+
pushNotesManager.sendLocalNotificationResponse(response)
248+
249+
// Then
250+
XCTAssertEqual(analytics.receivedEvents, [WooAnalyticsStat.loginLocalNotificationTapped.rawValue])
251+
let actionPropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["action"] as? String)
252+
XCTAssertEqual(actionPropertyValue, "login_with_wpcom")
253+
let typePropertyValue = try XCTUnwrap(analytics.receivedProperties.first?["type"] as? String)
254+
XCTAssertEqual(typePropertyValue, "site_address_error")
255+
}
256+
233257
func test_loginLocalNotificationTapped_is_tracked_after_notification_tap_action() throws {
234258
// Given
235259
let analytics = MockAnalyticsProvider()

0 commit comments

Comments
 (0)