//
// AppUnit.m
// Project
//
// Created by 杨殷杭 on 17/3/12.
//
//

#import "AppUnit.h"
#if DEBUG
 #import "CocoaUtils.h"
 #import "DrawUtils.h"
 #import "RandomUtils.h"
 #import <BlocksKit/BlocksKit+UIKit.h>
 #import <LoremIpsum/LoremIpsum.h>
 #import <OHHTTPStubs/OHHTTPStubs.h>
 #import <PureLayout/PureLayout.h>
 #import "Utility.h"
 #import "AppUnitSubclass.h"
 #import "Vars.h"
#endif

@implementation AppUnit

#if DEBUG

+ (UITabBarController *)wrappingTabBarControllerOnNavigationPushingViewController:(UIViewController *)viewController atTop:(BOOL)atTop {
	UITabBarController *tabbarController = [UITabBarController new];
	viewController.tabBarItem.image = [DrawUtils imageWithFAKIcon:[RandomUtils nextIcon:24] fillColor:[UIColor blackColor]];
	viewController.tabBarItem.title = [LoremIpsum word];
	tabbarController.viewControllers = @[[self wrappingNavigationControllerPushingViewController:viewController atTop:atTop]];
	return tabbarController;
}

+ (UINavigationController *)wrappingNavigationControllerPushingViewController:(UIViewController *)viewController atTop:(BOOL)atTop {
	UIViewController *vc = nil;
	if (atTop) {
		vc = viewController;
	} else {
		vc = [UIViewController new];
		// vc add button bk_blcok
		UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
		[button setTitle:NSStringFromClass(viewController.class) forState:UIControlStateNormal];
		[button bk_addEventHandler:^(id sender) {
			[vc.navigationController pushViewController:viewController animated:YES];
		} forControlEvents:UIControlEventTouchUpInside];
		[vc.view addSubview:button];
		[button autoCenterInSuperview];
	}
	return [CocoaUtils wrappingNavigationControllerAroundViewController:vc];
}

+ (void)stubRequest {
	[OHHTTPStubs stubRequestsPassingTest:^BOOL (NSURLRequest *request) {
		NSLog(@"%@", request);
		return NO;
	} withStubResponse:^OHHTTPStubsResponse * (NSURLRequest *request) {
		return nil;
	}];
}

#endif

@end
