react-native-navigation的迁移库

RNNRootViewControllerTest.m 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #import <XCTest/XCTest.h>
  2. #import "RNNRootViewController.h"
  3. #import "RNNReactRootViewCreator.h"
  4. #import "RNNTestRootViewCreator.h"
  5. #import <React/RCTConvert.h>
  6. #import "RNNNavigationOptions.h"
  7. @interface RNNRootViewControllerTest : XCTestCase
  8. @property (nonatomic, strong) id<RNNRootViewCreator> creator;
  9. @property (nonatomic, strong) NSString* pageName;
  10. @property (nonatomic, strong) NSString* containerId;
  11. @property (nonatomic, strong) id emitter;
  12. @property (nonatomic, strong) RNNNavigationOptions* options;
  13. @property (nonatomic, strong) RNNRootViewController* uut;
  14. @end
  15. @implementation RNNRootViewControllerTest
  16. - (void)setUp {
  17. [super setUp];
  18. self.creator = [[RNNTestRootViewCreator alloc] init];
  19. self.pageName = @"somename";
  20. self.containerId = @"cntId";
  21. self.emitter = nil;
  22. self.options = [RNNNavigationOptions new];
  23. self.uut = [[RNNRootViewController alloc] initWithName:self.pageName withOptions:self.options withContainerId:self.containerId rootViewCreator:self.creator eventEmitter:self.emitter];
  24. }
  25. -(void)testTopBarBackgroundColor_validColor{
  26. NSNumber* inputColor = @(0xFFFF0000);
  27. self.options.topBarBackgroundColor = inputColor;
  28. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  29. [self.uut viewWillAppear:false];
  30. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  31. XCTAssertTrue([self.uut.navigationController.navigationBar.barTintColor isEqual:expectedColor]);
  32. }
  33. -(void)testTopBarBackgroundColorWithoutNavigationController{
  34. NSNumber* inputColor = @(0xFFFF0000);
  35. self.options.topBarBackgroundColor = inputColor;
  36. XCTAssertNoThrow([self.uut viewWillAppear:false]);
  37. }
  38. - (void)testStatusBarHidden_default {
  39. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  40. [self.uut viewWillAppear:false];
  41. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  42. }
  43. - (void)testStatusBarHidden_true {
  44. self.options.statusBarHidden = @(1);
  45. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  46. [self.uut viewWillAppear:false];
  47. XCTAssertTrue([self.uut prefersStatusBarHidden]);
  48. }
  49. - (void)testStatusBarHidden_false {
  50. self.options.statusBarHidden = @(0);
  51. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  52. [self.uut viewWillAppear:false];
  53. XCTAssertFalse([self.uut prefersStatusBarHidden]);
  54. }
  55. -(void)testTitle_string{
  56. NSString* title =@"some title";
  57. self.options.title= title;
  58. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  59. [self.uut viewWillAppear:false];
  60. XCTAssertTrue([self.uut.navigationItem.title isEqual:title]);
  61. }
  62. -(void)testTitle_default{
  63. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  64. [self.uut viewWillAppear:false];
  65. XCTAssertNil(self.uut.navigationItem.title);
  66. }
  67. -(void)testTopBarTextColor_validColor{
  68. NSNumber* inputColor = @(0xFFFF0000);
  69. self.options.topBarTextColor = inputColor;
  70. __unused UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:self.uut];
  71. [self.uut viewWillAppear:false];
  72. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  73. XCTAssertTrue([self.uut.navigationController.navigationBar.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
  74. }
  75. -(void)testScreenBackgroundColor_validColor{
  76. NSNumber* inputColor = @(0xFFFF0000);
  77. self.options.screenBackgroundColor = inputColor;
  78. [self.uut viewWillAppear:false];
  79. UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
  80. XCTAssertTrue([self.uut.view.backgroundColor isEqual:expectedColor]);
  81. }
  82. @end