This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func startInteractiveTransition(for state: State) { | |
| state = newState | |
| runningAnimators = createTransitionAnimators(with: TransitionCoordinator.animationDuration) | |
| runningAnimators.pauseAnimations() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @objc private func didPanPlayer(recognizer: UIPanGestureRecognizer) { | |
| switch recognizer.state { | |
| case .began: | |
| startInteractiveTransition(for: !state) // ➊ | |
| case .changed: | |
| let translation = recognizer.translation(in: recognizer.view!) | |
| updateInteractiveTransition(distanceTraveled: translation.y) // ➋ | |
| case .ended: | |
| let velocity = recognizer.velocity(in: recognizer.view!).y | |
| let isCancelled = isGestureCancelled(with: velocity) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class TransitionCoordinator { | |
| enum State: Equatable { | |
| case open | |
| case closed | |
| static prefix func !(_ state: State) -> State { | |
| return state == .open ? .closed : .open | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func test_intialState() { | |
| // GIVEN /WHEN | |
| open(viewController: factory.moviesSearchController(navigator: moviesSearchNavigator)) | |
| // THEN | |
| Page.on(MoviesSearchPage.self) | |
| .assertScreenTitle("Movies") | |
| .assertContentIsHidden() | |
| .on(AlertPage.self) | |
| .assertTitle("Search for a movie...") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func test_startMoviesSearch_whenTypeSearchText() { | |
| // GIVEN | |
| let movies = Movies.loadFromFile("Movies.json") | |
| networkService.responses["/3/search/movie"] = movies | |
| open(viewController: factory.moviesSearchController(navigator: moviesSearchNavigator)) | |
| // WHEN | |
| Page.on(MoviesSearchPage.self).search("joker") | |
| // THEN |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class MoviesSearchPage: Page { | |
| override func verify() { | |
| EarlGrey.selectElement(with: grey_accessibilityID(AccessibilityIdentifiers.MoviesSearch.rootViewId)).assert(grey_notNil()) | |
| } | |
| } | |
| // MARK: Actions | |
| extension MoviesSearchPage { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Page { | |
| static func on<T: Page>(_ type: T.Type) -> T { | |
| let pageObject = T() | |
| pageObject.verify() | |
| return pageObject | |
| } | |
| func verify() { | |
| fatalError("Override \(#function) function in a subclass!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private func createTableViewRowsAssert(rowsCount: Int, inSection section: Int) -> GREYAssertion { | |
| return GREYAssertionBlock(name: "TableViewRowsAssert") { (element, error) -> Bool in | |
| guard let tableView = element as? UITableView, tableView.numberOfSections > section else { | |
| return false | |
| } | |
| return rowsCount == tableView.numberOfRows(inSection: section) | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func test_startMoviesSearch_whenTypeSearchText() { | |
| // GIVEN | |
| let movies = Movies.loadFromFile("Movies.json") | |
| networkService.responses["/3/search/movie"] = movies | |
| open(viewController: factory.moviesSearchController(navigator: moviesSearchNavigator)) | |
| // WHEN | |
| EarlGrey | |
| .selectElement(with: grey_accessibilityID(AccessibilityIdentifiers.MoviesSearch.searchTextFieldId)) | |
| .perform(grey_typeText("joker")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| override func setUp() { | |
| GREYConfiguration.sharedInstance().setValue(false, forConfigKey: kGREYConfigKeyAnalyticsEnabled) ➊ | |
| GREYConfiguration.sharedInstance().setValue(5.0, forConfigKey: kGREYConfigKeyInteractionTimeoutDuration) ➋ | |
| GREYTestHelper.enableFastAnimation() ➌ | |
| } |