Add PromiseKit dependency
- Added PromiseKit dependency
This commit is contained in:
34
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIImagePickerController.swift
vendored
Normal file
34
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIImagePickerController.swift
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
import PromiseKit
|
||||
import PMKUIKit
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
#if os(iOS)
|
||||
|
||||
class Test_UIImagePickerController_Swift: XCTestCase {
|
||||
func test() {
|
||||
class Mock: UIViewController {
|
||||
var info = [String:AnyObject]()
|
||||
|
||||
override func present(_ vc: UIViewController, animated flag: Bool, completion: (() -> Void)?) {
|
||||
let ipc = vc as! UIImagePickerController
|
||||
after(seconds: 0.05).done {
|
||||
ipc.delegate?.imagePickerController?(ipc, didFinishPickingMediaWithInfo: self.info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let (originalImage, editedImage) = (UIImage(), UIImage())
|
||||
|
||||
let mockvc = Mock()
|
||||
mockvc.info = [UIImagePickerControllerOriginalImage: originalImage, UIImagePickerControllerEditedImage: editedImage]
|
||||
|
||||
let ex = expectation(description: "")
|
||||
mockvc.promise(UIImagePickerController(), animate: []).done { _ in
|
||||
ex.fulfill()
|
||||
}
|
||||
waitForExpectations(timeout: 10, handler: nil)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
19
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIView.swift
vendored
Normal file
19
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIView.swift
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
import PromiseKit
|
||||
import PMKUIKit
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
class UIViewTests: XCTestCase {
|
||||
func test() {
|
||||
let ex1 = expectation(description: "")
|
||||
let ex2 = expectation(description: "")
|
||||
|
||||
UIView.animate(.promise, duration: 0.1) {
|
||||
ex1.fulfill()
|
||||
}.done { _ in
|
||||
ex2.fulfill()
|
||||
}
|
||||
|
||||
waitForExpectations(timeout: 1)
|
||||
}
|
||||
}
|
||||
135
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIViewController.m
vendored
Normal file
135
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/TestUIViewController.m
vendored
Normal file
@@ -0,0 +1,135 @@
|
||||
@import PromiseKit;
|
||||
@import PMKUIKit;
|
||||
@import XCTest;
|
||||
@import UIKit;
|
||||
|
||||
|
||||
@interface MyViewController: UIViewController
|
||||
@property AnyPromise *promise;
|
||||
@end
|
||||
@implementation MyViewController
|
||||
@end
|
||||
|
||||
|
||||
@implementation UIViewControllerTests: XCTestCase {
|
||||
UIViewController *rootvc;
|
||||
}
|
||||
|
||||
- (void)setUp {
|
||||
rootvc = [UIApplication sharedApplication].keyWindow.rootViewController = [UIViewController new];
|
||||
}
|
||||
|
||||
- (void)tearDown {
|
||||
[UIApplication sharedApplication].keyWindow.rootViewController = nil;
|
||||
}
|
||||
|
||||
// view controller is presented and dismissed when promise is resolved
|
||||
- (void)test1 {
|
||||
XCTestExpectation *ex = [self expectationWithDescription:@""];
|
||||
|
||||
PMKResolver resolve;
|
||||
|
||||
MyViewController *myvc = [MyViewController new];
|
||||
myvc.promise = [[AnyPromise alloc] initWithResolver:&resolve];
|
||||
[rootvc promiseViewController:myvc animated:NO completion:nil].then(^{
|
||||
// seems to take another tick for the dismissal to complete
|
||||
}).then(^{
|
||||
[ex fulfill];
|
||||
});
|
||||
|
||||
XCTAssertNotNil(rootvc.presentedViewController);
|
||||
|
||||
PMKAfter(1).then(^{
|
||||
resolve(@1);
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
// view controller is not presented if promise is resolved
|
||||
- (void)test2 {
|
||||
MyViewController *myvc = [MyViewController new];
|
||||
myvc.promise = [AnyPromise promiseWithValue:nil];
|
||||
[rootvc promiseViewController:myvc animated:NO completion:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
// promise property must be promise
|
||||
- (void)test3 {
|
||||
XCTestExpectation *ex = [self expectationWithDescription:@""];
|
||||
|
||||
MyViewController *myvc = [MyViewController new];
|
||||
myvc.promise = (id) @1;
|
||||
[rootvc promiseViewController:myvc animated:NO completion:nil].catch(^(id err){
|
||||
[ex fulfill];
|
||||
});
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
// promise property must not be nil
|
||||
- (void)test4 {
|
||||
XCTestExpectation *ex = [self expectationWithDescription:@""];
|
||||
|
||||
MyViewController *myvc = [MyViewController new];
|
||||
[rootvc promiseViewController:myvc animated:NO completion:nil].catch(^(id err){
|
||||
[ex fulfill];
|
||||
});
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
// view controller must have a promise property
|
||||
- (void)test5 {
|
||||
XCTestExpectation *ex = [self expectationWithDescription:@""];
|
||||
|
||||
UIViewController *vc = [UIViewController new];
|
||||
[rootvc promiseViewController:vc animated:NO completion:nil].catch(^(id err){
|
||||
[ex fulfill];
|
||||
});
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
// promised nav controllers use their root vc’s promise property
|
||||
- (void)test6 {
|
||||
XCTestExpectation *ex = [self expectationWithDescription:@""];
|
||||
|
||||
PMKResolver resolve;
|
||||
|
||||
MyViewController *myvc = [MyViewController new];
|
||||
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:myvc];
|
||||
myvc.promise = [[AnyPromise alloc] initWithResolver:&resolve];
|
||||
[rootvc promiseViewController:nc animated:NO completion:nil].then(^(id obj){
|
||||
XCTAssertEqualObjects(@1, obj);
|
||||
}).then(^{
|
||||
[ex fulfill];
|
||||
});
|
||||
|
||||
XCTAssertNotNil(rootvc.presentedViewController);
|
||||
|
||||
PMKAfter(1).then(^{
|
||||
resolve(@1);
|
||||
});
|
||||
|
||||
[self waitForExpectationsWithTimeout:10 handler:nil];
|
||||
|
||||
XCTAssertNil(rootvc.presentedViewController);
|
||||
}
|
||||
|
||||
@end
|
||||
16
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/infrastructure.swift
vendored
Normal file
16
Carthage/Checkouts/PromiseKit/Extensions/UIKit/Tests/infrastructure.swift
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
import XCTest
|
||||
import UIKit
|
||||
|
||||
extension XCTestCase {
|
||||
var rootvc: UIViewController {
|
||||
return UIApplication.shared.keyWindow!.rootViewController!
|
||||
}
|
||||
|
||||
override open func setUp() {
|
||||
UIApplication.shared.keyWindow!.rootViewController = UIViewController()
|
||||
}
|
||||
|
||||
override open func tearDown() {
|
||||
UIApplication.shared.keyWindow!.rootViewController = nil
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user