Files
sodalive-ios/work/tests/SubBannerGestureUITests.swift
T

170 lines
5.9 KiB
Swift

import XCTest
final class SubBannerGestureUITests: XCTestCase {
private var app: XCUIApplication!
private func launch(_ arguments: [String] = []) {
continueAfterFailure = false
app = XCUIApplication()
app.launchArguments = arguments
app.launchEnvironment["SB_TEST_NAME"] = name
app.launch()
XCTAssertTrue(app.staticTexts["tap-status"].waitForExistence(timeout: 5))
if !arguments.contains("empty") { XCTAssertTrue(page(1, total: arguments.contains("single") ? 1 : (arguments.contains("active") ? 2 : 3)).waitForExistence(timeout: 5)) }
}
private func page(_ index: Int, total: Int = 3) -> XCUIElement {
app.buttons["\(index) / \(total)"].firstMatch
}
private func status(_ count: Int, _ last: Int = 0) {
XCTAssertEqual(app.staticTexts["tap-status"].label, "taps=\(count);last=\(last)")
}
private func drag(_ index: Int, from: CGFloat = 0.8, to: CGFloat = 0.2, duration: TimeInterval = 0.05, total: Int = 3) {
let banner = page(index, total: total)
banner.coordinate(withNormalizedOffset: CGVector(dx: from, dy: 0.5))
.press(forDuration: duration, thenDragTo: banner.coordinate(withNormalizedOffset: CGVector(dx: to, dy: 0.5)))
}
func testSwipeDoesNotTap() {
launch()
drag(1)
XCTAssertTrue(page(2).exists)
status(0)
page(2).tap()
status(1, 2)
}
func testDirectionsWrapShortDragAndTap() {
launch()
page(1).tap()
status(1, 1)
drag(1, from: 0.2, to: 0.8)
XCTAssertTrue(page(3).exists)
status(1, 1)
page(3).tap()
status(2, 3)
drag(3)
XCTAssertTrue(page(1).exists)
status(2, 3)
drag(1, from: 0.5, to: 0.41)
XCTAssertTrue(page(1).exists)
status(2, 3)
drag(1, from: 0.5, to: 0.455)
status(2, 3)
page(1).tap()
status(3, 1)
XCTAssertEqual(app.buttons.matching(NSPredicate(format: "label == '1 / 3'")).count, 1)
}
func testVerticalParentScrollDoesNotTap() {
launch()
let before = app.staticTexts["Content row 3"].frame.minY
let banner = page(1)
let start = banner.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.9))
let end = banner.coordinate(withNormalizedOffset: CGVector(dx: 0.5, dy: 0.1))
start.press(forDuration: 0.05, thenDragTo: end)
status(0)
XCTAssertLessThan(app.staticTexts["Content row 3"].frame.minY, before - 30)
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.lifetime = .keepAlways
add(attachment)
}
func testSingleAndEmpty() {
launch(["single"])
page(1, total: 1).tap()
status(1, 1)
drag(1, total: 1)
status(1, 1)
app.terminate()
launch(["empty"])
XCTAssertEqual(app.buttons.matching(NSPredicate(format: "label CONTAINS ' / '")).count, 0)
XCTAssertLessThan(app.staticTexts["after-banner"].frame.minY, 200)
}
func testMixedRatiosAndReplacement() {
launch(["mixed"])
XCTAssertEqual(page(1).frame.height, page(1).frame.width / 2, accuracy: 2)
drag(1)
XCTAssertEqual(page(2).frame.height, page(2).frame.width / 3, accuracy: 2)
drag(2, from: 0.2, to: 0.8)
drag(1, from: 0.2, to: 0.8)
XCTAssertEqual(page(3).frame.height, page(3).frame.width / 2, accuracy: 2)
app.buttons["Replace"].tap()
XCTAssertTrue(page(1, total: 1).exists)
page(1, total: 1).tap()
status(1, 9)
}
func testManualBoundaryFrames() {
launch()
app.buttons["Record"].tap()
drag(1, from: 0.2, to: 0.8)
XCTAssertTrue(page(3).exists)
status(0)
let attachment = XCTAttachment(screenshot: app.screenshot())
attachment.lifetime = .keepAlways
add(attachment)
Thread.sleep(forTimeInterval: 1)
app.buttons["Forward"].tap()
drag(3)
XCTAssertTrue(page(1).exists)
status(0)
Thread.sleep(forTimeInterval: 1)
}
func testSwipeReleasePositionsAndRepeatedInput() {
launch()
drag(1, from: 0.9, to: 0.6, duration: 0.2)
XCTAssertTrue(page(2).waitForExistence(timeout: 2))
status(0)
drag(2, from: 0.7, to: 0.15, duration: 0)
drag(3, from: 0.6, to: 0.1, duration: 0.1)
XCTAssertTrue(page(1).exists)
status(0)
page(1).tap()
status(1, 1)
}
func testAutomaticFiveSecondWrapFrames() {
launch(["active"])
XCTAssertTrue(page(2, total: 2).waitForExistence(timeout: 7))
XCTAssertTrue(page(1, total: 2).waitForExistence(timeout: 7))
Thread.sleep(forTimeInterval: 2)
status(0)
page(1, total: 2).tap()
status(1, 1)
}
func testReplacementDuringAutomaticWrap() {
launch(["active", "replace-during-wrap"])
XCTAssertTrue(page(1, total: 1).waitForExistence(timeout: 13))
Thread.sleep(forTimeInterval: 0.5)
page(1, total: 1).tap()
status(1, 9)
}
func testDisappearanceDuringAutomaticWrap() {
launch(["active", "hide-during-wrap"])
XCTAssertTrue(page(2, total: 2).waitForExistence(timeout: 7))
let removed = expectation(for: NSPredicate(format: "count == 0"), evaluatedWith: app.buttons.matching(NSPredicate(format: "label CONTAINS ' / '")))
wait(for: [removed], timeout: 8)
Thread.sleep(forTimeInterval: 1)
status(0)
app.buttons["Show"].tap()
XCTAssertTrue(page(1, total: 2).waitForExistence(timeout: 2))
}
func testInactiveSceneCancelsAutomaticAdvance() {
launch(["active", "background"])
let label = app.buttons.matching(NSPredicate(format: "label CONTAINS ' / '")).firstMatch.label
XCUIDevice.shared.press(.home)
Thread.sleep(forTimeInterval: 6)
app.activate()
XCTAssertTrue(app.buttons[label].exists)
status(0)
}
}