~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1

test(ui): isolate setup and add focused coverage

Merged geesawra.industries asked to merge into main from geesawra.industries/old-fella:test/atomic-ui
scripts/dev.sh+6−1
@@ -95,7 +95,12 @@ case "${1:-}" in
;;
test)
DEVICE_ID="$(first_simulator)"
xcodebuild -scheme Oldsky -destination "platform=iOS Simulator,id=$DEVICE_ID" test
selector="${2:-}"
if [ -n "$selector" ]; then
xcodebuild -scheme Oldsky -destination "platform=iOS Simulator,id=$DEVICE_ID" "-only-testing:$selector" test
else
xcodebuild -scheme Oldsky -destination "platform=iOS Simulator,id=$DEVICE_ID" test
fi
;;
*)
echo "Usage: $0 {build|sim|device|device-release|test}" >&2
Sources/Oldsky/BlueskyService.swift+19−5
@@ -23,6 +23,7 @@ struct MockBlueskyService: BlueskyService {
var failsPublishing = false
var failsMarkingNotificationsRead = false
var requiresAuthFactorToken = false
var restoresAccount = false
var threadResponseDelayNanoseconds: UInt64 = 0
var replyBranchesEnabled = ProcessInfo.processInfo.arguments.contains("-ui-testing-reply-branches")
var threadReplyOrder: [String] = []
@@ -44,6 +45,7 @@ struct MockBlueskyService: BlueskyService {
init(
failsPublishing: Bool = false,
requiresAuthFactorToken: Bool = false,
restoresAccount: Bool = false,
threadResponseDelayNanoseconds: UInt64 = 0,
replyBranchesEnabled: Bool = ProcessInfo.processInfo.arguments.contains("-ui-testing-reply-branches"),
threadReplyOrder: [String] = [],
@@ -53,6 +55,7 @@ struct MockBlueskyService: BlueskyService {
) {
self.failsPublishing = failsPublishing
self.requiresAuthFactorToken = requiresAuthFactorToken
self.restoresAccount = restoresAccount
self.threadResponseDelayNanoseconds = threadResponseDelayNanoseconds
self.replyBranchesEnabled = replyBranchesEnabled
self.threadReplyOrder = threadReplyOrder
@@ -73,7 +76,7 @@ struct MockBlueskyService: BlueskyService {
Profile(author: Post.Author(id: "sam", name: "Sam Lee", handle: "sam.example"), bio: "Learning to cook one seasonal recipe at a time.", location: nil, website: URL(string: "https://sam.example"), followerCount: 2301, followingCount: 701)
]
func restoreAccount() async throws -> Account? { nil }
func restoreAccount() async throws -> Account? { restoresAccount ? account : nil }
func signIn(handle: String, appPassword: String, authFactorToken: String?) async throws -> Account {
if requiresAuthFactorToken && authFactorToken == nil {
throw ServiceError.authFactorTokenRequired
@@ -102,6 +105,9 @@ struct MockBlueskyService: BlueskyService {
FeedNotification(id: "notification-7", author: authors[2], reason: .mention, indexedAt: now.addingTimeInterval(-432_000), isRead: false, postID: "mention-post-1", relatedPost: 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)
}
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), 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],
@@ -111,13 +117,13 @@ struct MockBlueskyService: BlueskyService {
isLiked: false,
isReposted: false,
imageURLs: [],
replyRootURI: likedPost.id,
replyParentURI: likedPost.id,
replyRootURI: replyParent.id,
replyParentURI: replyParent.id,
replyIDs: []
)
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: reply, parentPost: likedPost),
FeedNotification(id: "notification-2", author: authors[1], reason: .reply, indexedAt: now.addingTimeInterval(-3600), isRead: false, postID: reply.id, relatedPost: reply, parentPost: replyParent),
FeedNotification(id: "notification-3", author: authors[2], reason: .follow, indexedAt: now.addingTimeInterval(-86_400), isRead: true, postID: nil)
], cursor: "mock-notifications-page-2")
}
@@ -197,7 +203,15 @@ struct MockBlueskyService: BlueskyService {
return result
}
func loadProfile(actorID: String) async throws -> Profile? { profiles.first { $0.author.id == actorID } }
func loadProfile(actorID: String) async throws -> Profile? {
if actorID == account.id {
return Profile(
author: Post.Author(id: account.id, name: account.displayName, handle: account.handle),
bio: "", location: nil, website: nil, followerCount: 0, followingCount: 0
)
}
return profiles.first { $0.author.id == actorID }
}
func loadAuthorPosts(actorID: String, cursor: String?) async throws -> FeedPage {
loadState.authorFeedLoadCount += 1
loadState.authorFeedActorIDs.append(actorID)
Sources/Oldsky/OldskyApp.swift+27−3
@@ -48,15 +48,27 @@ enum AppPalette {
@main
struct OldskyApp: App {
@StateObject private var model: AppModel
private let defaults: UserDefaults
init() {
let arguments = ProcessInfo.processInfo.arguments
let isUITesting = arguments.contains("-ui-testing")
if isUITesting { UserDefaults.standard.removeObject(forKey: "hideQuotedPosts") }
if isUITesting {
let suite = "com.oldsky.app.ui-tests"
let testDefaults = UserDefaults(suiteName: suite)!
testDefaults.removePersistentDomain(forName: suite)
defaults = testDefaults
} else {
defaults = .standard
}
let requiresAuthFactor = arguments.contains("-ui-testing-auth-factor")
let threadResponseDelay: UInt64 = arguments.contains("-ui-testing-thread-delay") ? 3_000_000_000 : 0
let service: any BlueskyService = isUITesting
? MockBlueskyService(requiresAuthFactorToken: requiresAuthFactor, threadResponseDelayNanoseconds: threadResponseDelay)
? MockBlueskyService(
requiresAuthFactorToken: requiresAuthFactor,
restoresAccount: arguments.contains("-ui-testing-signed-in"),
threadResponseDelayNanoseconds: threadResponseDelay
)
: ATProtoBlueskyService()
_model = StateObject(wrappedValue: AppModel(service: service))
}
@@ -64,6 +76,7 @@ struct OldskyApp: App {
var body: some Scene {
WindowGroup {
RootView()
.defaultAppStorage(defaults)
.tint(AppPalette.accent)
.environmentObject(model)
}
@@ -521,6 +534,16 @@ struct NotificationsView: View {
}
PostTimestamp(date: notification.indexedAt).fixedSize()
}
ReplyContextPosts(
post: reply,
posts: notification.parentPost.map { [$0] } ?? [],
avatarIdentifierPrefix: "notificationReplyAvatar",
openPost: { path.append(.post($0)) },
openProfile: { path.append(.profile($0)) },
openComposer: { replyTo, quotePostID in
showComposer(replyTo: replyTo, quotePostID: quotePostID)
}
)
PostRow(
post: reply,
openPost: { path.append(.post(reply.id)) },
@@ -1036,6 +1059,7 @@ struct ReplyContextPosts: View {
let post: Post
let posts: [Post]
var avatarIdentifierPrefix = "replyContextAvatar"
let openPost: (String) -> Void
let openProfile: (String) -> Void
let openComposer: (String?, String?) -> Void
@@ -1075,7 +1099,7 @@ struct ReplyContextPosts: View {
titleAuthorName: isRoot ? nil : parent?.author.name,
showsReplyArrow: contextPost.id != post.replyRootURI,
openProfile: { openProfile(contextPost.author.id) },
avatarIdentifierPrefix: "replyContextAvatar",
avatarIdentifierPrefix: avatarIdentifierPrefix,
showsBar: false,
openActor: openProfile,
openLinkedPost: openPost,
Tests/OldskyTests/AppModelTests.swift+9−0
@@ -57,6 +57,15 @@ final class AppModelTests: XCTestCase {
XCTAssertTrue(model.hasMorePosts)
}
func testMockAccountRestorationLoadsFollowingFeed() async throws {
let service = MockBlueskyService(restoresAccount: true)
let account = try await service.restoreAccount()
XCTAssertEqual(account?.handle, "demo.bsky.social")
let page = try await service.loadFollowingFeed(cursor: nil)
XCTAssertEqual(page.posts.map(\.id), ["post-1", "post-2", "post-3"])
XCTAssertEqual(page.cursor, "page-2")
}
func testSignInCanContinueAfterAuthFactorChallenge() async {
let model = AppModel(service: MockBlueskyService(requiresAuthFactorToken: true))
await model.signIn(handle: "demo.bsky.social", appPassword: "test-only")
Tests/OldskyUITests/OldskyUITests.swift+175−92
@@ -10,21 +10,6 @@ final class OldskyUITests: XCTestCase {
app.buttons["demoSignInButton"].tap()
XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
app.buttons["postText-post-2"].tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-post-1"].exists)
XCTAssertTrue(app.buttons["postText-post-2"].isHittable)
XCTAssertTrue(app.descendants(matching: .any)["earlierPostsCue"].waitForExistence(timeout: 5))
app.navigationBars.buttons["Following"].tap()
app.buttons["profileLink-mae"].tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertTrue(app.staticTexts["Mae Rivers"].exists)
app.buttons["followButton"].tap()
XCTAssertTrue(app.buttons["Following"].exists)
app.navigationBars.buttons["Following"].tap()
app.buttons["yourProfileButton"].tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
app.navigationBars.buttons["Following"].tap()
app.tabBars.buttons["New post"].tap()
let editor = app.textViews["composeTextField"]
XCTAssertTrue(editor.waitForExistence(timeout: 5))
@@ -37,11 +22,45 @@ final class OldskyUITests: XCTestCase {
XCTAssertTrue(createdPost.waitForExistence(timeout: 5))
}
func testFollowFromProfile() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let profile = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(profile.waitForExistence(timeout: 5))
profile.tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
app.buttons["followButton"].tap()
XCTAssertTrue(app.buttons["Following"].waitForExistence(timeout: 5))
}
func testOwnProfileOpens() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let profile = app.buttons["yourProfileButton"]
XCTAssertTrue(profile.waitForExistence(timeout: 5))
profile.tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Demo Account")
}
func testEarlierPostsCueAppearsInThread() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
let post = app.buttons["postText-post-2"]
XCTAssertTrue(post.waitForExistence(timeout: 5))
post.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.descendants(matching: .any)["earlierPostsCue"].waitForExistence(timeout: 5))
}
func testFollowingBarRemainsVisibleWhenScrolling() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let profile = app.buttons["yourProfileButton"]
XCTAssertTrue(profile.waitForExistence(timeout: 5))
app.swipeUp()
@@ -52,8 +71,8 @@ final class OldskyUITests: XCTestCase {
func testVideoViewerHasOneCloseButton() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-video"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let video = app.buttons["Tap here to play the video"].firstMatch
XCTAssertTrue(video.waitForExistence(timeout: 5))
video.tap()
@@ -68,8 +87,8 @@ final class OldskyUITests: XCTestCase {
func testPostTimestampIsRelativeInFeedAndDetail() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let timestamp = app.staticTexts["postTimestamp-post-1"]
XCTAssertTrue(timestamp.waitForExistence(timeout: 5))
XCTAssertLessThanOrEqual(timestamp.label.count, 4)
@@ -86,8 +105,8 @@ final class OldskyUITests: XCTestCase {
func testQuoteShowsOriginalAndOpensPost() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let quote = app.buttons["quotedPostLink"]
for _ in 0..<5 {
@@ -104,8 +123,8 @@ final class OldskyUITests: XCTestCase {
func testHideQuotedPostsSetting() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
app.tabBars.buttons["Settings"].tap()
let setting = app.switches["hideQuotedPosts"]
XCTAssertTrue(setting.waitForExistence(timeout: 5))
@@ -130,14 +149,13 @@ final class OldskyUITests: XCTestCase {
func testNotificationsAndSettingsTabs() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
XCTAssertTrue(app.tabBars.buttons["Following"].waitForExistence(timeout: 5))
app.tabBars.buttons["Notifications"].tap()
XCTAssertTrue(app.navigationBars["Notifications"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-reply-post-1"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons.matching(NSPredicate(format: "identifier CONTAINS %@ AND label CONTAINS %@", "replyContext-post-1", "Your post Mae Rivers")).firstMatch.exists)
XCTAssertTrue(app.buttons["postText-reply-post-1"].label.contains("Thanks for the thoughtful reply."))
XCTAssertFalse(app.staticTexts["Alex Kim replied to your post"].exists)
let likedPost = app.buttons["notificationPost-notification-1"]
@@ -145,27 +163,6 @@ final class OldskyUITests: XCTestCase {
likedPost.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.navigationBars.buttons["Notifications"].tap()
app.buttons["loadMoreNotificationsButton"].tap()
XCTAssertTrue(app.buttons["notification-notification-4"].waitForExistence(timeout: 5))
XCTAssertTrue(app.staticTexts["Alex Kim reposted your post"].exists)
XCTAssertTrue(app.buttons["notificationPost-notification-5"].exists)
let quotedPostLink = app.buttons["quotedPostLink"]
for _ in 0..<5 {
if quotedPostLink.exists && quotedPostLink.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(quotedPostLink.exists)
app.tabBars.buttons["Following"].tap()
app.tabBars.buttons["Notifications"].tap()
let replyPost = app.buttons["postText-reply-post-1"]
for _ in 0..<5 {
if replyPost.exists && replyPost.isHittable { break }
app.swipeDown()
}
app.buttons["postText-reply-post-1"].tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
app.navigationBars.buttons["Notifications"].tap()
app.tabBars.buttons["Settings"].tap()
XCTAssertTrue(app.navigationBars["Settings"].waitForExistence(timeout: 5))
XCTAssertTrue(app.staticTexts["settingsDisplayName"].exists)
@@ -175,31 +172,106 @@ final class OldskyUITests: XCTestCase {
XCTAssertTrue(app.staticTexts["Sign in to Bluesky"].waitForExistence(timeout: 5))
}
func testNotificationAvatarsOpenProfiles() {
func testNotificationReplyShowsContextAndOpensReply() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.buttons["demoSignInButton"].tap()
app.tabBars.buttons["Notifications"].tap()
let reply = app.buttons["postText-reply-post-1"]
XCTAssertTrue(reply.waitForExistence(timeout: 5))
let context = app.descendants(matching: .any)["replyContext-post-1"].firstMatch
XCTAssertTrue(context.waitForExistence(timeout: 5))
XCTAssertTrue(context.label.contains("Morning walk along the water."))
XCTAssertTrue(app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "Thread started by Mae Rivers")).firstMatch.exists)
reply.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-reply-post-1"].waitForExistence(timeout: 5))
}
let actorAvatar = app.buttons["notificationAvatar-notification-1"]
XCTAssertTrue(actorAvatar.waitForExistence(timeout: 5))
actorAvatar.tap()
XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
func testNotificationReplyParentAvatarOpensProfile() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.tabBars.buttons["Notifications"].tap()
let avatar = app.buttons["notificationReplyAvatar-post-1"]
XCTAssertTrue(avatar.waitForExistence(timeout: 5))
avatar.tap()
XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
app.navigationBars.buttons["Notifications"].tap()
}
app.buttons["notificationPostAvatar-post-1"].tap()
XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
app.navigationBars.buttons["Notifications"].tap()
func testNotificationReplyShowsOwnParentAuthor() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-own-reply-parent"]
app.launch()
app.tabBars.buttons["Notifications"].tap()
let context = app.descendants(matching: .any)["replyContext-own-parent"].firstMatch
XCTAssertTrue(context.waitForExistence(timeout: 5))
XCTAssertTrue(context.label.contains("A post by the signed-in account."))
XCTAssertTrue(app.buttons.matching(NSPredicate(format: "label CONTAINS %@", "Thread started by Demo Account")).firstMatch.exists)
}
func testNotificationReplyRespectsHiddenContextSetting() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.tabBars.buttons["Settings"].tap()
let setting = app.switches["hideReplyContexts"]
XCTAssertTrue(setting.waitForExistence(timeout: 5))
setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap()
app.tabBars.buttons["Notifications"].tap()
let link = app.buttons["replyContextLink-reply-post-1"]
XCTAssertTrue(link.waitForExistence(timeout: 5))
XCTAssertTrue(link.label.contains("In reply to Mae Rivers"))
XCTAssertFalse(app.descendants(matching: .any)["replyContext-post-1"].exists)
link.tap()
XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
}
func testNotificationPaginationShowsRepostAndQuote() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.tabBars.buttons["Notifications"].tap()
let more = app.buttons["loadMoreNotificationsButton"]
XCTAssertTrue(more.waitForExistence(timeout: 5))
more.tap()
let repost = app.buttons["notificationPost-notification-5"]
for _ in 0..<5 {
if repost.exists { break }
app.swipeUp()
}
XCTAssertTrue(repost.waitForExistence(timeout: 5))
XCTAssertTrue(repost.label.hasPrefix("Your post"))
let quote = app.buttons["quotedPostLink"]
for _ in 0..<5 {
if quote.exists && quote.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(quote.waitForExistence(timeout: 5))
}
app.buttons["notificationReplyAvatar-post-1"].tap()
func testLikeNotificationAvatarOpensProfile() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.tabBars.buttons["Notifications"].tap()
let avatar = app.buttons["notificationAvatar-notification-1"]
XCTAssertTrue(avatar.waitForExistence(timeout: 5))
avatar.tap()
XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers")
app.navigationBars.buttons["Notifications"].tap()
}
app.buttons["notificationAvatar-notification-3"].tap()
func testFollowNotificationAvatarOpensProfile() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"]
app.launch()
app.tabBars.buttons["Notifications"].tap()
let avatar = app.buttons["notificationAvatar-notification-3"]
XCTAssertTrue(avatar.waitForExistence(timeout: 5))
avatar.tap()
XCTAssertTrue(app.navigationBars["Profile"].waitForExistence(timeout: 5))
XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Sam Lee")
}
@@ -207,8 +279,8 @@ final class OldskyUITests: XCTestCase {
func testMentionShowsFullPostAndActions() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
XCTAssertTrue(app.tabBars.buttons["Notifications"].waitForExistence(timeout: 5))
app.tabBars.buttons["Notifications"].tap()
let loadMore = app.buttons["loadMoreNotificationsButton"]
@@ -253,8 +325,8 @@ final class OldskyUITests: XCTestCase {
func testTappedPostKeepsScreenPositionWhenThreadLoads() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-thread-delay"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let timelinePost = app.buttons["postText-post-2"]
XCTAssertTrue(timelinePost.waitForExistence(timeout: 5))
timelinePost.tap()
@@ -286,8 +358,8 @@ final class OldskyUITests: XCTestCase {
func testThreadAuthorStaysBelowTopBarWithImmediateResponse() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let timelinePost = app.buttons["postText-post-2"]
XCTAssertTrue(timelinePost.waitForExistence(timeout: 5))
timelinePost.tap()
@@ -309,8 +381,8 @@ final class OldskyUITests: XCTestCase {
func testProfileLoadsMorePostsOnlyAfterExplicitTap() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let avatar = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(avatar.waitForExistence(timeout: 5))
avatar.tap()
@@ -334,8 +406,8 @@ final class OldskyUITests: XCTestCase {
func testProfileReplyShowsCompactParentPostAndOpensProfile() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let profile = app.buttons["profileLink-alex"].firstMatch
XCTAssertTrue(profile.waitForExistence(timeout: 5))
profile.tap()
@@ -353,8 +425,8 @@ final class OldskyUITests: XCTestCase {
func testHideReplyContextSetting() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let parent = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
XCTAssertTrue(parent.waitForExistence(timeout: 5))
@@ -382,8 +454,8 @@ final class OldskyUITests: XCTestCase {
func testFollowingReplyContextOpensRootPost() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let parent = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
for _ in 0..<5 {
if parent.exists && parent.isHittable { break }
@@ -400,8 +472,8 @@ final class OldskyUITests: XCTestCase {
func testReplyContextFacetsNavigateAndPlainTextOpensRootPost() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-facets"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let context = app.descendants(matching: .any)["replyContext-post-1"].firstMatch
for _ in 0..<5 {
@@ -434,8 +506,8 @@ final class OldskyUITests: XCTestCase {
func testQuotedPostFacetsNavigateAndPlainTextOpensQuotedPost() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-facets"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let quoteText = app.descendants(matching: .any)["quotedPostText-post-2"].firstMatch
for _ in 0..<6 {
@@ -468,8 +540,8 @@ final class OldskyUITests: XCTestCase {
func testFollowingReplyContextUsesMissingGapRow() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let gap = app.descendants(matching: .any)["missingReplyContext"].firstMatch
for _ in 0..<5 {
if gap.exists && gap.isHittable { break }
@@ -483,8 +555,8 @@ final class OldskyUITests: XCTestCase {
func testProfileReplyUsesFeedGapRow() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let profile = app.buttons["profileLink-alex"].firstMatch
XCTAssertTrue(profile.waitForExistence(timeout: 5))
profile.tap()
@@ -497,8 +569,8 @@ final class OldskyUITests: XCTestCase {
func testProfilePostsShareTimelineActionsAndNavigation() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let avatar = app.buttons["profileLink-mae"].firstMatch
XCTAssertTrue(avatar.waitForExistence(timeout: 5))
avatar.tap()
@@ -525,8 +597,8 @@ final class OldskyUITests: XCTestCase {
func testReplyBranchesShowNestedRepliesAndOpenThem() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-reply-branches"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let rootPost = app.buttons["postText-post-1"]
XCTAssertTrue(rootPost.waitForExistence(timeout: 5))
rootPost.tap()
@@ -551,11 +623,15 @@ final class OldskyUITests: XCTestCase {
func testFeedLoadsNextPageOnlyAfterExplicitTap() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
XCTAssertFalse(app.buttons["postText-post-4"].exists)
let loadMoreButton = app.buttons["loadMorePostsButton"]
for _ in 0..<5 {
if loadMoreButton.exists && loadMoreButton.isHittable { break }
app.swipeUp()
}
XCTAssertTrue(loadMoreButton.waitForExistence(timeout: 5))
loadMoreButton.tap()
XCTAssertTrue(app.buttons["postText-post-4"].waitForExistence(timeout: 5))
@@ -565,10 +641,10 @@ final class OldskyUITests: XCTestCase {
func testSingleImageTileFillsItsSpaceAndViewerImageFitsViewport() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
let gridImage = grid.images["Attached image"]
XCTAssertTrue(gridImage.waitForExistence(timeout: 5))
@@ -599,8 +675,8 @@ final class OldskyUITests: XCTestCase {
private func assertReplyImages(count: Int) {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "\(count)"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let context = app.descendants(matching: .any)["replyPostContext-post-1"].firstMatch
XCTAssertTrue(context.waitForExistence(timeout: 5))
let grid = context.descendants(matching: .any)["postImageGrid"].firstMatch
@@ -640,9 +716,9 @@ final class OldskyUITests: XCTestCase {
func testPostImageShowMoreAndFewer() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "5"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"].firstMatch
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"].firstMatch
XCTAssertTrue(grid.waitForExistence(timeout: 5))
let button = grid.buttons["showMoreImagesButton"]
XCTAssertTrue(button.waitForExistence(timeout: 5))
@@ -658,10 +734,10 @@ final class OldskyUITests: XCTestCase {
func testImageViewerOpensSelectedImageZoomsAndDismisses() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
let selectedGridImage = grid.images["Attached image 2 of 3"].firstMatch
XCTAssertTrue(selectedGridImage.waitForExistence(timeout: 5))
@@ -692,10 +768,10 @@ final class OldskyUITests: XCTestCase {
func testImageViewerSwipesBetweenImages() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"].firstMatch
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"].firstMatch
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.images["Attached image 2 of 3"].firstMatch.tap()
@@ -719,9 +795,9 @@ final class OldskyUITests: XCTestCase {
func testImageViewerShowsDescriptionWithButton() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"].firstMatch
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"].firstMatch
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.images["Attached image"].firstMatch.tap()
let image = app.descendants(matching: .any)["imageViewerImage"].firstMatch
@@ -739,10 +815,10 @@ final class OldskyUITests: XCTestCase {
func testImageViewerShortDownwardDragKeepsViewerOpen() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.images["Attached image"].tap()
@@ -762,10 +838,10 @@ final class OldskyUITests: XCTestCase {
func testImageViewerZoomAndPanStayOpen() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "3"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.images["Attached image 2 of 3"].firstMatch.tap()
@@ -790,10 +866,10 @@ final class OldskyUITests: XCTestCase {
func testImageViewerDownwardFlickDismisses() {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "1"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
grid.images["Attached image"].tap()
@@ -832,12 +908,18 @@ final class OldskyUITests: XCTestCase {
private func assertImageGrid(imageCount: Int, expectedColumnCount: Int) {
let app = XCUIApplication()
app.launchArguments = ["-ui-testing", "-ui-testing-image-grid", "\(imageCount)"]
app.launchArguments.append("-ui-testing-signed-in")
app.launch()
app.buttons["demoSignInButton"].tap()
let grid = app.descendants(matching: .any)["postImageGrid"]
let grid = app.cells.containing(.button, identifier: "postText-post-1").firstMatch.descendants(matching: .any)["postImageGrid"]
XCTAssertTrue(grid.waitForExistence(timeout: 5))
XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5))
if imageCount > 4 {
let more = grid.buttons["showMoreImagesButton"]
XCTAssertTrue(more.waitForExistence(timeout: 5))
more.tap()
XCTAssertEqual(more.label, "Show fewer images")
}
let images = (1...imageCount).map { index in
let imageLabel = imageCount == 1 ? "Attached image" : "Attached image \(index) of \(imageCount)"
@@ -852,7 +934,8 @@ final class OldskyUITests: XCTestCase {
XCTAssertLessThanOrEqual(image.frame.maxX, grid.frame.maxX + 1)
XCTAssertLessThanOrEqual(image.frame.maxY, grid.frame.maxY + 1)
}
XCTAssertEqual(grid.images.count, imageCount)
let attachedImages = grid.images.matching(NSPredicate(format: "label BEGINSWITH %@", "Attached image"))
XCTAssertEqual(attachedImages.count, imageCount)
let firstRowY = images[0].frame.minY
let firstRowCount = images.filter { abs($0.frame.minY - firstRowY) < 2 }.count
Justfile+2−2
@@ -19,8 +19,8 @@ device:
device-release:
./scripts/dev.sh device-release
test:
./scripts/dev.sh test
test selector="":
./scripts/dev.sh test {{quote(selector)}}
lint:
swiftlint lint --strict
README.md+7−0
@@ -47,6 +47,13 @@ OLDSKY_SIMULATOR_DEVICE="iPhone 18 Pro" OLDSKY_SIMULATOR_OS=27.2 just test
```
UI tests use predictable service responses. They do not need live Bluesky credentials or network access.
Most UI tests start with a signed-in mock account. Sign-in tests start at the sign-in screen.
To run one test, pass its identifier to `just test`. The command accepts one identifier, not arbitrary `xcodebuild` arguments.
```sh
just test OldskyUITests/OldskyUITests/testFeedLoadsNextPageOnlyAfterExplicitTap
```
## License