react-native-navigation的迁移库

UIViewController+LayoutProtocolTest.m 5.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "RCTConvert+Modal.h"
  7. #import "RNNBottomTabsController.h"
  8. #import "RNNStackController.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. _uut.layoutInfo = [[RNNLayoutInfo alloc] init];
  17. _uut.layoutInfo.componentId = @"componentId";
  18. }
  19. - (void)testInitWithLayoutApplyDefaultOptions {
  20. RNNComponentPresenter* presenter = [[RNNComponentPresenter 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)testResolveOptions {
  36. RNNComponentPresenter* presenter = [[RNNComponentPresenter alloc] init];
  37. RNNNavigationOptions* childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  38. RNNNavigationOptions* parentOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  39. parentOptions.bottomTab.text = [[Text alloc] initWithValue:@"text"];
  40. parentOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.redColor];
  41. RNNNavigationOptions* defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  42. defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"];
  43. defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor];
  44. UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:childOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:nil];
  45. RNNStackController* parent = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:parentOptions defaultOptions:defaultOptions presenter:presenter eventEmitter:nil childViewControllers:@[child]];
  46. XCTAssertEqual([parent getCurrentChild], child);
  47. XCTAssertEqual([[parent resolveOptions].bottomTab.text get], @"text");
  48. XCTAssertEqual([[parent resolveOptions].bottomTab.selectedIconColor get], UIColor.redColor);
  49. }
  50. - (void)testMergeOptions_invokedOnParentViewController {
  51. id parent = [OCMockObject partialMockForObject:[RNNStackController new]];
  52. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  53. [(UIViewController *) [parent expect] mergeChildOptions:toMerge];
  54. RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:nil defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  55. [parent addChildViewController:uut];
  56. [uut mergeOptions:toMerge];
  57. [parent verify];
  58. }
  59. - (void)testMergeOptions_presenterIsInvokedWithResolvedOptions {
  60. id parent = [OCMockObject partialMockForObject:[RNNStackController new]];
  61. id presenter = [OCMockObject partialMockForObject:[RNNStackPresenter new]];
  62. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  63. toMerge.topBar.title.color = [[Color alloc] initWithValue:[UIColor redColor]];
  64. [[presenter expect] mergeOptions:toMerge resolvedOptions:[OCMArg checkWithBlock:^(id value) {
  65. RNNNavigationOptions *options = (RNNNavigationOptions *) value;
  66. XCTAssertEqual([options.topBar.title.text get], @"Initial title");
  67. XCTAssertEqual([options.bottomTab.text get], @"Child tab text");
  68. return YES;
  69. }]];
  70. RNNNavigationOptions * childOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  71. childOptions.bottomTab.text = [[Text alloc] initWithValue:@"Child tab text"];
  72. UIViewController* child = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:childOptions defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:nil];
  73. RNNNavigationOptions * initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions];
  74. initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"Initial title"];
  75. RNNStackController* uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:initialOptions defaultOptions:nil presenter:presenter eventEmitter:nil childViewControllers:@[child]];
  76. [parent addChildViewController:uut];
  77. [uut mergeOptions:toMerge];
  78. [presenter verify];
  79. }
  80. - (void)testMergeOptions_mergedIntoCurrentOptions {
  81. UIViewController* uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil];
  82. RNNNavigationOptions * toMerge = [[RNNNavigationOptions alloc] initEmptyOptions];
  83. toMerge.topBar.title.text = [[Text alloc] initWithValue:@"merged"];
  84. [uut mergeOptions:toMerge];
  85. XCTAssertEqual(uut.resolveOptions.topBar.title.text.get, @"merged");
  86. }
  87. @end