react-native-navigation的迁移库

RNNNavigationOptionsTest.m 3.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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)testChangeRNNNavigationOptionsDynamically {
  18. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
  19. NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"textColor" : @(0xffff00ff), @"title" : @{@"text": @"hello"}}};
  20. RNNNavigationOptions* dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict];
  21. [options overrideOptions:dynamicOptions];
  22. XCTAssertTrue([options.topBar.title.text.get isEqual:@"hello"]);
  23. }
  24. - (void)testChangeRNNNavigationOptionsWithInvalidProperties {
  25. RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initWithDict:@{@"topBar": @{@"background" : @{@"color" : @(0xff0000ff)}}}];
  26. NSDictionary* dynamicOptionsDict = @{@"topBar": @{@"titleeeee" : @"hello"}};
  27. RNNNavigationOptions* dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict];
  28. XCTAssertNoThrow([options overrideOptions:dynamicOptions]);
  29. }
  30. - (void)testWithDefault {
  31. RNNNavigationOptions * options = [[RNNNavigationOptions alloc] initWithDict:@{
  32. @"topBar": @{
  33. @"subtitle" : @{@"text": @"hey"}
  34. },
  35. @"bottomTab": @{
  36. @"selectedIconColor": @(0xff000000)
  37. }
  38. }];
  39. RNNNavigationOptions * defaultOptions = [[RNNNavigationOptions alloc] initWithDict:@{
  40. @"topBar": @{
  41. @"subtitle": @{@"text": @"ho"},
  42. @"title": @{@"text": @"hello"}
  43. },
  44. @"bottomTab": @{
  45. @"selectedIconColor": @(0xff0000ff)
  46. }
  47. }];
  48. RNNNavigationOptions * withDefault = [options withDefault:defaultOptions];
  49. XCTAssertEqual(withDefault.topBar.subtitle.text.get, @"hey");
  50. XCTAssertEqual(withDefault.bottomTab.selectedIconColor.get, options.bottomTab.selectedIconColor.get);
  51. }
  52. //
  53. //- (void)test_applyDefaultOptions {
  54. // RNNNavigationOptions* options = [[RNNNavigationOptions alloc] initEmptyOptions];
  55. // UIViewController* viewController = [UIViewController new];
  56. // UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];
  57. // UITabBarController* tabBarController = [[UITabBarController alloc] init];
  58. // [tabBarController setViewControllers:@[navigationController]];
  59. //
  60. // [options applyDefaultOptionsOn:viewController];
  61. //
  62. // XCTAssertFalse(navigationController.navigationBar.hidden);
  63. // XCTAssertFalse(navigationController.navigationBar.translucent);
  64. // XCTAssertFalse(navigationController.navigationBar.clipsToBounds);
  65. // XCTAssertFalse(navigationController.hidesBarsOnSwipe);
  66. // XCTAssertTrue(navigationController.navigationBar.barStyle == UIBarStyleDefault);
  67. //
  68. // XCTAssertNil(tabBarController.tabBar.barTintColor);
  69. // XCTAssertTrue(tabBarController.tabBar.barStyle == UIBarStyleDefault);
  70. // XCTAssertFalse(tabBarController.tabBar.translucent);
  71. //}
  72. @end