import XCTest extension OldFellaUITests { func testProfileLinksShowTitlesAndOpenPostsInsideApp() { 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() let photos = app.descendants(matching: .any)["profileLink-photos"].firstMatch XCTAssertTrue(photos.waitForExistence(timeout: 5)) XCTAssertTrue(photos.label.contains("My Photos!")) let github = app.descendants(matching: .any)["profileLink-github"].firstMatch XCTAssertTrue(github.exists) XCTAssertTrue(github.label.contains("GitHub")) let screenshot = XCTAttachment(screenshot: app.screenshot()) screenshot.lifetime = .keepAlways add(screenshot) XCTAssertEqual(photos.frame.midY, github.frame.midY, accuracy: 2) XCTAssertLessThan(photos.frame.maxX, github.frame.minX) let website = app.descendants(matching: .any)["profileWebsiteLink"].firstMatch XCTAssertTrue(website.exists) XCTAssertGreaterThan(website.frame.minY, photos.frame.maxY) let post = app.descendants(matching: .any)["profileLink-post"].firstMatch post.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) } func testOwnProfileOpens() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in", "-ui-testing-info-label"] app.launch() app.openOwnProfile() XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Demo Account") let photos = app.descendants(matching: .any)["profileLink-photos"].firstMatch XCTAssertTrue(photos.waitForExistence(timeout: 5)) XCTAssertTrue(photos.label.contains("My Photos!")) let github = app.descendants(matching: .any)["profileLink-github"].firstMatch XCTAssertTrue(github.exists) XCTAssertEqual(photos.frame.midY, github.frame.midY, accuracy: 2) let counts = app.descendants(matching: .any)["profileCounts"].firstMatch XCTAssertTrue(counts.exists) XCTAssertLessThan(photos.frame.maxY, counts.frame.minY) XCTAssertFalse(app.descendants(matching: .any)["profileLink-hidden"].firstMatch.exists) let screenshot = XCTAttachment(screenshot: app.screenshot()) screenshot.lifetime = .keepAlways add(screenshot) } 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() let headerControl = app.buttons[UIDevice.current.userInterfaceIdiom == .pad ? "yourProfileButton" : "feedPickerButton"] XCTAssertTrue(headerControl.waitForExistence(timeout: 5)) app.swipeUp() app.swipeUp() XCTAssertTrue(headerControl.isHittable) } func testGIFSettingControlsPostAndQuotedGIFs() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-gif"] app.launch() app.buttons["demoSignInButton"].tap() XCTAssertTrue(app.descendants(matching: .any)["inlineGIF"].firstMatch.waitForExistence(timeout: 5)) let gif = app.buttons["A moving square."].firstMatch XCTAssertTrue(gif.waitForExistence(timeout: 5)) app.swipeUp() gif.tap() XCTAssertTrue(app.buttons["imageViewerClose"].waitForExistence(timeout: 5)) app.buttons["imageDescriptionButton"].tap() XCTAssertTrue(app.staticTexts["A moving square."].waitForExistence(timeout: 5)) app.buttons["imageViewerClose"].tap() XCTAssertEqual(app.buttons.matching(identifier: "showGIFButton").count, 0) let quote = app.cells.containing(.button, identifier: "postText-post-1").firstMatch XCTAssertTrue(quote.buttons["showReplyGIFButton"].firstMatch.waitForExistence(timeout: 5)) XCTAssertFalse(app.descendants(matching: .any)["replyPostContext-post-1"].exists) app.openSettings() let setting = app.switches["showGIFsInline"] XCTAssertTrue(setting.waitForExistence(timeout: 5)) setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() XCTAssertEqual(String(describing: setting.value ?? ""), "0") app.closeSettings() let buttons = app.buttons.matching(identifier: "showGIFButton") XCTAssertTrue(app.buttons["showReplyGIFButton"].firstMatch.waitForExistence(timeout: 5)) XCTAssertTrue(buttons.firstMatch.waitForExistence(timeout: 5)) buttons.firstMatch.tap() XCTAssertTrue(app.buttons["A moving square."].firstMatch.waitForExistence(timeout: 5)) XCTAssertFalse(quote.buttons["showGIFButton"].exists) } func testQuotedGIFNeedsOnlyOneRevealWhenSettingIsOff() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-gif", "-ui-testing-signed-in"] app.launch() app.openSettings() let setting = app.switches["showGIFsInline"] XCTAssertTrue(setting.waitForExistence(timeout: 5)) setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() XCTAssertEqual(String(describing: setting.value ?? ""), "0") app.closeSettings() let post = app.cells.containing(.button, identifier: "postText-post-1").firstMatch let reveal = post.buttons["showReplyGIFButton"].firstMatch XCTAssertTrue(reveal.waitForExistence(timeout: 5)) reveal.tap() XCTAssertTrue(post.buttons["GIF"].firstMatch.waitForExistence(timeout: 5)) XCTAssertFalse(post.buttons["showReplyGIFButton"].exists) XCTAssertTrue(post.buttons["showGIFButton"].exists) } func testDirectReplyGIFFollowsSetting() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-gif", "-ui-testing-signed-in"] app.launch() let reply = app.cells.containing(.button, identifier: "postText-post-2").firstMatch for _ in 0..<5 { if reply.exists { break } app.swipeUp() } XCTAssertTrue(reply.waitForExistence(timeout: 5)) XCTAssertTrue(reply.descendants(matching: .any)["inlineGIF"].firstMatch.waitForExistence(timeout: 5)) XCTAssertFalse(reply.buttons["showGIFButton"].exists) app.openSettings() let setting = app.switches["showGIFsInline"] XCTAssertTrue(setting.waitForExistence(timeout: 5)) setting.coordinate(withNormalizedOffset: CGVector(dx: 0.95, dy: 0.5)).tap() XCTAssertEqual(String(describing: setting.value ?? ""), "0") app.closeSettings() for _ in 0..<5 { if reply.buttons["showGIFButton"].exists { break } app.swipeUp() } XCTAssertTrue(reply.buttons["showGIFButton"].firstMatch.waitForExistence(timeout: 5)) } func testVideoViewerUsesNativeDismissal() throws { try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone player layout") let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-video"] app.launchArguments.append("-ui-testing-signed-in") app.launch() let video = app.buttons["Tap here to play the video"].firstMatch XCTAssertTrue(video.waitForExistence(timeout: 5)) for _ in 0..<2 { video.tap() let failure = app.alerts["Video could not be played"] XCTAssertTrue(failure.waitForExistence(timeout: 10)) failure.buttons["OK"].tap() app.coordinate(withNormalizedOffset: CGVector(dx: 0.11, dy: 0.096)).tap() XCTAssertTrue(video.waitForExistence(timeout: 5)) XCTAssertTrue(video.isHittable) } } func testPostTimestampIsRelativeInFeedAndDetail() { let app = XCUIApplication() app.launchArguments = ["-ui-testing"] app.launchArguments.append("-ui-testing-signed-in") app.launch() let timestamp = app.staticTexts["postTimestamp-post-1"] XCTAssertTrue(timestamp.waitForExistence(timeout: 5)) XCTAssertLessThanOrEqual(timestamp.label.count, 4) let author = app.buttons["profileLink-mae"].firstMatch XCTAssertTrue(author.waitForExistence(timeout: 5)) XCTAssertEqual(timestamp.frame.midY, author.frame.midY, accuracy: 2) app.buttons["postText-post-1"].tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) let detailTimestamp = app.staticTexts["postTimestamp-post-1"].firstMatch XCTAssertTrue(detailTimestamp.waitForExistence(timeout: 5)) XCTAssertLessThanOrEqual(detailTimestamp.label.count, 4) app.navigationBars.buttons["Following"].tap() app.openSettings() XCTAssertFalse(app.buttons["postTimestampSetting"].exists) } func testQuoteShowsOriginalAndOpensPost() { let app = XCUIApplication() app.launchArguments = ["-ui-testing"] app.launchArguments.append("-ui-testing-signed-in") app.launch() let quote = app.buttons["quotedPostLink"] for _ in 0..<5 { if quote.exists && quote.isHittable { break } app.swipeUp() } XCTAssertTrue(quote.exists) XCTAssertTrue(quote.label.contains("Quoted Alex Kim")) XCTAssertFalse(quote.label.contains("@alex.example")) quote.tap() XCTAssertTrue(app.navigationBars["Post"].waitForExistence(timeout: 5)) } }