-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #195 from pietrocaselani/adding_kif_tests
Add a simple KIF test
- Loading branch information
Showing
20 changed files
with
840 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import CouchTrackerCore | ||
import CouchTrackerPersistence | ||
import Moya | ||
import TMDBSwift | ||
import TraktSwift | ||
import TVDBSwift | ||
|
||
public struct AppEnvironment { | ||
public var trakt: TraktProvider = Environment.instance.trakt | ||
public var tmdb: TMDBProvider = Environment.instance.tmdb | ||
public var tvdb: TVDBProvider = Environment.instance.tvdb | ||
public var schedulers: Schedulers = Environment.instance.schedulers | ||
public var realmProvider: RealmProvider = Environment.instance.realmProvider | ||
public var buildConfig: BuildConfig = Environment.instance.buildConfig | ||
public var appStateManager: AppStateManager = Environment.instance.appStateManager | ||
public var showsSynchronizer: WatchedShowsSynchronizer = Environment.instance.showsSynchronizer | ||
public var showSynchronizer: WatchedShowSynchronizer = Environment.instance.showSynchronizer | ||
public var watchedShowEntitiesObservable: WatchedShowEntitiesObservable = Environment.instance.watchedShowEntitiesObservable | ||
public var watchedShowEntityObserable: WatchedShowEntityObserable = Environment.instance.watchedShowEntityObserable | ||
public var userDefaults: UserDefaults = Environment.instance.userDefaults | ||
public var genreRepository: GenreRepository = Environment.instance.genreRepository | ||
public var imageRepository: ImageRepository = Environment.instance.imageRepository | ||
public var configurationRepository: ConfigurationCachedRepository = Environment.instance.configurationRepository | ||
public var movieImageRepository: MovieImageCachedRepository = Environment.instance.movieImageRepository | ||
public var showImageRepository: ShowImageCachedRepository = Environment.instance.showImageRepository | ||
public var episodeImageRepository: EpisodeImageCachedRepository = Environment.instance.episodeImageRepository | ||
public var syncStateObservable: SyncStateObservable = Environment.instance.syncStateObservable | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import CouchTrackerCore | ||
import CouchTrackerPersistence | ||
import Moya | ||
import TMDBSwift | ||
import TraktSwift | ||
import TVDBSwift | ||
|
||
@testable import CouchTrackerApp | ||
|
||
extension AppEnvironment {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// | ||
// CouchTrackerAppTestable.h | ||
// CouchTrackerAppTestable | ||
// | ||
// Created by Pietro Caselani on 17/05/19. | ||
// Copyright © 2019 Pietro Caselani. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
|
||
//! Project version number for CouchTrackerAppTestable. | ||
FOUNDATION_EXPORT double CouchTrackerAppTestableVersionNumber; | ||
|
||
//! Project version string for CouchTrackerAppTestable. | ||
FOUNDATION_EXPORT const unsigned char CouchTrackerAppTestableVersionString[]; | ||
|
||
// In this header, you should import all the public headers of your framework using statements like #import <CouchTrackerAppTestable/PublicHeader.h> | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>CFBundleDevelopmentRegion</key> | ||
<string>$(DEVELOPMENT_LANGUAGE)</string> | ||
<key>CFBundleExecutable</key> | ||
<string>$(EXECUTABLE_NAME)</string> | ||
<key>CFBundleIdentifier</key> | ||
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string> | ||
<key>CFBundleInfoDictionaryVersion</key> | ||
<string>6.0</string> | ||
<key>CFBundleName</key> | ||
<string>$(PRODUCT_NAME)</string> | ||
<key>CFBundlePackageType</key> | ||
<string>FMWK</string> | ||
<key>CFBundleShortVersionString</key> | ||
<string>0.0.1</string> | ||
<key>CFBundleVersion</key> | ||
<string>37</string> | ||
</dict> | ||
</plist> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
import Foundation | ||
import KIF | ||
import XCTest | ||
|
||
public extension XCTestCase { | ||
func tester(file: String = #file, _ line: Int = #line) -> KIFUITestActor { | ||
return KIFUITestActor(inFile: file, atLine: line, delegate: self) | ||
} | ||
|
||
func system(file: String = #file, _ line: Int = #line) -> KIFSystemTestActor { | ||
return KIFSystemTestActor(inFile: file, atLine: line, delegate: self) | ||
} | ||
} | ||
|
||
public extension KIFTestActor { | ||
func tester(file: String = #file, _ line: Int = #line) -> KIFUITestActor { | ||
return KIFUITestActor(inFile: file, atLine: line, delegate: self) | ||
} | ||
|
||
func system(file: String = #file, _ line: Int = #line) -> KIFSystemTestActor { | ||
return KIFSystemTestActor(inFile: file, atLine: line, delegate: self) | ||
} | ||
} | ||
|
||
extension UIView { | ||
var keyWindow: UIWindow? { return UIApplication.shared.keyWindow } | ||
|
||
public func isVisible() -> Bool { | ||
guard let rect = superview?.convert(frame, to: nil) else { return false } | ||
let isInWindow = keyWindow?.bounds.contains(rect) ?? false | ||
return isInWindow | ||
&& !isHidden | ||
&& alpha > 0 | ||
} | ||
} | ||
|
||
extension UITableView { | ||
public func scrollToTop() { | ||
setContentOffset(.zero, animated: false) | ||
} | ||
|
||
public func scrollToBottom() { | ||
setContentOffset(CGPoint(x: 0, y: contentSize.height), animated: false) | ||
} | ||
} | ||
|
||
extension KIFUITestActor { | ||
var keyWindow: UIWindow? { return UIApplication.shared.keyWindow } | ||
|
||
// MARK: - Instant matchers | ||
|
||
public func element(withAccessibilityHint hint: String) -> UIAccessibilityElement? { | ||
return keyWindow?.accessibilityElement { $0?.accessibilityHint == hint } | ||
} | ||
|
||
public func element(withAccessibilityIdentifier identifier: String) -> UIAccessibilityElement? { | ||
return keyWindow?.accessibilityElement { $0?.accessibilityIdentifier == identifier } | ||
} | ||
|
||
public func view(withAccessibilityHint hint: String) -> UIView? { | ||
return keyWindow?.view { $0?.accessibilityHint == hint } | ||
} | ||
|
||
public func view(withAccessibilityLabel label: String) -> UIView? { | ||
return keyWindow?.view { $0?.accessibilityLabel == label } | ||
} | ||
|
||
public func view(withAccessibilityIdentifier identifier: String) -> UIView? { | ||
return keyWindow?.view { $0?.accessibilityIdentifier == identifier } | ||
} | ||
|
||
// MARK: - Partial instant matchers | ||
|
||
public func element(withAccessibilityLabelThatContains label: String) -> UIAccessibilityElement? { | ||
return keyWindow?.accessibilityElement { $0?.accessibilityLabel?.contains(label) ?? false } | ||
} | ||
|
||
public func view(withAccessibilityLabelThatContains string: String) -> UIView? { | ||
return keyWindow?.view { $0?.accessibilityLabel?.contains(string) ?? false } | ||
} | ||
|
||
public func view(withAccessibilityHintThatContains string: String) -> UIView? { | ||
return keyWindow?.view { $0?.accessibilityHint?.contains(string) ?? false } | ||
} | ||
|
||
// MARK: - Partial tap matchers | ||
|
||
public func tapElement(withAccessibilityLabelThatContains string: String) { | ||
var element: UIAccessibilityElement? | ||
wait(for: &element, | ||
view: nil, | ||
withElementMatching: NSPredicate(format: "accessibilityLabel CONTAINS %@", string), | ||
tappable: true) | ||
|
||
if let e = element { | ||
tap(element: e) | ||
} else { | ||
XCTFail("Failed to find element that contains: \(string)") | ||
} | ||
} | ||
|
||
public func tapView(withAccessibilityIdentifier identifier: String) { | ||
var view: UIView? | ||
wait(for: nil, view: &view, withIdentifier: identifier, tappable: true) | ||
view?.tap() | ||
} | ||
|
||
public func tapNavigationBackButton() { | ||
tester().tapScreen(at: CGPoint(x: 15, y: 25)) | ||
} | ||
|
||
// MARK: - Swipe actions | ||
|
||
public func swipeView(withAccessibilityIdentifier identifier: String, inDirection direction: KIFSwipeDirection) { | ||
var view: UIView? | ||
var element: UIAccessibilityElement? | ||
|
||
wait(for: &element, view: &view, withIdentifier: identifier, tappable: true) | ||
swipeAccessibilityElement(element, in: view, in: direction) | ||
} | ||
|
||
// MARK: - TableView/Scroll actions | ||
|
||
public func firstTableView() -> UITableView? { | ||
return keyWindow?.view { $0 is UITableView } as! UITableView? | ||
} | ||
|
||
public func scroll(_ tableView: UITableView?, toIndexPath indexPath: IndexPath) { | ||
guard let tableView = tableView else { return XCTFail("A tableView was not provided.") } | ||
tableView.scrollToRow(at: indexPath, at: .middle, animated: false) | ||
} | ||
|
||
// MARK: - Condition waiters | ||
|
||
public func wait(for timeout: TimeInterval? = nil, untilTrue block: @escaping () -> Bool) { | ||
let waitBlock: KIFTestExecutionBlock = { _ in block() ? .success : .wait } | ||
if let t = timeout { | ||
run(waitBlock, timeout: t) | ||
} else { | ||
run(waitBlock) | ||
} | ||
} | ||
|
||
// MARK: - View waiters | ||
|
||
@discardableResult | ||
public func waitForView(withAccessibilityIdentifier identifier: String) -> UIView? { | ||
var view: UIView? | ||
wait(for: nil, | ||
view: &view, | ||
withElementMatching: NSPredicate(format: "accessibilityIdentifier == %@", identifier), | ||
tappable: false) | ||
|
||
return view | ||
} | ||
|
||
@discardableResult | ||
public func waitForView(withAccessibilityLabelThatContains label: String, tappable: Bool = true) -> UIView? { | ||
var view: UIView? | ||
wait(for: nil, | ||
view: &view, | ||
withElementMatching: NSPredicate(format: "accessibilityLabel CONTAINS %@", label), | ||
tappable: tappable) | ||
|
||
return view | ||
} | ||
|
||
public func waitForAbsenceOfView(withAccessibilityIdentifier identifier: String) { | ||
waitForAbsenceOfViewWithElement(matching: NSPredicate(format: "accessibilityIdentifer = %@", identifier)) | ||
} | ||
|
||
public func waitForAbsenceOfView(withAccessibilityHint hint: String) { | ||
waitForAbsenceOfViewWithElement(matching: NSPredicate(format: "accessibilityHint = %@", hint)) | ||
} | ||
} | ||
|
||
// MARK: - Private methods | ||
|
||
extension KIFUITestActor { | ||
func tap(element: NSObject) { | ||
if let view = element as? UIView { | ||
view.tap() | ||
} else { | ||
let center = CGPoint(x: element.accessibilityFrame.origin.x + element.accessibilityFrame.size.width / 2, | ||
y: element.accessibilityFrame.origin.y + element.accessibilityFrame.size.height / 2) | ||
tapScreen(at: center) | ||
} | ||
} | ||
} | ||
|
||
extension KIFUITestActor { | ||
public func speedUp() { keyWindow?.layer.speed = 1e2 } | ||
public func restoreSpeed() { keyWindow?.layer.speed = 1 } | ||
} | ||
|
||
extension UIWindow { | ||
public func view(matching matchBlock: @escaping ((UIView?) -> Bool)) -> UIView? { | ||
let element = accessibilityElement(matching: { (element) -> Bool in | ||
if let view = (element as Any?) as? UIView { | ||
return matchBlock(view) | ||
} | ||
return false | ||
}) | ||
|
||
return (element as Any?) as! UIView? | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.