Skip to content

Commit

Permalink
Refactor NotificationsCenterCellViewModelGenericTests to pass in any …
Browse files Browse the repository at this point in the history
…language/region
  • Loading branch information
tonisevener committed Sep 1, 2023
1 parent 6196fdb commit ba2b40d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 28 deletions.
2 changes: 2 additions & 0 deletions WMF Framework/CommonStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ public class CommonStrings: NSObject {
public static let notificationsCenterMarkAsReadSwipe = WMFLocalizedString("notifications-center-swipe-mark-as-read", value: "Mark as read", comment: "Button text in Notifications Center swipe actions to mark a notification as read.")
public static let notificationsCenterMarkAsUnread = WMFLocalizedString("notifications-center-mark-as-unread", value: "Mark as Unread", comment: "Button text in Notifications Center to mark a notification as unread.")
public static let notificationsCenterMarkAsUnreadSwipe = WMFLocalizedString("notifications-center-swipe-mark-as-unread", value: "Mark as unread", comment: "Button text in Notifications Center swipe actions to mark a notification as unread.")
public static let notificationsCenterNotificationsSettings = WMFLocalizedString("notifications-center-notifications-settings", value: "Notification settings", comment: "Button text in Notifications Center that automatically routes to the notifications settings screen.")
public static let notificationsCenterAllNotificationsStatus = WMFLocalizedString("notifications-center-status-all", value: "All", comment: "Text to indicate all notifications in Notifications Center.")
public static let notificationsCenterReadNotificationsStatus = WMFLocalizedString("notifications-center-status-read", value: "Read", comment: "Text to indicate a read notification in Notifications Center.")
public static let notificationsCenterUnreadNotificationsStatus = WMFLocalizedString("notifications-center-status-unread", value: "Unread", comment: "Text to indicate an unread notification in Notifications Center.")
public static let notificationsCenterAgentDescriptionFromFormat = WMFLocalizedString("notifications-center-agent-description-from-format", value: "From %1$@", comment: "Text indicating who triggered a notification in notifications center. %1$@ will be replaced with the origin agent of the notification, which could be a username.")
public static let notificationsCenterAlert = WMFLocalizedString("notifications-center-alert", value: "Alert", comment: "Description of various \"alert\" notification types, used on the notifications cell and detail views.")
public static let notificationsCenterNotice = WMFLocalizedString("notifications-center-type-item-description-notice", value: "Notice", comment: "Description of \"notice\" notification types, used on the notification cell and detail views.")
public static let notificationsUserPageFormat = WMFLocalizedString("notifications-center-go-to-user-page", value: "%1$@'s user page", comment: "Button text in Notifications Center that routes to a web view of the user page of the sender that triggered the notification. %1$@ is replaced with the sender's username.")
public static let notificationsChangePassword = WMFLocalizedString("notifications-center-change-password", value: "Change password", comment: "Button text in Notifications Center that routes user to change password screen.")
public static let notificationsCenterDestinationWeb = WMFLocalizedString("notifications-center-destination-web", value: "On web", comment: "Informational text next to each notification center action on the detail screen, informing the user that the action will take them to a web view or outside of the app.")
public static let notificationsCenterDestinationApp = WMFLocalizedString("notifications-center-destination-app", value: "In app", comment: "Informational text next to each notification center action on the detail screen, informing the user that the action will take them to a native view within the app.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ extension NotificationsCenterCellViewModel {

}

let notificationSubscriptionSettingsText = WMFLocalizedString("notifications-center-notifications-settings", value: "Notification settings", comment: "Button text in Notifications Center that automatically routes to the notifications settings screen.")
let notificationSubscriptionSettingsText = CommonStrings.notificationsCenterNotificationsSettings
let notificationSettingsActionData = NotificationsCenterActionData(text: notificationSubscriptionSettingsText, url: nil, iconType: nil, destinationText: nil, actionType: .settings)
sheetActions.append(.notificationSubscriptionSettings(notificationSettingsActionData))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension NotificationsCenterCommonViewModel {
return nil
}

let format = WMFLocalizedString("notifications-center-go-to-user-page", value: "%1$@'s user page", comment: "Button text in Notifications Center that routes to a web view of the user page of the sender that triggered the notification. %1$@ is replaced with the sender's username.")
let format = CommonStrings.notificationsUserPageFormat
let text = String.localizedStringWithFormat(format, agentName)

let data = NotificationsCenterActionData(text: text, url: url, iconType: .person, destinationText: destinationText(for: url), actionType: .senderPage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
throw TestError.failureConvertingManagedObjectToViewModel
}

try testPageReviewText(cellViewModel: cellViewModel)
try testPageReviewText(notificationDate: notification.date!, cellViewModel: cellViewModel)
try testPageReviewIcons(cellViewModel: cellViewModel)
try testPageReviewActions(cellViewModel: cellViewModel)
}
Expand All @@ -26,7 +26,7 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
throw TestError.failureConvertingManagedObjectToViewModel
}

try testFlowReplyText(cellViewModel: cellViewModel)
try testFlowReplyText(notificationDate: notification.date!, cellViewModel: cellViewModel)
try testFlowReplyIcons(cellViewModel: cellViewModel)
try testFlowReplyActions(cellViewModel: cellViewModel)
}
Expand All @@ -38,17 +38,17 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
throw TestError.failureConvertingManagedObjectToViewModel
}

try testFlowTopicRenamedText(cellViewModel: cellViewModel)
try testFlowTopicRenamedText(notificationDate: notification.date!, cellViewModel: cellViewModel)
try testFlowTopicRenamedIcons(cellViewModel: cellViewModel)
try testFlowTopicRenamedActions(cellViewModel: cellViewModel)
}

private func testPageReviewText(cellViewModel: NotificationsCenterCellViewModel) throws {
private func testPageReviewText(notificationDate: Date, cellViewModel: NotificationsCenterCellViewModel) throws {
XCTAssertEqual(cellViewModel.headerText, "A reviewer suggested improvements to the page Bird. Tags: notability, blp sources.", "Invalid headerText")
XCTAssertEqual(cellViewModel.subheaderText, "Alert from Fred The Bird", "Invalid subheaderText")
XCTAssertEqual(cellViewModel.bodyText, nil)
XCTAssertEqual(cellViewModel.footerText, "View page", "Invalid footerText")
XCTAssertEqual(cellViewModel.dateText, "7/20/21", "Invalid dateText")
XCTAssertEqual(cellViewModel.dateText, DateFormatter.wmf_short().string(from: notificationDate), "Invalid dateText")
XCTAssertEqual(cellViewModel.projectText, "EN", "Invalid projectText")
}

Expand All @@ -61,7 +61,7 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel

XCTAssertEqual(cellViewModel.sheetActions.count, 5, "Invalid sheetActionsCount")

let expectedText0 = "Mark as read"
let expectedText0 = CommonStrings.notificationsCenterMarkAsReadSwipe
let expectedURL0: URL? = nil
let expectedIcon0: NotificationsCenterIconType? = nil
let expectedDestinationText0: String? = nil
Expand All @@ -71,35 +71,35 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
let expectedText1 = "View page"
let expectedURL1: URL? = URL(string: "https://en.wikipedia.org/wiki/Black_Bird?markasread=181035797&markasreadwiki=enwiki")!
let expectedIcon1: NotificationsCenterIconType = .link
let expectedDestinationText1 = "In app"
let expectedDestinationText1 = CommonStrings.notificationsCenterDestinationApp
try testActions(expectedText: expectedText1, expectedURL: expectedURL1, expectedIcon: expectedIcon1, expectedDestinationText: expectedDestinationText1, actionToTest: cellViewModel.sheetActions[1], actionType: .linkNonspecific)

let expectedText2 = "Fred The Bird"
let expectedURL2: URL? = URL(string: "https://en.wikipedia.org/wiki/User:Fred_The_Bird")!
let expectedIcon2: NotificationsCenterIconType = .link
let expectedDestinationText2 = "On web"
let expectedDestinationText2 = CommonStrings.notificationsCenterDestinationWeb
try testActions(expectedText: expectedText2, expectedURL: expectedURL2, expectedIcon: expectedIcon2, expectedDestinationText: expectedDestinationText2, actionToTest: cellViewModel.sheetActions[2], actionType: .linkNonspecific)

let expectedText3 = "Thank"
let expectedURL3: URL? = URL(string: "https://en.wikipedia.org/wiki/Special:Thanks/937441471")!
let expectedIcon3: NotificationsCenterIconType = .link
let expectedDestinationText3 = "On web"
let expectedDestinationText3 = CommonStrings.notificationsCenterDestinationWeb
try testActions(expectedText: expectedText3, expectedURL: expectedURL3, expectedIcon: expectedIcon3, expectedDestinationText: expectedDestinationText3, actionToTest: cellViewModel.sheetActions[3], actionType: .linkNonspecific)
let expectedText4 = "Notification settings"

let expectedText4 = CommonStrings.notificationsCenterNotificationsSettings
let expectedURL4: URL? = nil
let expectedIcon4: NotificationsCenterIconType? = nil
let expectedDestinationText4: String? = nil
let expectedAction4: NotificationsCenterActionData.LoggingLabel = .settings
try testActions(expectedText: expectedText4, expectedURL: expectedURL4, expectedIcon: expectedIcon4, expectedDestinationText: expectedDestinationText4, actionToTest: cellViewModel.sheetActions[4], isNotificationSettings: true, actionType: expectedAction4)
}

private func testFlowReplyText(cellViewModel: NotificationsCenterCellViewModel) throws {
private func testFlowReplyText(notificationDate: Date, cellViewModel: NotificationsCenterCellViewModel) throws {
XCTAssertEqual(cellViewModel.headerText, "Fred The Bird replied in \"Section Title\".", "Invalid headerText")
XCTAssertEqual(cellViewModel.subheaderText, "Alert from Fred The Bird", "Invalid subheaderText")
XCTAssertEqual(cellViewModel.bodyText, "Reply text")
XCTAssertEqual(cellViewModel.footerText, "View post", "Invalid footerText")
XCTAssertEqual(cellViewModel.dateText, "7/20/21", "Invalid dateText")
XCTAssertEqual(cellViewModel.dateText, DateFormatter.wmf_short().string(from: notificationDate), "Invalid dateText")
XCTAssertEqual(cellViewModel.projectText, "TEST", "Invalid projectText")
}

Expand All @@ -112,7 +112,7 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel

XCTAssertEqual(cellViewModel.sheetActions.count, 4, "Invalid sheetActionsCount")

let expectedText0 = "Mark as unread"
let expectedText0 = CommonStrings.notificationsCenterMarkAsUnreadSwipe
let expectedURL0: URL? = nil
let expectedIcon0: NotificationsCenterIconType? = nil
let expectedDestinationText0: String? = nil
Expand All @@ -122,30 +122,30 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
let expectedText1 = "View post"
let expectedURL1: URL? = URL(string: "https://test.wikipedia.org/w/index.php?title=Topic:Wcd3birxz0ixz4di&topic_showPostId=wd321irw4jqrwsyf&fromnotif=1&markasread=75530&markasreadwiki=testwiki#flow-post-wd321irw4jqrwsyf")!
let expectedIcon1: NotificationsCenterIconType = .link
let expectedDestinationText1 = "On web"
let expectedDestinationText1 = CommonStrings.notificationsCenterDestinationWeb
try testActions(expectedText: expectedText1, expectedURL: expectedURL1, expectedIcon: expectedIcon1, expectedDestinationText: expectedDestinationText1, actionToTest: cellViewModel.sheetActions[1], actionType: .linkNonspecific)

let expectedText2 = "Fred The Bird\'s user page"
let expectedText2 = String.localizedStringWithFormat(CommonStrings.notificationsUserPageFormat, "Fred The Bird")
let expectedURL2: URL? = URL(string: "https://test.wikipedia.org/wiki/User:Fred_The_Bird")!
let expectedIcon2: NotificationsCenterIconType = .person
let expectedDestinationText2 = "On web"
let expectedDestinationText2 = CommonStrings.notificationsCenterDestinationWeb
let expectedAction2: NotificationsCenterActionData.LoggingLabel = .senderPage
try testActions(expectedText: expectedText2, expectedURL: expectedURL2, expectedIcon: expectedIcon2, expectedDestinationText: expectedDestinationText2, actionToTest: cellViewModel.sheetActions[2], actionType: expectedAction2)

let expectedText3 = "Notification settings"
let expectedText3 = CommonStrings.notificationsCenterNotificationsSettings
let expectedURL3: URL? = nil
let expectedIcon3: NotificationsCenterIconType? = nil
let expectedDestinationText3: String? = nil
let expectedAction3: NotificationsCenterActionData.LoggingLabel = .settings
try testActions(expectedText: expectedText3, expectedURL: expectedURL3, expectedIcon: expectedIcon3, expectedDestinationText: expectedDestinationText3, actionToTest: cellViewModel.sheetActions[3], isNotificationSettings: true, actionType: expectedAction3)
}

private func testFlowTopicRenamedText(cellViewModel: NotificationsCenterCellViewModel) throws {
private func testFlowTopicRenamedText(notificationDate: Date, cellViewModel: NotificationsCenterCellViewModel) throws {
XCTAssertEqual(cellViewModel.headerText, "The topic \"Topic:Section Title\" was renamed to \"Section Title 2\".", "Invalid headerText")
XCTAssertEqual(cellViewModel.subheaderText, "Alert from 47.234.198.142", "Invalid subheaderText")
XCTAssertEqual(cellViewModel.bodyText, nil)
XCTAssertEqual(cellViewModel.footerText, "View topic", "Invalid footerText")
XCTAssertEqual(cellViewModel.dateText, "1/30/22", "Invalid dateText")
XCTAssertEqual(cellViewModel.dateText, DateFormatter.wmf_short().string(from: notificationDate), "Invalid dateText")
XCTAssertEqual(cellViewModel.projectText, "TEST", "Invalid projectText")
}

Expand All @@ -158,7 +158,7 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel

XCTAssertEqual(cellViewModel.sheetActions.count, 4, "Invalid sheetActionsCount")

let expectedText0 = "Mark as unread"
let expectedText0 = CommonStrings.notificationsCenterMarkAsUnreadSwipe
let expectedURL0: URL? = nil
let expectedIcon0: NotificationsCenterIconType? = nil
let expectedDestinationText0: String? = nil
Expand All @@ -168,17 +168,17 @@ class NotificationsCenterCellViewModelGenericTests: NotificationsCenterViewModel
let expectedText1 = "View topic"
let expectedURL1: URL? = URL(string: "https://test.wikipedia.org/wiki/Topic:Section_Title?markasread=88298&markasreadwiki=testwiki")!
let expectedIcon1: NotificationsCenterIconType = .link
let expectedDestinationText1 = "On web"
let expectedDestinationText1 = CommonStrings.notificationsCenterDestinationWeb
try testActions(expectedText: expectedText1, expectedURL: expectedURL1, expectedIcon: expectedIcon1, expectedDestinationText: expectedDestinationText1, actionToTest: cellViewModel.sheetActions[1], actionType: .linkNonspecific)

let expectedText2 = "47.234.198.142\'s user page"
let expectedText2 = String.localizedStringWithFormat(CommonStrings.notificationsUserPageFormat, "47.234.198.142")
let expectedURL2: URL? = URL(string: "https://test.wikipedia.org/wiki/User:47.234.198.142")!
let expectedIcon2: NotificationsCenterIconType = .person
let expectedDestinationText2 = "On web"
let expectedDestinationText2 = CommonStrings.notificationsCenterDestinationWeb
let expectedAction2: NotificationsCenterActionData.LoggingLabel = .senderPage
try testActions(expectedText: expectedText2, expectedURL: expectedURL2, expectedIcon: expectedIcon2, expectedDestinationText: expectedDestinationText2, actionToTest: cellViewModel.sheetActions[2], actionType: expectedAction2)

let expectedText3 = "Notification settings"
let expectedText3 = CommonStrings.notificationsCenterNotificationsSettings
let expectedURL3: URL? = nil
let expectedIcon3: NotificationsCenterIconType? = nil
let expectedDestinationText3: String? = nil
Expand Down

0 comments on commit ba2b40d

Please sign in to comment.