#import #import #import "RNNStackPresenter.h" #import "UINavigationController+RNNOptions.h" #import "RNNStackController.h" #import "UIImage+Utils.h" @interface RNNStackPresenterTest : XCTestCase @property (nonatomic, strong) RNNStackPresenter *uut; @property (nonatomic, strong) RNNNavigationOptions *options; @property (nonatomic, strong) RNNStackController* boundViewController; @end @implementation RNNStackPresenterTest - (void)setUp { [super setUp]; self.uut = [[RNNStackPresenter alloc] init]; RNNStackController* stackController = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:self.uut eventEmitter:nil childViewControllers:@[[UIViewController new], [UIViewController new]]]; self.boundViewController = [OCMockObject partialMockForObject:stackController]; [self.uut bindViewController:self.boundViewController]; self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; } - (void)testApplyOptions_shouldSetBackButtonColor_withDefaultValues { [[(id)_boundViewController expect] setBackButtonColor:nil]; [self.uut applyOptions:self.options]; [(id)_boundViewController verify]; } - (void)testApplyOptions_shouldSetBackButtonColor_withColor { self.options.topBar.backButton.color = [[Color alloc] initWithValue:[UIColor redColor]]; [[(id)_boundViewController expect] setBackButtonColor:[UIColor redColor]]; [self.uut applyOptions:self.options]; [(id)_boundViewController verify]; } - (void)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewController { _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]]; [self.uut applyOptionsBeforePopping:self.options]; XCTAssertTrue([_boundViewController.navigationBar.standardAppearance.backgroundColor isEqual:[UIColor redColor]]); } - (void)testApplyOptionsBeforePoppingShouldSetLargeTitleForPoppingViewController { _options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES]; [self.uut applyOptionsBeforePopping:self.options]; XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]); } - (void)testApplyOptionsBeforePoppingShouldSetDefaultLargeTitleFalseForPoppingViewController { _options.topBar.largeTitle.visible = nil; [self.uut applyOptionsBeforePopping:self.options]; XCTAssertFalse([[_boundViewController navigationBar] prefersLargeTitles]); } - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle { Text* title = [[Text alloc] initWithValue:@"Title"]; self.options.topBar.backButton.title = title; [self.uut applyOptions:self.options]; XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqual:@"Title"]); } - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withHideTitle { Text* title = [[Text alloc] initWithValue:@"Title"]; self.options.topBar.backButton.title = title; self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)]; [self.uut applyOptions:self.options]; XCTAssertNil(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title); } - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues { [self.uut applyOptions:self.options]; XCTAssertTrue(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title == nil); } - (void)testSetBackButtonIcon_withColor_shouldSetColor { Color* color = [[Color alloc] initWithValue:UIColor.redColor]; self.options.topBar.backButton.color = color; [self.uut applyOptions:self.options]; XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor); } - (void)testSetBackButtonIcon_withColor_shouldSetTitle { Color* color = [[Color alloc] initWithValue:UIColor.redColor]; Text* title = [[Text alloc] initWithValue:@"Title"]; self.options.topBar.backButton.color = color; self.options.topBar.backButton.title = title; [self.uut applyOptions:self.options]; XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor); XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title, @"Title"); } - (void)testSetBackButtonIcon_withColor_shouldSetIcon { Color* color = [[Color alloc] initWithValue:UIColor.redColor]; UIImage *image = [UIImage emptyImage]; Image* icon = [[Image alloc] initWithValue:image]; self.options.topBar.backButton.color = color; self.options.topBar.backButton.icon = icon; [self.uut applyOptions:self.options]; XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor); XCTAssertTrue([self.boundViewController.navigationBar.standardAppearance.backIndicatorImage isEqual:image]); } @end