react-native-navigation的迁移库

StackOptionsTest.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #import <XCTest/XCTest.h>
  2. #import "LayoutCreator.h"
  3. #import "CommandsHandlerCreator.h"
  4. #import <FBSnapshotTestCase/FBSnapshotTestCase.h>
  5. @interface StackOptionsTest : FBSnapshotTestCase
  6. @property (nonatomic, strong) RNNCommandsHandler* commandsHandler;
  7. @property (nonatomic, strong) UIWindow* window;
  8. @end
  9. @implementation StackOptionsTest
  10. - (void)setUp {
  11. [super setUp];
  12. _window = [[[UIApplication sharedApplication] delegate] window];
  13. _commandsHandler = [CommandsHandlerCreator createWithWindow:_window];
  14. self.usesDrawViewHierarchyInRect = YES;
  15. if (NSProcessInfo.processInfo.environment[@"RECORD_SNAPSHOTS"]) {
  16. self.recordMode = YES;
  17. }
  18. }
  19. - (void)tearDown {
  20. [super tearDown];
  21. _window.rootViewController = nil;
  22. }
  23. #define RNNStackFlow(NAME, FIRST, SECOND, ...)\
  24. [self setRoot:[LayoutCreator component:@"FirstComponent" options:FIRST] testName:@#NAME]; \
  25. [self push:[LayoutCreator component:@"SecondComponent" options:SECOND] testName:@#NAME]; \
  26. [self pop:@"SecondComponent" testName:@#NAME]; \
  27. - (void)testStack_topBar {
  28. RNNStackFlow(opaque background, @{@"topBar": @{@"background": @{@"color": @(0xFFFF00FF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}});
  29. RNNStackFlow(tansparent background, @{@"topBar": @{@"background": @{@"color": @(0x00FFFFFF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}});
  30. RNNStackFlow(translucent background, @{@"topBar": @{@"background": @{@"translucent": @(1)}}}, @{@"topBar": @{@"background": @{@"translucent": @(0)}}});
  31. RNNStackFlow(title change, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, @{@"topBar": @{@"title": @{@"text": @"Second Component"}}});
  32. RNNStackFlow(visibility, @{@"topBar": @{@"visible": @(0)}}, @{@"topBar": @{@"visible": @(1)}});
  33. RNNStackFlow(title font, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, (@{@"topBar": @{@"title": @{@"text": @"Second Component", @"fontFamily": @"Arial", @"color": @(0xFFFF00FF), @"fontSize": @(15)}}}));
  34. }
  35. - (void)setRoot:(NSDictionary *)firstComponent testName:(NSString *)testName {
  36. NSDictionary* root = [LayoutCreator stack:@{} children:@[firstComponent]];
  37. NSString* rootTestName = [NSString stringWithFormat:@"%@_root", testName];
  38. [_commandsHandler setRoot:@{@"root": root}
  39. commandId:@"SetRoot"
  40. completion:^{}];
  41. FBSnapshotVerifyView(_window, rootTestName);
  42. }
  43. - (void)push:(NSDictionary *)secondComponent testName:(NSString *)testName {
  44. NSString* pushTestName = [NSString stringWithFormat:@"%@_push", testName];
  45. [_commandsHandler push:@"FirstComponent"
  46. commandId:@"push"
  47. layout:secondComponent
  48. completion:^{}
  49. rejection:^(NSString *code, NSString *message, NSError *error) {}];
  50. FBSnapshotVerifyView(_window, pushTestName);
  51. }
  52. - (void)pop:(NSString *)componentId testName:(NSString *)testName {
  53. NSString* popTestName = [NSString stringWithFormat:@"%@_pop", testName];
  54. [_commandsHandler pop:componentId
  55. commandId:@"pop"
  56. mergeOptions:@{}
  57. completion:^{}
  58. rejection:^(NSString *code, NSString *message, NSError *error) {}];
  59. FBSnapshotVerifyView(_window, popTestName);
  60. }
  61. @end