react-native-navigation的迁移库

UIViewController+LayoutProtocolTest.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. #import <XCTest/XCTest.h>
  2. #import <OCMock/OCMock.h>
  3. #import "UIViewController+LayoutProtocol.h"
  4. #import "UIViewController+RNNOptions.h"
  5. #import "RNNComponentPresenter.h"
  6. #import "RNNBottomTabsController.h"
  7. #import "RNNStackController.h"
  8. @interface UIViewController_LayoutProtocolTest : XCTestCase
  9. @property (nonatomic, retain) UIViewController * uut;
  10. @end
  11. @implementation UIViewController_LayoutProtocolTest
  12. - (void)setUp {
  13. [super setUp];
  14. self.uut = [OCMockObject partialMockForObject:[UIViewController new]];
  15. _uut.layoutInfo = [[RNNLayoutInfo alloc] init];
  16. _uut.layoutInfo.componentId = @"componentId";
  17. }
  18. - (void)testInitWithLayoutApplyDefaultOptions {
  19. RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] init];
  20. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  21. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  22. defaultOptions.modalPresentationStyle = [[Text alloc] initWithValue:@"default"];
  23. UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  24. XCTAssertEqual(uut.modalPresentationStyle, UIModalPresentationPageSheet);
  25. }
  26. - (void)testInitWithLayoutInfoShouldSetChildViewControllers {
  27. UIViewController* child1 = [UIViewController new];
  28. UIViewController* child2 = [UIViewController new];
  29. NSArray* childViewControllers = @[child1, child2];
  30. UINavigationController* uut = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:childViewControllers];
  31. XCTAssertEqual(uut.viewControllers[0], child1);
  32. XCTAssertEqual(uut.viewControllers[1], child2);
  33. }
  34. - (void)testResolveOptions {
  35. RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] init];
  36. RNNNavigationOptions* childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  37. RNNNavigationOptions* parentOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  38. parentOptions.bottomTab.text = [[Text alloc] initWithValue:@"text"];
  39. parentOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.redColor];
  40. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  41. defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
  42. defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor];
  43. UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:childOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  44. RNNStackController* parent = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
  45. XCTAssertEqual([parent getCurrentChild], child);
  46. XCTAssertEqual([[parent resolveOptions].bottomTab.text get], @"text");
  47. XCTAssertEqual([[parent resolveOptions].bottomTab.selectedIconColor get], UIColor.redColor);
  48. }
  49. - (void)testMergeOptions_invokedOnParentViewController {
  50. id parent = [OCMockObject partialMockForObject:[RNNStackController new]];
  51. RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  52. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  53. [(UIViewController *) [parent expect] mergeChildOptions:toMerge child:uut];
  54. [parent addChildViewController:uut];
  55. [uut mergeOptions:toMerge];
  56. [parent verify];
  57. }
  58. - (void)testMergeOptions_presenterIsInvokedWithResolvedOptions {
  59. id parent = [OCMockObject partialMockForObject:[RNNStackController new]];
  60. id presenter = [OCMockObject partialMockForObject:[RNNStackPresenter new]];
  61. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  62. toMerge.topBar.title.color = [[Color alloc] initWithValue:[UIColor redColor]];
  63. [[presenter expect] mergeOptions:toMerge resolvedOptions:[OCMArg checkWithBlock:^(id value) {
  64. RNNNavigationOptions *options = (RNNNavigationOptions *) value;
  65. XCTAssertEqual([options.topBar.title.text get], @"Initial title");
  66. XCTAssertEqual([options.bottomTab.text get], @"Child tab text");
  67. return YES;
  68. }]];
  69. RNNNavigationOptions * childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  70. childOptions.bottomTab.text = [[Text alloc] initWithValue:@"Child tab text"];
  71. UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:childOptions defaultOptions:nil presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:nil];
  72. RNNNavigationOptions * initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  73. initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"Initial title"];
  74. RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil options:initialOptions defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:@[child]];
  75. [parent addChildViewController:uut];
  76. [uut mergeOptions:toMerge];
  77. [presenter verify];
  78. }
  79. - (void)testMergeOptions_mergedIntoCurrentOptions {
  80. UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  81. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  82. toMerge.topBar.title.text = [[Text alloc] initWithValue:@"merged"];
  83. [uut mergeOptions:toMerge];
  84. XCTAssertEqual(uut.resolveOptions.topBar.title.text.get, @"merged");
  85. }
  86. - (void)testLayout_shouldExtendedLayoutIncludesOpaqueBars {
  87. UIViewController* component = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  88. UINavigationController* stack = [[UINavigationController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  89. UITabBarController* tabBar = [[UITabBarController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  90. XCTAssertTrue(component.extendedLayoutIncludesOpaqueBars);
  91. XCTAssertTrue(stack.extendedLayoutIncludesOpaqueBars);
  92. XCTAssertTrue(tabBar.extendedLayoutIncludesOpaqueBars);
  93. }
  94. @end