123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- #import <XCTest/XCTest.h>
- #import "RNNTabBarController.h"
- #import "RNNNavigationOptions.h"
- #import "RNNTabBarPresenter.h"
- #import "RNNRootViewController.h"
- #import <OCMock/OCMock.h>
-
- @interface RNNTabBarControllerTest : XCTestCase
-
- @property (nonatomic, strong) RNNTabBarController *uut;
-
- @end
-
- @implementation RNNTabBarControllerTest
-
- - (void)setUp {
- [super setUp];
-
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[[UIViewController alloc] init]] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
- }
-
- - (void)testInitWithLayoutInfo_shouldBindPresenter {
- XCTAssertNotNil(self.uut.presenter);
- }
-
- - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
- UIViewController* vc1 = [[UIViewController alloc] init];
- UIViewController* vc2 = [[UIViewController alloc] init];
-
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[vc1, vc2] options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
- XCTAssertTrue(self.uut.viewControllers.count == 2);
- }
-
- - (void)testInitWithLayoutInfo_shouldInitializeDependencies {
- RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarPresenter* presenter = [[RNNTabBarPresenter alloc] init];
- NSArray* childViewControllers = @[[UIViewController new]];
-
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter];
- XCTAssertTrue(self.uut.layoutInfo == layoutInfo);
- XCTAssertTrue(self.uut.options == options);
- XCTAssertTrue(self.uut.presenter == presenter);
- XCTAssertTrue(self.uut.childViewControllers.count == childViewControllers.count);
- }
-
- - (void)testInitWithEventEmmiter_shouldInitializeDependencies {
- RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarPresenter* presenter = [[RNNTabBarPresenter alloc] init];
- RNNEventEmitter* eventEmmiter = [RNNEventEmitter new];
-
- NSArray* childViewControllers = @[[UIViewController new]];
-
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:layoutInfo childViewControllers:childViewControllers options:options presenter:presenter eventEmitter:eventEmmiter];
- XCTAssertTrue(self.uut.layoutInfo == layoutInfo);
- XCTAssertTrue(self.uut.options == options);
- XCTAssertTrue(self.uut.presenter == presenter);
- XCTAssertTrue(self.uut.childViewControllers.count == childViewControllers.count);
- XCTAssertTrue(self.uut.eventEmitter == eventEmmiter);
- }
-
- - (void)testInitWithLayoutInfo_shouldSetDelegate {
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:[[RNNNavigationOptions alloc] initWithDict:@{}] presenter:[[RNNViewControllerPresenter alloc] init]];
-
- XCTAssertTrue(self.uut.delegate == self.uut);
- }
-
- - (void)testWillMoveToParent_invokePresenterApplyOptionsOnWillMoveToParent {
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
-
- [[presenterMock expect] applyOptionsOnWillMoveToParentViewController:options];
- [self.uut willMoveToParentViewController:[UIViewController new]];
- [presenterMock verify];
- }
-
- - (void)testWillMoveToParent_shouldNotInvokePresenterApplyOptionsOnWillMoveToNilParent {
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- self.uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
-
- [[presenterMock reject] applyOptionsOnWillMoveToParentViewController:options];
- [self.uut willMoveToParentViewController:nil];
- [presenterMock verify];
- }
-
- - (void)testOnChildAppear_shouldInvokePresenterApplyOptionsWithResolvedOptions {
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
-
- [[presenterMock expect] applyOptions:[OCMArg any]];
- [uut onChildWillAppear];
- [presenterMock verify];
- }
-
- - (void)testMergeOptions_shouldInvokePresenterMergeOptions {
- id presenterMock = [OCMockObject partialMockForObject:[RNNTabBarPresenter new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:presenterMock];
-
- [(RNNTabBarPresenter *)[presenterMock expect] mergeOptions:options resolvedOptions:nil];
- [uut mergeOptions:options];
- [presenterMock verify];
- }
-
- - (void)testMergeOptions_shouldInvokeParentMergeOptions {
- id parentMock = [OCMockObject partialMockForObject:[RNNTabBarController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:[RNNTabBarPresenter new]];
- [parentMock addChildViewController:uut];
-
- [(RNNTabBarController *)[parentMock expect] mergeOptions:options];
- [uut mergeOptions:options];
- [parentMock verify];
- }
-
- - (void)testOnChildAppear_shouldInvokeParentOnChildAppear {
- id parentMock = [OCMockObject partialMockForObject:[RNNTabBarController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:nil options:options presenter:[RNNTabBarPresenter new]];
- [parentMock addChildViewController:uut];
-
- [[parentMock expect] onChildWillAppear];
- [uut onChildWillAppear];
- [parentMock verify];
- }
-
- - (void)testGetCurrentChild_shouldInvokeSelectedViewControllerGetCurrentChild {
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[childMock] options:options presenter:[RNNTabBarPresenter new]];
-
- [[childMock expect] getCurrentChild];
- [uut getCurrentChild];
- [childMock verify];
- }
-
- - (void)testGetCurrentChild_shouldInvokeOnSelectedViewController {
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[UIViewController new], childMock] options:options presenter:[RNNTabBarPresenter new]];
- [uut setSelectedIndex:1];
-
- [[childMock expect] getCurrentChild];
- [uut getCurrentChild];
- [childMock verify];
- }
-
- - (void)testPreferredStatusBarStyle_shouldInvokeSelectedViewControllerPreferredStatusBarStyle {
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[childMock] options:options presenter:[RNNTabBarPresenter new]];
-
- [[childMock expect] preferredStatusBarStyle];
- [uut preferredStatusBarStyle];
- [childMock verify];
- }
-
- - (void)testPreferredStatusBarStyle_shouldInvokeOnSelectedViewController {
- id childMock = [OCMockObject partialMockForObject:[RNNRootViewController new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[UIViewController new], childMock] options:options presenter:[RNNTabBarPresenter new]];
- [uut setSelectedIndex:1];
-
- [[childMock expect] preferredStatusBarStyle];
- [uut preferredStatusBarStyle];
- [childMock verify];
- }
-
- - (void)testTabBarControllerDidSelectViewControllerDelegate_shouldInvokeSendBottomTabSelectedEvent {
- id eventEmmiterMock = [OCMockObject partialMockForObject:[RNNEventEmitter new]];
- RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
- UIViewController* vc = [UIViewController new];
- UIViewController* vc2 = [UIViewController new];
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[vc, vc2] options:options presenter:[RNNTabBarPresenter new] eventEmitter:eventEmmiterMock];
- [uut setSelectedIndex:1];
- [[eventEmmiterMock expect] sendBottomTabSelected:[OCMArg any] unselected:[OCMArg any]];
- [uut tabBarController:uut didSelectViewController:vc2];
- [eventEmmiterMock verify];
- }
-
- - (void)testSetSelectedIndexByComponentID_ShouldSetSelectedIndexWithCorrectIndex {
- RNNLayoutInfo* layoutInfo = [RNNLayoutInfo new];
- layoutInfo.componentId = @"componentId";
-
- RNNRootViewController* vc = [[RNNRootViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil];
-
- RNNTabBarController* uut = [[RNNTabBarController alloc] initWithLayoutInfo:nil childViewControllers:@[[UIViewController new], vc] options:nil presenter:[RNNTabBarPresenter new]];
- [uut setSelectedIndexByComponentID:@"componentId"];
- XCTAssertTrue(uut.selectedIndex == 1);
- }
-
- @end
|