import XCTest extension OldFellaUITests { func testSearchAccountsPaginationAndPostMode() throws { try XCTSkipIf(UIDevice.current.userInterfaceIdiom == .pad, "Requires the iPhone tab layout") let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() let searchTab = app.tabBars.buttons["Search"] XCTAssertTrue(searchTab.waitForExistence(timeout: 10)) searchTab.tap() let field = app.searchFields.firstMatch XCTAssertTrue(field.waitForExistence(timeout: 5)) field.tap() field.typeText("example") XCTAssertTrue(app.buttons["searchAccount-mae"].waitForExistence(timeout: 5)) XCTAssertTrue( app.buttons["searchAccount-mae"].label.contains( "Writer, walker, and amateur cloud spotter. Sharing small things worth noticing.")) let more = app.buttons["loadMoreSearchButton"] XCTAssertTrue(more.waitForExistence(timeout: 5)) more.tap() XCTAssertTrue(app.buttons["searchAccount-alex"].waitForExistence(timeout: 5)) field.tap() field.typeText("\n") XCTAssertTrue(app.buttons["searchAccount-alex"].waitForExistence(timeout: 5)) more.tap() XCTAssertTrue(app.buttons["searchAccount-sam"].waitForExistence(timeout: 5)) XCTAssertTrue(app.staticTexts["End of results"].waitForExistence(timeout: 5)) XCTAssertFalse(more.exists) let screenshot = XCTAttachment(screenshot: app.screenshot()) screenshot.lifetime = .keepAlways add(screenshot) let filter = app.buttons["searchFilterMenu"] XCTAssertTrue(filter.waitForExistence(timeout: 5)) filter.tap() XCTAssertFalse(app.buttons["My posts"].exists) app.buttons["Posts"].tap() XCTAssertTrue(app.buttons["My posts"].waitForExistence(timeout: 5)) app.buttons["My posts"].tap() XCTAssertTrue(app.staticTexts["No results"].waitForExistence(timeout: 5)) XCTAssertFalse(app.buttons["searchAccount-mae"].exists) XCTAssertEqual(filter.label, "Filter search: My posts") filter.tap() app.buttons["All posts"].tap() XCTAssertEqual(filter.label, "Filter search: Posts") filter.tap() app.buttons["Accounts"].tap() XCTAssertFalse(app.buttons["My posts"].exists) app.coordinate(withNormalizedOffset: CGVector(dx: 0.1, dy: 0.7)).tap() XCTAssertTrue(app.buttons["searchAccount-mae"].waitForExistence(timeout: 5)) app.buttons["searchAccount-mae"].tap() XCTAssertTrue(app.staticTexts["profileDisplayName"].waitForExistence(timeout: 5)) XCTAssertEqual(app.staticTexts["profileDisplayName"].label, "Mae Rivers") } func testCustomFeedPickerSavesSelectionAcrossLaunches() { let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() XCTAssertTrue(app.buttons["feedPickerButton"].waitForExistence(timeout: 10)) app.buttons["feedPickerButton"].tap() XCTAssertTrue( app.buttons["feedChoice-at://did:plc:demo/app.bsky.feed.generator/nature"].waitForExistence(timeout: 5)) app.buttons["feedChoice-at://did:plc:demo/app.bsky.feed.generator/nature"].tap() XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 5)) app.terminate() app.launchArguments.append("-ui-testing-preserve-defaults") app.launch() XCTAssertTrue(app.navigationBars["Nature"].waitForExistence(timeout: 10)) XCTAssertTrue(app.tabBars.buttons["Timeline"].exists) XCTAssertEqual(app.buttons["feedPickerButton"].value as? String, "Nature") app.buttons["feedPickerButton"].tap() XCTAssertTrue(app.buttons["feedChoice-following"].waitForExistence(timeout: 5)) app.buttons["feedChoice-following"].tap() XCTAssertTrue(app.navigationBars["Following"].waitForExistence(timeout: 5)) } func testIPadPortraitLayoutAndComposeMatchDeviceSize() throws { try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "Requires iPad") XCUIDevice.shared.orientation = .portrait defer { XCUIDevice.shared.orientation = .portrait } let app = XCUIApplication() app.launchArguments = ["-ui-testing", "-ui-testing-signed-in"] app.launch() let isMini = app.frame.width < 768 if isMini { XCTAssertTrue(app.buttons["feedPickerButton"].waitForExistence(timeout: 10)) XCTAssertFalse(app.buttons["addFeedColumnButton"].exists) let compose = app.buttons["floatingComposeButton"] XCTAssertTrue(compose.waitForExistence(timeout: 5)) XCTAssertFalse(app.tabBars.buttons["New post"].exists) XCTAssertGreaterThan(compose.frame.midX, app.frame.midX) XCTAssertGreaterThan(compose.frame.midY, app.frame.midY) compose.tap() XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5)) app.buttons["Cancel"].tap() app.buttons.matching(identifier: "Notifications").firstMatch.tap() XCTAssertTrue(app.navigationBars["Notifications"].waitForExistence(timeout: 5)) XCTAssertFalse(app.navigationBars["Following"].exists) XCTAssertTrue(compose.exists) } else { openPadActions(app) XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10)) XCTAssertTrue(app.navigationBars["Following"].exists) XCTAssertTrue(app.navigationBars["Notifications"].exists) app.buttons["New post"].tap() XCTAssertTrue(app.textViews["composeTextField"].waitForExistence(timeout: 5)) app.buttons["Cancel"].tap() } let portrait = XCTAttachment(screenshot: app.screenshot()) portrait.name = "iPad portrait layout" portrait.lifetime = .keepAlways add(portrait) XCUIDevice.shared.orientation = .landscapeLeft openPadActions(app) XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10)) XCTAssertTrue(app.navigationBars["Following"].exists) XCTAssertTrue(app.navigationBars["Notifications"].exists) XCUIDevice.shared.orientation = .portrait if isMini { XCTAssertTrue(app.buttons["floatingComposeButton"].waitForExistence(timeout: 10)) XCTAssertFalse(app.buttons["addFeedColumnButton"].exists) } else { openPadActions(app) XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10)) XCTAssertTrue(app.navigationBars["Notifications"].exists) } } func testIPadColumnCountSettingPersists() 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"] app.launch() openPadActions(app) XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10)) XCTAssertFalse(app.buttons["showLeftColumnButton"].exists) XCTAssertFalse(app.buttons["showRightColumnButton"].exists) app.buttons["Settings"].tap() let picker = app.segmentedControls["padVisibleColumnCount"] XCTAssertTrue(picker.waitForExistence(timeout: 5)) XCTAssertTrue(picker.buttons["2"].isSelected) picker.buttons["3"].tap() XCTAssertTrue(picker.buttons["3"].isSelected) picker.buttons["4"].tap() XCTAssertTrue(picker.buttons["4"].isSelected) app.buttons["Done"].tap() XCTAssertFalse(app.buttons["showLeftColumnButton"].exists) XCTAssertFalse(app.buttons["showRightColumnButton"].exists) app.terminate() app.launchArguments.append("-ui-testing-preserve-defaults") app.launch() openPadActions(app) XCTAssertTrue(app.buttons["Settings"].waitForExistence(timeout: 10)) app.buttons["Settings"].tap() XCTAssertTrue(picker.waitForExistence(timeout: 5)) XCTAssertTrue(picker.buttons["4"].isSelected) } func testIPadFeedColumnsPersistAndClose() 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"] app.launch() openPadActions(app) let feedID = "at://did:plc:demo/app.bsky.feed.generator/nature" XCTAssertTrue(app.buttons["addFeedColumnButton"].waitForExistence(timeout: 10)) app.buttons["addFeedColumnButton"].tap() XCTAssertTrue(app.buttons["feedChoice-\(feedID)"].waitForExistence(timeout: 5)) app.buttons["feedChoice-\(feedID)"].tap() let move = app.images["moveColumn-\(feedID)"] XCTAssertTrue(move.waitForExistence(timeout: 5)) XCTAssertGreaterThanOrEqual(move.frame.minX, 0) XCTAssertLessThan(move.frame.maxX, app.frame.maxX, "Adding a feed must scroll its handle into view") XCTAssertLessThan(app.buttons["closeColumn-\(feedID)"].frame.maxX, app.frame.maxX) XCTAssertLessThan(move.frame.minX, app.buttons["closeColumn-\(feedID)"].frame.minX) XCTAssertTrue(app.buttons["showLeftColumnButton"].waitForExistence(timeout: 5)) XCTAssertFalse(app.buttons["showRightColumnButton"].exists) app.buttons["showLeftColumnButton"].tap() XCTAssertTrue(app.buttons["showRightColumnButton"].waitForExistence(timeout: 5)) XCTAssertFalse(app.buttons["showLeftColumnButton"].exists) app.buttons["showRightColumnButton"].tap() XCTAssertTrue(app.buttons["showLeftColumnButton"].waitForExistence(timeout: 5)) let destination = move.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) .withOffset(CGVector(dx: -(app.frame.width - 12) / 2, dy: 0)) move.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.5)) .press(forDuration: 0.1, thenDragTo: destination) XCTAssertFalse(app.buttons["closeColumn-following"].exists) XCTAssertFalse(app.buttons["closeColumn-notifications"].exists) app.terminate() app.launchArguments.append("-ui-testing-preserve-defaults") app.launch() let close = app.buttons["closeColumn-\(feedID)"] XCTAssertTrue(close.waitForExistence(timeout: 10)) let following = app.images["moveColumn-following"] let nature = app.images["moveColumn-\(feedID)"] let notifications = app.images["moveColumn-notifications"] XCTAssertGreaterThanOrEqual(following.frame.minX, 0, "Restoring columns must not scroll to a custom feed") XCTAssertLessThan(following.frame.minX, nature.frame.minX) XCTAssertLessThan(nature.frame.minX, notifications.frame.minX) close.tap() XCTAssertFalse(close.exists) app.terminate() app.launch() XCTAssertTrue(app.buttons["togglePadActionsButton"].waitForExistence(timeout: 10)) XCTAssertFalse(app.buttons["closeColumn-\(feedID)"].exists) } }