1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import Foundation
import UIKit
extension MockBlueskyService {
func loadNotifications(cursor: String?) async throws -> NotificationPage {
if ProcessInfo.processInfo.arguments.contains("-ui-testing-pull-refresh-delay") {
try await Task.sleep(for: .seconds(4))
}
if cursor == nil, ProcessInfo.processInfo.arguments.contains("-ui-testing-notification-delay") {
try await Task.sleep(for: .seconds(15))
}
let now = Date()
let likedPost = firstPage[0]
if ProcessInfo.processInfo.arguments.contains("-ui-testing-grouped-notifications") {
return groupedNotifications(now: now, post: likedPost)
}
if cursor != nil { return laterNotifications(now: now, likedPost: likedPost) }
return firstNotifications(now: now, likedPost: likedPost)
}
private func groupedNotifications(now: Date, post: Post) -> NotificationPage {
let reasons: [FeedNotification.Reason] = [.like, .repost]
let notifications = reasons.flatMap { reason in
profiles.prefix(2).map { profile in
var author = profile.author
author.bio = profile.bio
return FeedNotification(
id: "\(reason.rawValue)-\(author.id)", author: author, reason: reason,
indexedAt: now, isRead: false, postID: post.id, relatedPost: post)
}
}
return NotificationPage(notifications: notifications, cursor: nil)
}
private func laterNotifications(now: Date, likedPost: Post) -> NotificationPage {
let quote = withInteractions(
Post(
id: "quote-post-1", author: authors[2], text: "A short thought about the quoted post.",
likeCount: 2, repostCount: 1, isLiked: false, isReposted: false, imageURLs: [],
quote: Post.Quote(postID: "post-1"), replyIDs: []))
return NotificationPage(
notifications: [
FeedNotification(
id: "notification-4", author: authors[0], reason: .follow,
indexedAt: now.addingTimeInterval(-172_800), isRead: true, postID: nil),
FeedNotification(
id: "notification-5", author: authors[1], reason: .repost,
indexedAt: now.addingTimeInterval(-259_200), isRead: false, postID: likedPost.id,
relatedPost: likedPost),
FeedNotification(
id: "notification-6", author: authors[2], reason: .quote,
indexedAt: now.addingTimeInterval(-345_600), isRead: false, postID: quote.id, relatedPost: quote
),
FeedNotification(
id: "notification-7", author: authors[2], reason: .mention,
indexedAt: now.addingTimeInterval(-432_000), isRead: false, postID: "mention-post-1",
relatedPost: withInteractions(
Post(
id: "mention-post-1", author: authors[2],
text: "Take a look at this, @demo.bsky.social. The post is the main content.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [],
replyIDs: [])))
], cursor: nil)
}
private func firstNotifications(now: Date, likedPost: Post) -> NotificationPage {
let replyParent =
ProcessInfo.processInfo.arguments.contains("-ui-testing-own-reply-parent")
? Post(
id: "own-parent",
author: Post.Author(
id: account.id, name: account.displayName, handle: account.handle,
moderationLabels: ProcessInfo.processInfo.arguments.contains("-ui-testing-info-label")
? [.init(value: "scam", sourceDID: account.id)] : []), text: "A post by the signed-in account.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyIDs: [])
: likedPost
let reply = Post(
id: "reply-post-1",
author: authors[1],
text: "Thanks for the thoughtful reply.",
likeCount: 0,
repostCount: 0,
isLiked: false,
isReposted: false,
imageURLs: [],
replyRootURI: replyParent.id,
replyParentURI: replyParent.id,
replyIDs: []
)
var followAuthor = authors[2]
followAuthor.bio = profiles[2].bio
return NotificationPage(
notifications: [
FeedNotification(
id: "notification-1", author: authors[0], reason: .like, indexedAt: now.addingTimeInterval(-300),
isRead: false, postID: likedPost.id, relatedPost: likedPost),
FeedNotification(
id: "notification-2", author: authors[1], reason: .reply, indexedAt: now.addingTimeInterval(-3600),
isRead: false, postID: reply.id, relatedPost: withInteractions(reply),
parentPost: withInteractions(replyParent)),
FeedNotification(
id: "notification-3", author: followAuthor, reason: .follow,
indexedAt: now.addingTimeInterval(-86_400), isRead: true, postID: nil)
], cursor: "mock-notifications-page-2")
}
func markNotificationsRead(seenAt: Date) async throws {
loadState.notificationsSeenAt.append(seenAt)
if failsMarkingNotificationsRead { throw ServiceError.invalidResponse }
}
}