123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #import <XCTest/XCTest.h>
- #import <OCMock/OCMock.h>
- #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]);
- }
-
- - (void)testBackgroundColor_validColor {
- UIColor* inputColor = [RCTConvert UIColor:@(0xFFFF0000)];
- self.options.layout.backgroundColor = [[Color alloc] initWithValue:inputColor];
- [self.uut applyOptions:self.options];
- UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
- XCTAssertTrue([self.boundViewController.view.backgroundColor isEqual:expectedColor]);
- }
-
- @end
|