import XCTest extension OldFellaUITests { func testComposerInsertsMentionAndKeepsTyping() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["New post"].tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) editor.tap() editor.typeText("Hello @ma") let suggestion = app.buttons["mentionSuggestion-mae"] XCTAssertTrue(suggestion.waitForExistence(timeout: 5)) let initialFrame = suggestion.frame XCTAssertEqual(initialFrame.maxX, app.frame.maxX - 16, accuracy: 1) editor.typeText("\n@ma") XCTAssertTrue(suggestion.waitForExistence(timeout: 5)) XCTAssertEqual(suggestion.frame.minX, initialFrame.minX, accuracy: 1) XCTAssertGreaterThan(suggestion.frame.minY, initialFrame.minY + 10) XCTAssertLessThan(suggestion.frame.minY, editor.frame.minY + 100) XCTAssertLessThan(suggestion.frame.maxY, app.keyboards.firstMatch.frame.minY) let dropdownScreenshot = XCTAttachment(screenshot: app.screenshot()) dropdownScreenshot.name = "Mention dropdown" dropdownScreenshot.lifetime = .keepAlways add(dropdownScreenshot) suggestion.tap() XCTAssertEqual(editor.value as? String, "Hello @ma\n@mae.example ") editor.typeText("#sky https://example.com") XCTAssertEqual(editor.value as? String, "Hello @ma\n@mae.example #sky https://example.com") XCTAssertFalse(app.buttons["mentionSuggestion-mae"].exists) app.dismissComposer() app.buttons["New post"].tap() XCTAssertTrue(editor.waitForExistence(timeout: 5)) XCTAssertEqual(editor.value as? String, "") } func testComposerRetriesMentionLookupInDropdown() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-mention-failure"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["New post"].tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) editor.tap() editor.typeText("@ma") let retry = app.buttons["Retry"] XCTAssertTrue(retry.waitForExistence(timeout: 5)) XCTAssertTrue( app.staticTexts["You are not connected to the internet. Check your connection and try again."].exists) retry.tap() let suggestion = app.buttons["mentionSuggestion-mae"] XCTAssertTrue(suggestion.waitForExistence(timeout: 5)) suggestion.tap() XCTAssertEqual(editor.value as? String, "@mae.example ") } func testComposerAccessibilityLabels() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.tabBars.buttons["New post"].tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) XCTAssertEqual(editor.label, "Post text") XCTAssertTrue(app.buttons["editAltText-0"].exists) XCTAssertTrue(app.buttons["editAltText-1"].exists) XCTAssertTrue(app.buttons["Remove image 1"].exists) XCTAssertTrue(app.buttons["Remove image 2"].exists) } func testComposerEditorKeepsItsHeightWithImages() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["New post"].tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) editor.tap() editor.typeText("A draft with photos") let heightWithImages = editor.frame.height XCTAssertGreaterThanOrEqual(heightWithImages, 199) let photo = app.buttons["editAltText-0"] let toolbar = app.buttons["addPhotosButton"] XCTAssertGreaterThanOrEqual(photo.frame.minY, editor.frame.maxY) let composer = app.scrollViews["composerScrollView"] let remove = app.buttons["Remove image 1"] if !remove.isHittable { composer.swipeUp() } remove.tap() app.buttons["Remove image 1"].tap() XCTAssertEqual(editor.frame.height, heightWithImages, accuracy: 1) XCTAssertTrue(app.buttons["addPhotosButton"].isHittable) XCTAssertTrue(editor.value as? String == "A draft with photos") } func testReplyComposerScrollsWithImagesAndKeyboardOnIPad() throws { try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad") XCUIDevice.shared.orientation = .landscapeLeft defer { XCUIDevice.shared.orientation = .portrait } let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["replyButton"].firstMatch.tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) editor.tap() editor.typeText("A reply with photos") XCTAssertTrue(app.keyboards.firstMatch.waitForExistence(timeout: 5)) let photo = app.buttons["editAltText-0"] XCTAssertGreaterThanOrEqual(photo.frame.minY, editor.frame.maxY) let composer = app.scrollViews["composerScrollView"] composer.swipeUp() XCTAssertTrue(photo.isHittable) XCTAssertTrue(app.buttons["addPhotosButton"].isHittable) composer.swipeDown() XCTAssertTrue(editor.isHittable) XCTAssertEqual(editor.value as? String, "A reply with photos") } func testComposerSupportsTenPhotos() { let app = XCUIApplication() app.launchArguments = [ "-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images", "-ui-testing-compose-ten-images" ] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["New post"].tap() XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5)) XCTAssertEqual(app.buttons.matching(NSPredicate(format: "identifier BEGINSWITH %@", "editAltText-")).count, 10) XCTAssertFalse(app.buttons["addPhotosButton"].isEnabled) app.buttons["Remove image 1"].tap() XCTAssertTrue(app.buttons["addPhotosButton"].isEnabled) } func testComposerPostsVideoWithoutAltText() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-video"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.buttons["New post"].tap() XCTAssertTrue(app.buttons["Remove video"].waitForExistence(timeout: 5)) XCTAssertFalse(app.buttons["addPhotosButton"].isEnabled) XCTAssertFalse(app.buttons["editAltText-0"].exists) let post = app.buttons["publishButton"] XCTAssertTrue(post.isEnabled) post.tap() XCTAssertFalse(app.alerts["Add alt text?"].exists) XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 5)) } func testComposerShowsReplyAndQuoteText() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) let postText = app.buttons["postText-post-1"].label app.buttons["replyButton"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Reply"].waitForExistence(timeout: 5)) let context = app.staticTexts["composeContextText-post-1"] XCTAssertTrue(context.waitForExistence(timeout: 5)) XCTAssertFalse(context.label.isEmpty) let replyText = context.label XCTAssertTrue(postText.contains(replyText)) app.dismissComposer() app.buttons["quoteButton"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5)) XCTAssertTrue(context.waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-post-1").count, 1) XCTAssertEqual(context.label, replyText) } func testPostDetailQuoteDoesNotAddReplyContext() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-own-post"] app.launch() let ownID = "at://demo/app.bsky.feed.post/own123" let ownPost = app.buttons["postText-\(ownID)"].firstMatch XCTAssertTrue(ownPost.waitForExistence(timeout: 10)) ownPost.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) app.buttons["quoteButton"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-\(ownID)").count, 1) app.dismissComposer() app.buttons["replyButton"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Reply"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-\(ownID)").count, 1) app.dismissComposer() app.navigationBars["Post"].buttons.element(boundBy: 0).tap() let otherPost = app.buttons["postText-post-1"].firstMatch XCTAssertTrue(otherPost.waitForExistence(timeout: 5)) otherPost.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) app.buttons["quoteButton"].firstMatch.tap() XCTAssertTrue(app.navigationBars["Quote post"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts.matching(identifier: "composeContextText-post-1").count, 1) } func testPublishedPostShowsAccountAndSelectedImages() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-compose-images"] app.launch() XCTAssertTrue(app.buttons["postText-post-1"].waitForExistence(timeout: 10)) app.tabBars.buttons["New post"].tap() let editor = app.textViews["composeTextField"] XCTAssertTrue(editor.waitForExistence(timeout: 5)) editor.tap() editor.typeText("A new photo") app.buttons["publishButton"].tap() let withoutAlt = app.buttons["Post without alt text"] if withoutAlt.waitForExistence(timeout: 2) { withoutAlt.tap() } XCTAssertTrue(app.staticTexts["Demo Account"].firstMatch.waitForExistence(timeout: 5)) let image = app.buttons["postImageTile-1"].firstMatch XCTAssertTrue(image.waitForExistence(timeout: 5)) image.tap() XCTAssertTrue(app.buttons["imageViewerClose"].waitForExistence(timeout: 5)) } }