react-native-navigation的迁移库

RNNNavigationOptionsTest.m 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #import <XCTest/XCTest.h>
  2. #import "RNNNavigationOptions.h"
  3. @interface RNNNavigationOptionsTest : XCTestCase
  4. @end
  5. @implementation RNNNavigationOptionsTest
  6. - (void)setUp {
  7. [super setUp];
  8. }
  9. - (void)testInitCreatesInstanceType {
  10. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{}];
  11. XCTAssertTrue([options isKindOfClass:[RNNNavigationOptions class]]);
  12. }
  13. - (void)testAddsStyleFromDictionaryWithInit {
  14. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
  15. XCTAssertTrue(options.topBar.background.color);
  16. }
  17. - (void)testAddsFontToBackButtonOptions {
  18. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"backButton" : @{@"fontFamily" : @"HelveticaNeue"}}}];
  19. XCTAssertTrue([options.topBar.backButton.fontFamily.get isEqual:@"HelveticaNeue"]);
  20. }
  21. - (void)testChangeRNNNavigationOptionsDynamically {
  22. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
  23. NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};
  24. RNNNavigationOptions* dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict];
  25. [options overrideOptions:dynamicOptions];
  26. XCTAssertTrue([options.topBar.title.text.get isEqual:@"hello"]);
  27. }
  28. - (void)testChangeRNNNavigationOptionsWithInvalidProperties {
  29. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
  30. NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"titleeeee" : @"hello"}};
  31. RNNNavigationOptions* dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict];
  32. XCTAssertNoThrow([options overrideOptions:dynamicOptions]);
  33. }
  34. - (void)testWithDefault {
  35. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initWithDict:@{
  36. @"topBar": @{
  37. @"subtitle" : @{@"text": @"hey"}
  38. },
  39. @"bottomTab": @{
  40. @"selectedIconColor": @(0xff000000)
  41. }
  42. }];
  43. RNNNavigationOptions * defaultOptions = [[RNNNavigationOptions alloc] initWithDict:@{
  44. @"topBar": @{
  45. @"subtitle": @{@"text": @"ho"},
  46. @"title": @{@"text": @"hello"}
  47. },
  48. @"bottomTab": @{
  49. @"selectedIconColor": @(0xff0000ff)
  50. }
  51. }];
  52. RNNNavigationOptions * withDefault = [options withDefault:defaultOptions];
  53. XCTAssertEqual(withDefault.topBar.subtitle.text.get, @"hey");
  54. XCTAssertEqual(withDefault.bottomTab.selectedIconColor.get, options.bottomTab.selectedIconColor.get);
  55. }
  56. //
  57. //- (void)test_applyDefaultOptions {
  58. // RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  59. // UIViewController* viewController = [UIViewController new];
  60. // UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  61. // UITabBarController* tabBarController = [[UITabBarController alloc] init];
  62. // [tabBarController setViewControllers:@[navigationController]];
  63. //
  64. // [options applyDefaultOptionsOn:viewController];
  65. //
  66. // XCTAssertFalse(navigationController.navigationBar.hidden);
  67. // XCTAssertFalse(navigationController.navigationBar.translucent);
  68. // XCTAssertFalse(navigationController.navigationBar.clipsToBounds);
  69. // XCTAssertFalse(navigationController.hidesBarsOnSwipe);
  70. // XCTAssertTrue(navigationController.navigationBar.barStyle == UIBarStyleDefault);
  71. //
  72. // XCTAssertNil(tabBarController.tabBar.barTintColor);
  73. // XCTAssertTrue(tabBarController.tabBar.barStyle == UIBarStyleDefault);
  74. // XCTAssertFalse(tabBarController.tabBar.translucent);
  75. //}
  76. @end