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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import Foundation
import UIKit
extension MockBlueskyService {
var firstPage: [Post] { initialPosts.map(withInteractions) }
var initialPosts: [Post] {
if usesRichScrollFixture { return richScrollFixture.posts }
if ProcessInfo.processInfo.arguments.contains("-ui-testing-post-targets") { return postTargetFixture }
var posts = [
Post(
id: "post-1", author: authors[0],
text: "Morning walk along the water. The light changed every few minutes.", likeCount: 18,
repostCount: 3, isLiked: false, isReposted: false, imageURLs: [], replyIDs: ["post-2"],
createdAt: Date(timeIntervalSince1970: 1_714_998_896)),
Post(
id: "post-2", author: authors[1],
text: "A small reminder to take breaks and look away from the screen.", likeCount: 42, repostCount: 8,
isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1", replyRootCID: "",
replyParentURI: "post-1", replyParentCID: "", replyIDs: []),
Post(
id: "post-3", author: authors[2], text: "This is a quote post. Open the link to read the original.",
likeCount: 7, repostCount: 1, isLiked: false, isReposted: false, imageURLs: [],
quote: Post.Quote(postID: "post-2"), replyIDs: [])
]
if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-scroll") {
let encodedImage = Self.imageGridPNGData.base64EncodedString()
return (0..<24).map { index in
let imageURL = URL(string: "data:image/png;name=scroll-image-\(index);base64,\(encodedImage)")!
return Post(
id: "image-scroll-\(index)", author: authors[index % authors.count],
text: "Image \(index + 1)", likeCount: 0, repostCount: 0,
isLiked: false, isReposted: false, imageURLs: [imageURL], replyIDs: [])
}
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-adult-media") {
posts[0].moderationLabels = [.init(value: "porn", sourceDID: ModerationPolicy.defaultLabelerDID)]
posts[0].imageURLs = [URL(string: "data:image/png;base64,\(Self.imageGridPNGData.base64EncodedString())")!]
posts[1].replyRootURI = nil
posts[1].replyParentURI = nil
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-info-label") {
posts[0].moderationLabels = [.init(value: "scam", sourceDID: posts[0].author.id)]
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-content-warnings") {
let warning = ModerationPolicy.Label(value: "!warn", sourceDID: ModerationPolicy.defaultLabelerDID)
if ProcessInfo.processInfo.arguments.contains("-ui-testing-notification-warning") {
posts[0].moderationLabels = [warning]
} else {
posts[0].quote = Post.Quote(
postID: "warning-quote", author: authors[2], text: "A quoted post with a warning.",
moderationLabels: [warning])
posts[1].replyRootURI = nil
posts[1].replyParentURI = nil
}
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-reply-attribution") {
posts.insert(
Post(
id: "attribution-selected", author: authors[2], text: "The latest reply.", likeCount: 0,
repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-2", replyIDs: []), at: 0)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-context-quote") {
posts[0].text =
"A thread starts here with enough text to wrap across several lines. "
+ "This text must stay above the quoted post."
posts[0].quote = Post.Quote(postID: "post-3", author: authors[2], text: "The quoted post.")
posts[0].author.isFollowing = true
posts[1].author.isFollowing = true
posts.swapAt(0, 1)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-share") {
posts.insert(
Post(
id: "at://did:plc:sharetest/app.bsky.feed.post/abc123", author: authors[0],
text: "A post to share.", likeCount: 0, repostCount: 0, isLiked: false, isReposted: false,
imageURLs: [], replyIDs: []), at: 0)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-own-post") {
let author = Post.Author(id: account.id, name: account.displayName, handle: account.handle)
posts.insert(
Post(
id: "at://\(account.id)/app.bsky.feed.post/own123", author: author,
text: "My post to share and delete.", likeCount: 0, repostCount: 0, isLiked: false,
isReposted: false, imageURLs: [], replyIDs: []), at: 0)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-facets") {
let rootText =
"Root context: @alex.example shared https://oldsky.app/post?uri=post-2 and https://example.com/reply."
posts[0].text = rootText
posts[0].facets = [
Self.mockFacet(in: rootText, matching: "@alex.example", feature: .mention("alex")),
Self.mockFacet(
in: rootText, matching: "https://oldsky.app/post?uri=post-2",
feature: .link(URL(string: "https://oldsky.app/post?uri=post-2")!)),
Self.mockFacet(
in: rootText, matching: "https://example.com/reply",
feature: .link(URL(string: "https://example.com/reply")!))
]
let quotedText =
"Quoted context: @mae.example shared https://oldsky.app/post?uri=post-1 and https://example.com/quote."
posts[2].quote = Post.Quote(
postID: "post-2",
author: authors[1],
text: quotedText,
facets: [
Self.mockFacet(in: quotedText, matching: "@mae.example", feature: .mention("mae")),
Self.mockFacet(
in: quotedText, matching: "https://oldsky.app/post?uri=post-1",
feature: .link(URL(string: "https://oldsky.app/post?uri=post-1")!)),
Self.mockFacet(
in: quotedText, matching: "https://example.com/quote",
feature: .link(URL(string: "https://example.com/quote")!))
]
)
posts[0].author.isFollowing = true
posts[1].author.isFollowing = true
posts.swapAt(0, 1)
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-gif") {
let image = URL(
string:
"data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAAAAAAALAAAAAABAAEAAAIBRAAh+QQAAAAA"
+ "ACwAAAAAAQABAAACAUQAOw=="
)!
posts[0].gifURLs = [image]
posts[0].imageDescriptions[image] = "A moving square."
posts[1].imageURLs = [image]
posts[1].gifURLs = [image]
posts[0].quote = Post.Quote(postID: "post-2", author: authors[1], text: "Quoted GIF", gifURLs: [image])
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-video") {
posts[0].videoURLs = [URL(fileURLWithPath: "/ui-test-missing-video.mp4")]
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-link-only") {
posts.insert(
Post(
id: "link-only", author: authors[0], text: " \n ", likeCount: 0, repostCount: 0, isLiked: false,
isReposted: false, imageURLs: [], links: [URL(string: "https://example.com/article")!], replyIDs: []
), at: 0)
return posts
}
if let imageCount = imageGridImageCount {
let encodedImage = Self.imageGridPNGData.base64EncodedString()
posts[0].imageURLs = (1...imageCount).compactMap {
URL(string: "data:image/png;name=ui-test-image-\($0);base64,\(encodedImage)")
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-quality") {
let data = ProcessInfo.processInfo.arguments.contains("-ui-testing-image-failure")
? Data("invalid".utf8) : Self.viewerPNGData
let thumbnails = posts[0].imageURLs
posts[0].imageURLs = thumbnails.indices.map { index in
URL(string: "data:image/png;name=viewer-\(index);base64,\(data.base64EncodedString())")!
}
posts[0].imageThumbnailURLs = Dictionary(uniqueKeysWithValues: zip(posts[0].imageURLs, thumbnails))
}
if let first = posts[0].imageURLs.first {
posts[0].imageDescriptions[first] = "A blue square."
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-image-grid-reply-context") {
posts[0].author.isFollowing = true
posts[1].author.isFollowing = true
posts.swapAt(0, 1)
}
return posts
}
guard replyBranchesEnabled else { return posts }
posts[0].replyIDs = ["post-2", "post-branch-a", "post-branch-b", "post-branch-child"]
posts.append(contentsOf: [
Post(
id: "post-gap", author: authors[1], text: "A reply after a longer conversation.", likeCount: 0,
repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-gap-parent", replyIDs: []),
Post(
id: "post-gap-parent", author: authors[2], text: "A later reply in the conversation.", likeCount: 0,
repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-gap-middle", replyIDs: []),
Post(
id: "post-branch-a", author: authors[1], text: "A separate conversation starts here.", likeCount: 0,
repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-1", replyIDs: ["post-branch-child"], replyCount: 1),
Post(
id: "post-branch-b", author: authors[2], text: "Another separate conversation starts here.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-1", replyIDs: [], replyCount: 0),
Post(
id: "post-branch-child", author: authors[0], text: "A direct reply in the first separate conversation.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-branch-a", replyIDs: [])
])
if ProcessInfo.processInfo.arguments.contains("-ui-testing-thread-gap-link"),
let index = posts.firstIndex(where: { $0.id == "post-gap-parent" }) {
posts[index].links = [URL(string: "https://example.invalid/thread")!]
for index in posts.indices { posts[index].author.isFollowing = true }
}
if ProcessInfo.processInfo.arguments.contains("-ui-testing-long-reply-branch") {
posts.append(
contentsOf: (1...9).map { index in
Post(
id: "post-branch-preview-\(index)", author: authors[1], text: "Reply \(index) in this branch.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [],
replyRootURI: "post-1", replyParentURI: "post-branch-a", replyIDs: [])
})
posts.append(contentsOf: [
Post(
id: "post-branch-sibling", author: authors[2], text: "A second reply in this branch.", likeCount: 0,
repostCount: 0, isLiked: false, isReposted: false, imageURLs: [], replyRootURI: "post-1",
replyParentURI: "post-branch-a", replyIDs: []),
Post(
id: "post-branch-grandchild", author: authors[1], text: "A deeper reply in this branch.",
likeCount: 0, repostCount: 0, isLiked: false, isReposted: false, imageURLs: [],
replyRootURI: "post-1", replyParentURI: "post-branch-child", replyIDs: [])
])
}
return posts
}
}