react-native-navigation的迁移库

RNNViewControllerTests.m 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // RNNViewControllerTests.m
  3. //
  4. // Created by Ran Greenberg on 26/12/2016.
  5. // Copyright © 2016 Facebook. All rights reserved.
  6. //
  7. #import <XCTest/XCTest.h>
  8. #import "RCCManager.h"
  9. #import "RNNViewController.h"
  10. #import "MMDrawerController.h"
  11. #define COMMAND_SINGLE_SCREEN_APP @"singleScreenApp"
  12. #define COMMAND_TAB_BASED_APP @"tabBasedApp"
  13. #define COMMAND_SINGLE_WITH_LEFT_SIDE_MENU @"singleWithLeftSideMenu"
  14. #define COMMAND_SINGLE_WITH_RIGHT_SIDE_MENU @"singleWithRightSideMenu"
  15. #define COMMAND_SINGLE_WITH_BOTH_SIDE_MENU @"singleWithBothMenus"
  16. #define COMMAND_TAB_BASED_WITH_SIDE_MENT @"tabBasedWithSideMenu"
  17. @interface RNNViewControllerTests : XCTestCase
  18. @property (nonatomic, strong) RCTBridge *bridge;
  19. @property (nonatomic, strong) NSDictionary *jsonCommands;
  20. @end
  21. @implementation RNNViewControllerTests
  22. - (void)setUp {
  23. [super setUp];
  24. // Put setup code here. This method is called before the invocation of each test method in the class.
  25. self.bridge = [[RCCManager sharedInstance] getBridge];
  26. self.jsonCommands = [self loadCommandsJsonAsDictionary];
  27. }
  28. - (void)tearDown {
  29. // Put teardown code here. This method is called after the invocation of each test method in the class.
  30. self.bridge = nil;
  31. self.jsonCommands = nil;
  32. [super tearDown];
  33. }
  34. -(NSDictionary*)loadCommandsJsonAsDictionary {
  35. NSString *filePath = [[NSBundle mainBundle] pathForResource:@"commands" ofType:@"json"];
  36. NSData *data = [NSData dataWithContentsOfFile:filePath];
  37. NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
  38. return json;
  39. }
  40. - (void)testWrongSyntax {
  41. NSDictionary *layout = @{@"key": @"com.example.FirstTabScreen"};
  42. id vc = [RNNViewController controllerWithLayout:layout bridge:self.bridge];
  43. XCTAssertNil(vc);
  44. }
  45. -(void)testSingleScreenApp {
  46. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_SINGLE_SCREEN_APP] bridge:self.bridge];
  47. XCTAssertTrue([vc isKindOfClass:[UINavigationController class]]);
  48. }
  49. -(void)testTabBasedApp {
  50. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_TAB_BASED_APP] bridge:self.bridge];
  51. XCTAssertTrue([vc isKindOfClass:[UITabBarController class]]);
  52. UITabBarController *tabsController = (UITabBarController*)vc;
  53. for (id tab in tabsController.viewControllers) {
  54. XCTAssertTrue([tab isKindOfClass:[UINavigationController class]]);
  55. }
  56. }
  57. -(void)testSingleWithLeftSideMenu {
  58. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_SINGLE_WITH_LEFT_SIDE_MENU] bridge:self.bridge];
  59. XCTAssertTrue([vc isKindOfClass:[MMDrawerController class]]);
  60. MMDrawerController *sideMenuLeft = (MMDrawerController*)vc;
  61. XCTAssertNotNil(sideMenuLeft.leftDrawerViewController);
  62. XCTAssertNotNil(sideMenuLeft.centerViewController);
  63. XCTAssertNil(sideMenuLeft.rightDrawerViewController);
  64. }
  65. -(void)testSingleWithRightSideMenu {
  66. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_SINGLE_WITH_RIGHT_SIDE_MENU] bridge:self.bridge];
  67. XCTAssertTrue([vc isKindOfClass:[MMDrawerController class]]);
  68. MMDrawerController *sideMenuRight = (MMDrawerController*)vc;
  69. XCTAssertNil(sideMenuRight.leftDrawerViewController);
  70. XCTAssertNotNil(sideMenuRight.centerViewController);
  71. XCTAssertNotNil(sideMenuRight.rightDrawerViewController);
  72. }
  73. -(void)testSingleWithBothSideMenu {
  74. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_SINGLE_WITH_BOTH_SIDE_MENU] bridge:self.bridge];
  75. XCTAssertTrue([vc isKindOfClass:[MMDrawerController class]]);
  76. MMDrawerController *sideMenuBoth = (MMDrawerController*)vc;
  77. XCTAssertNotNil(sideMenuBoth.leftDrawerViewController);
  78. XCTAssertNotNil(sideMenuBoth.centerViewController);
  79. XCTAssertNotNil(sideMenuBoth.rightDrawerViewController);
  80. }
  81. -(void)testTabBasedWithBothSideMenu {
  82. id vc = [RNNViewController controllerWithLayout:self.jsonCommands[COMMAND_TAB_BASED_WITH_SIDE_MENT] bridge:self.bridge];
  83. XCTAssertTrue([vc isKindOfClass:[MMDrawerController class]]);
  84. MMDrawerController *sideMenuBothWithTabs = (MMDrawerController*)vc;
  85. XCTAssertNotNil(sideMenuBothWithTabs.leftDrawerViewController);
  86. XCTAssertNotNil(sideMenuBothWithTabs.centerViewController);
  87. XCTAssertNotNil(sideMenuBothWithTabs.rightDrawerViewController);
  88. XCTAssertTrue([sideMenuBothWithTabs.centerViewController isKindOfClass:[UITabBarController class]]);
  89. }
  90. //- (void)testPerformanceExample {
  91. // // This is an example of a performance test case.
  92. // [self measureBlock:^{
  93. // // Put the code you want to measure the time of here.
  94. // }];
  95. //}
  96. @end