react-native-navigation的迁移库

StackOptionsTest.m 3.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // Uncomment next line to record new snapshots
  16. // self.recordMode = YES;
  17. }
  18. - (void)tearDown {
  19. [super tearDown];
  20. _window.rootViewController = nil;
  21. }
  22. #define RNNStackFlow(NAME, FIRST, SECOND, ...)\
  23. [self setRoot:[LayoutCreator component:@"FirstComponent" options:FIRST] testName:@#NAME]; \
  24. [self push:[LayoutCreator component:@"SecondComponent" options:SECOND] testName:@#NAME]; \
  25. [self pop:@"SecondComponent" testName:@#NAME]; \
  26. - (void)testStack_topBar {
  27. RNNStackFlow(opaque background, @{@"topBar": @{@"background": @{@"color": @(0xFFFF00FF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}});
  28. RNNStackFlow(tansparent background, @{@"topBar": @{@"background": @{@"color": @(0x00FFFFFF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}});
  29. RNNStackFlow(translucent background, @{@"topBar": @{@"background": @{@"translucent": @(1)}}}, @{@"topBar": @{@"background": @{@"translucent": @(0)}}});
  30. RNNStackFlow(title change, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, @{@"topBar": @{@"title": @{@"text": @"Second Component"}}});
  31. RNNStackFlow(visibility, @{@"topBar": @{@"visible": @(0)}}, @{@"topBar": @{@"visible": @(1)}});
  32. RNNStackFlow(title font, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, (@{@"topBar": @{@"title": @{@"text": @"Second Component", @"fontFamily": @"Arial", @"color": @(0xFFFF00FF), @"fontSize": @(15)}}}));
  33. }
  34. - (void)setRoot:(NSDictionary *)firstComponent testName:(NSString *)testName {
  35. NSDictionary* root = [LayoutCreator stack:@{} children:@[firstComponent]];
  36. NSString* rootTestName = [NSString stringWithFormat:@"%@_root", testName];
  37. [_commandsHandler setRoot:@{@"root": root}
  38. commandId:@"SetRoot"
  39. completion:^{}];
  40. FBSnapshotVerifyView(_window, rootTestName);
  41. }
  42. - (void)push:(NSDictionary *)secondComponent testName:(NSString *)testName {
  43. NSString* pushTestName = [NSString stringWithFormat:@"%@_push", testName];
  44. [_commandsHandler push:@"FirstComponent"
  45. commandId:@"push"
  46. layout:secondComponent
  47. completion:^{}
  48. rejection:^(NSString *code, NSString *message, NSError *error) {}];
  49. FBSnapshotVerifyView(_window, pushTestName);
  50. }
  51. - (void)pop:(NSString *)componentId testName:(NSString *)testName {
  52. NSString* popTestName = [NSString stringWithFormat:@"%@_pop", testName];
  53. [_commandsHandler pop:componentId
  54. commandId:@"pop"
  55. mergeOptions:@{}
  56. completion:^{}
  57. rejection:^(NSString *code, NSString *message, NSError *error) {}];
  58. FBSnapshotVerifyView(_window, popTestName);
  59. }
  60. @end