react-native-navigation的迁移库

UIViewController+LayoutProtocolTest.m 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "UIViewController+LayoutProtocol.h"
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNViewControllerPresenter.h"
  6. #import "RCTConvert+Modal.h"
  7. #import "RNNTabBarController.h"
  8. #import "RNNNavigationController.h"
  9. @interface UIViewController_LayoutProtocolTest : XCTestCase
  10. @property (nonatomic, retain) UIViewController* uut;
  11. @end
  12. @implementation UIViewController_LayoutProtocolTest
  13. - (void)setUp {
  14. [super setUp];
  15. self.uut = [OCMockObject partialMockForObject:[UIViewController new]];
  16. self.uut.layoutInfo = [[RNNLayoutInfo alloc] init];
  17. self.uut.layoutInfo.componentId = @"componentId";
  18. }
  19. - (void)testInitWithLayoutApplyDefaultOptions {
  20. RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
  21. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  22. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  23. defaultOptions.modalPresentationStyle = [[Text alloc] initWithValue:@"fullScreen"];
  24. UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  25. XCTAssertEqual(uut.modalPresentationStyle, [RCTConvert UIModalPresentationStyle:@"fullScreen"]);
  26. }
  27. - (void)testInitWithLayoutInfoShouldSetChildViewControllers {
  28. UIViewController* child1 = [UIViewController new];
  29. UIViewController* child2 = [UIViewController new];
  30. NSArray* childViewControllers = @[child1, child2];
  31. UINavigationController* uut = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:childViewControllers];
  32. XCTAssertEqual(uut.viewControllers[0], child1);
  33. XCTAssertEqual(uut.viewControllers[1], child2);
  34. }
  35. - (void)testSetBackButtonIcon_withColor_shouldSetColor {
  36. UIViewController* uut = [UIViewController new];
  37. [[UINavigationController alloc] initWithRootViewController:uut];
  38. UIColor* color = [UIColor blackColor];
  39. [uut rnn_setBackButtonIcon:nil withColor:color title:nil];
  40. XCTAssertEqual(color, uut.navigationItem.backBarButtonItem.tintColor);
  41. }
  42. - (void)testSetBackButtonIcon_withColor_shouldSetTitle {
  43. UIViewController* uut = [UIViewController new];
  44. UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:uut];
  45. NSString* title = @"Title";
  46. [uut rnn_setBackButtonIcon:nil withColor:nil title:title];
  47. XCTAssertEqual(title, uut.navigationItem.backBarButtonItem.title);
  48. }
  49. - (void)testSetBackButtonIcon_withColor_shouldSetIcon {
  50. UIViewController* uut = [UIViewController new];
  51. UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:uut];
  52. UIImage* icon = [UIImage new];
  53. [uut rnn_setBackButtonIcon:icon withColor:nil title:nil];
  54. XCTAssertEqual(icon, uut.navigationItem.backBarButtonItem.image);
  55. }
  56. - (void)testSetBackButtonIcon_shouldSetTitleOnPreviousViewControllerIfExists {
  57. UIViewController* uut = [UIViewController new];
  58. UIViewController* viewController2 = [UIViewController new];
  59. UINavigationController* nav = [[UINavigationController alloc] init];
  60. [nav setViewControllers:@[uut, viewController2]];
  61. NSString* title = @"Title";
  62. [uut rnn_setBackButtonIcon:nil withColor:nil title:title];
  63. XCTAssertEqual(title, uut.navigationItem.backBarButtonItem.title);
  64. }
  65. - (void)testResolveOptions {
  66. RNNViewControllerPresenter* presenter = [[RNNViewControllerPresenter alloc] init];
  67. RNNNavigationOptions* childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  68. RNNNavigationOptions* parentOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  69. parentOptions.bottomTab.text = [[Text alloc] initWithValue:@"text"];
  70. parentOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.redColor];
  71. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  72. defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
  73. defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor];
  74. UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:childOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  75. RNNNavigationController* parent = [[RNNNavigationController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
  76. XCTAssertEqual([parent getCurrentChild], child);
  77. XCTAssertEqual([[parent resolveOptions].bottomTab.text get], @"text");
  78. XCTAssertEqual([[parent resolveOptions].bottomTab.selectedIconColor get], UIColor.redColor);
  79. }
  80. @end