@@ -28,11 +28,11 @@ final class FetchedResultsViewsUITests: XCTestCase {
2828 let app = XCUIApplication ( )
2929
3030 let getCollectionView = {
31- XCUIApplication ( ) . collectionViews. matching ( identifier : Identifiers . fetchedResultsCollectionView. rawValue) . firstMatch
31+ XCUIApplication ( ) . collectionViews [ Identifiers . fetchedResultsCollectionView. rawValue]
3232 }
3333
3434 let getTableView = {
35- XCUIApplication ( ) . tables. matching ( identifier : Identifiers . fetchedResultsTableView. rawValue) . firstMatch
35+ XCUIApplication ( ) . tables [ Identifiers . fetchedResultsTableView. rawValue]
3636 }
3737
3838 let getDeleteButton = {
@@ -148,34 +148,36 @@ final class FetchedResultsViewsUITests: XCTestCase {
148148 func test_ThatActionButton_AddNewOption_AddsCell( ) {
149149 fetchedResultsCollectionViewMenuItem. tap ( )
150150
151- // GIVEN: initial number of cells in the collection
151+ // GIVEN: initial empty collection
152152 let collection = getCollectionView ( )
153- let numberOfCellsBeforeInCollection = countElements ( ofType: . cell, inView: collection) { $0. identifier }
154153
155154 // WHEN: "Add new" option is tapped
156155 getShareButton ( ) . tap ( )
157156 app. sheets [ " You must select items first " ] . buttons [ " Add new " ] . tap ( )
158157
159- // THEN: a new cell appears in the collection view
160- let numberOfCellsAfterInCollection = countElements ( ofType: . cell, inView: collection) { $0. identifier }
161- XCTAssertEqual ( numberOfCellsAfterInCollection,
162- numberOfCellsBeforeInCollection + 1 ,
163- " \" Add new \" should add one new cell " )
158+ let result1 = waitToAppearFor ( element: collection. cells. element ( boundBy: 0 ) )
159+ XCTAssertEqual ( result1, . completed)
160+
161+ // THEN: one new cell appears in the collection view
162+ let numberOfCellsInCollection = countElements ( ofType: . cell, inView: collection) { $0. identifier }
163+ XCTAssertEqual ( numberOfCellsInCollection, 1 , " \" Add new \" should add one new cell " )
164164
165165 navigateBack ( )
166+ getDeleteButton ( ) . tap ( )
166167 fetchedResultsTableViewMenuItem. tap ( )
167168
168- // GIVEN: initial number of cells in the table view
169+ // GIVEN: initial empty table
169170 let table = getTableView ( )
170- let numberOfCellsBeforeInTable = countElements ( ofType: . cell, inView: table) { $0. identifier }
171171
172172 // WHEN: "Add new" option is tapped
173173 getShareButton ( ) . tap ( )
174174 app. sheets [ " You must select items first " ] . buttons [ " Add new " ] . tap ( )
175+ let result2 = waitToAppearFor ( element: table. cells. element ( boundBy: 0 ) )
176+ XCTAssertEqual ( result2, . completed)
175177
176- // THEN: a new cell appears in the table view
177- let numberOfCellsAfterInTable = countElements ( ofType: . cell, inView: table) { $0. identifier }
178- XCTAssertEqual ( numberOfCellsAfterInTable , numberOfCellsBeforeInTable + 1 , " \" Add new \" should add one new cell " )
178+ // THEN: one new cell appears in the table view
179+ let numberOfCellsInTable = countElements ( ofType: . cell, inView: table) { $0. identifier }
180+ XCTAssertEqual ( numberOfCellsInTable , 1 , " \" Add new \" should add one new cell " )
179181 }
180182
181183 func test_ThatActionButton_DeleteSelectedOption_RemovesSelectedCells( ) {
0 commit comments