Skip to content

Commit

Permalink
Merge pull request #10 from carousell/feature/ui-test
Browse files Browse the repository at this point in the history
UI Tests
  • Loading branch information
bcylin authored Jul 18, 2017
2 parents c37e53b + 385b02c commit c23be50
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

* Add a configuration for the photo albums navigation bar shadow color [#9](https://github.com/carousell/pickle/pull/9)
* Fix the photo albums layout after device rotation [#9](https://github.com/carousell/pickle/pull/9)
* UI tests [#10](https://github.com/carousell/pickle/pull/10)

## v1.0.0

Expand Down
79 changes: 76 additions & 3 deletions Example/UITests/UITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ class UITests: XCTestCase {

private lazy var app: XCUIApplication = XCUIApplication()

private var cancelButton: XCUIElement {
return app.navigationBars["Camera Roll"].buttons["Cancel"]
}

private var doneButton: XCUIElement {
return app.navigationBars["Camera Roll"].buttons["Done"]
}

// MARK: -

override func setUp() {
super.setUp()
continueAfterFailure = false
app.launch()
}

func testLaunch() {
app.tables.cells.staticTexts["Default appearance"].tap()
private func showImagePicker(named name: String) {
app.tables.cells.staticTexts[name].tap()

addUIInterruptionMonitor(withDescription: "Pickle Example") { alert -> Bool in
let button = alert.buttons["OK"]
Expand All @@ -34,7 +44,70 @@ class UITests: XCTestCase {

// need to interact with the app for the handler to fire
app.tap()
app.navigationBars["Camera Roll"].buttons["Cancel"].tap()
}

func testDefaultStates() {
showImagePicker(named: "Default appearance")
XCTAssertTrue(cancelButton.isEnabled)
XCTAssertFalse(doneButton.isEnabled)
cancelButton.tap()
}

func testImageSelections() {
showImagePicker(named: "Default appearance")

let collectionViewsQuery = app.collectionViews
let first = collectionViewsQuery.children(matching: .cell).element(boundBy: 0)
let second = collectionViewsQuery.children(matching: .cell).element(boundBy: 1)
let third = collectionViewsQuery.children(matching: .cell).element(boundBy: 2)
let forth = collectionViewsQuery.children(matching: .cell).element(boundBy: 3)
let fifth = collectionViewsQuery.children(matching: .cell).element(boundBy: 4)

// Select and deselect an image
first.tap()
XCTAssert(first.staticTexts["1"].exists)
XCTAssertTrue(doneButton.isEnabled)

first.tap()
XCTAssertFalse(first.staticTexts["1"].exists)
XCTAssertFalse(doneButton.isEnabled)

// Select images in sequence
second.tap()
XCTAssert(second.staticTexts["1"].exists)

third.tap()
XCTAssert(third.staticTexts["2"].exists)

forth.tap()
XCTAssert(forth.staticTexts["3"].exists)

// Reorder selections
third.tap()
XCTAssert(second.staticTexts["1"].exists)
XCTAssert(forth.staticTexts["2"].exists)

third.tap()
XCTAssert(third.staticTexts["3"].exists)

fifth.tap()
XCTAssert(fifth.staticTexts["4"].exists)

doneButton.tap()
}

func testSwitchingAlbums() {
showImagePicker(named: "Default appearance")

app.navigationBars["Camera Roll"].staticTexts["Camera Roll"].tap()
app.tables.cells.staticTexts["Favorites"].tap()
XCTAssert(app.collectionViews.cells.count == 0)

app.navigationBars["Favorites"].staticTexts["Favorites"].tap()
app.tables.cells.staticTexts["Camera Roll"].tap()
XCTAssert(app.collectionViews.cells.count == 5)

cancelButton.tap()
}

}

0 comments on commit c23be50

Please sign in to comment.