forked from wix/react-native-navigation
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add snapshot tests
- Loading branch information
Showing
36 changed files
with
618 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#import <XCTest/XCTest.h> | ||
#import "LayoutCreator.h" | ||
#import "CommandsHandlerCreator.h" | ||
#import <FBSnapshotTestCase/FBSnapshotTestCase.h> | ||
|
||
@interface StackOptionsTest : FBSnapshotTestCase | ||
@property (nonatomic, strong) RNNCommandsHandler* commandsHandler; | ||
@property (nonatomic, strong) UIWindow* window; | ||
@end | ||
|
||
@implementation StackOptionsTest | ||
|
||
- (void)setUp { | ||
[super setUp]; | ||
_window = [[[UIApplication sharedApplication] delegate] window]; | ||
_commandsHandler = [CommandsHandlerCreator createWithWindow:_window]; | ||
self.usesDrawViewHierarchyInRect = YES; | ||
|
||
// Uncomment next line to record new snapshots | ||
// self.recordMode = YES; | ||
} | ||
|
||
- (void)tearDown { | ||
[super tearDown]; | ||
_window.rootViewController = nil; | ||
} | ||
|
||
#define RNNStackFlow(NAME, FIRST, SECOND, ...)\ | ||
[self setRoot:[LayoutCreator component:@"FirstComponent" options:FIRST] testName:@#NAME]; \ | ||
[self push:[LayoutCreator component:@"SecondComponent" options:SECOND] testName:@#NAME]; \ | ||
[self pop:@"SecondComponent" testName:@#NAME]; \ | ||
|
||
|
||
- (void)testStack_topBar { | ||
RNNStackFlow(opaque background, @{@"topBar": @{@"background": @{@"color": @(0xFFFF00FF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}}); | ||
RNNStackFlow(tansparent background, @{@"topBar": @{@"background": @{@"color": @(0x00FFFFFF)}}}, @{@"topBar": @{@"background": @{@"color": @(0xFFFF0000)}}}); | ||
RNNStackFlow(translucent background, @{@"topBar": @{@"background": @{@"translucent": @(1)}}}, @{@"topBar": @{@"background": @{@"translucent": @(0)}}}); | ||
RNNStackFlow(title change, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, @{@"topBar": @{@"title": @{@"text": @"Second Component"}}}); | ||
RNNStackFlow(visibility, @{@"topBar": @{@"visible": @(0)}}, @{@"topBar": @{@"visible": @(1)}}); | ||
RNNStackFlow(title font, @{@"topBar": @{@"title": @{@"text": @"First Component"}}}, (@{@"topBar": @{@"title": @{@"text": @"Second Component", @"fontFamily": @"Arial", @"color": @(0xFFFF00FF), @"fontSize": @(15)}}})); | ||
} | ||
|
||
- (void)setRoot:(NSDictionary *)firstComponent testName:(NSString *)testName { | ||
NSDictionary* root = [LayoutCreator stack:@{} children:@[firstComponent]]; | ||
NSString* rootTestName = [NSString stringWithFormat:@"%@_root", testName]; | ||
[_commandsHandler setRoot:@{@"root": root} | ||
commandId:@"SetRoot" | ||
completion:^{}]; | ||
FBSnapshotVerifyView(_window, rootTestName); | ||
} | ||
|
||
- (void)push:(NSDictionary *)secondComponent testName:(NSString *)testName { | ||
NSString* pushTestName = [NSString stringWithFormat:@"%@_push", testName]; | ||
[_commandsHandler push:@"FirstComponent" | ||
commandId:@"push" | ||
layout:secondComponent | ||
completion:^{} | ||
rejection:^(NSString *code, NSString *message, NSError *error) {}]; | ||
FBSnapshotVerifyView(_window, pushTestName); | ||
} | ||
|
||
- (void)pop:(NSString *)componentId testName:(NSString *)testName { | ||
NSString* popTestName = [NSString stringWithFormat:@"%@_pop", testName]; | ||
[_commandsHandler pop:componentId | ||
commandId:@"pop" | ||
mergeOptions:@{} | ||
completion:^{} | ||
rejection:^(NSString *code, NSString *message, NSError *error) {}]; | ||
FBSnapshotVerifyView(_window, popTestName); | ||
} | ||
|
||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#import <Foundation/Foundation.h> | ||
#import <ReactNativeNavigation/RNNCommandsHandler.h> | ||
|
||
@interface CommandsHandlerCreator : NSObject | ||
|
||
+ (RNNCommandsHandler *)createWithWindow:(UIWindow *)window; | ||
|
||
@end |
38 changes: 38 additions & 0 deletions
38
playground/ios/SnapshotTests/Utils/CommandsHandlerCreator.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#import "CommandsHandlerCreator.h" | ||
#import "RNNTestRootViewCreator.h" | ||
#import <ReactNativeNavigation/RNNEventEmitter.h> | ||
#import <ReactNativeNavigation/RNNOverlayManager.h> | ||
#import <ReactNativeNavigation/RNNModalManager.h> | ||
#import <ReactNativeNavigation/RNNControllerFactory.h> | ||
|
||
@implementation CommandsHandlerCreator | ||
|
||
+ (RNNCommandsHandler *)createWithWindow:(UIWindow *)window { | ||
RNNTestRootViewCreator* creator = [RNNTestRootViewCreator new]; | ||
RNNEventEmitter* eventEmmiter = [RNNEventEmitter new]; | ||
RNNOverlayManager* overlayManager = [RNNOverlayManager new]; | ||
RNNModalManager* modalManager = [RNNModalManager new]; | ||
RNNControllerFactory* controllerFactory = [[RNNControllerFactory alloc] initWithRootViewCreator:creator eventEmitter:eventEmmiter store:nil componentRegistry:nil andBridge:nil bottomTabsAttachModeFactory:[BottomTabsAttachModeFactory new]]; | ||
RNNCommandsHandler* commandsHandler = [[RNNCommandsHandler alloc] initWithControllerFactory:controllerFactory eventEmitter:eventEmmiter modalManager:modalManager overlayManager:overlayManager mainWindow:window]; | ||
[commandsHandler setReadyToReceiveCommands:YES]; | ||
[commandsHandler setDefaultOptions:@{ | ||
@"animations": @{ | ||
@"push": @{ | ||
@"enabled": @(0) | ||
}, | ||
@"pop": @{ | ||
@"enabled": @(0) | ||
} | ||
}, | ||
@"topBar": @{ | ||
@"drawBehind": @(1) | ||
}, | ||
@"layout": @{ | ||
@"componentBackgroundColor": @(0xFF00FF00) | ||
} | ||
} completion:^{}]; | ||
|
||
return commandsHandler; | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#import <Foundation/Foundation.h> | ||
|
||
@interface LayoutCreator : NSObject | ||
|
||
+ (NSDictionary *)component:(NSString *)componentId options:(NSDictionary *)options; | ||
|
||
+ (NSDictionary *)parentWithID:(NSString *)componentId type:(NSString *)type options:(NSDictionary *)options children:(NSArray<NSDictionary *> *)children; | ||
|
||
+ (NSDictionary *)stack:(NSDictionary *)options children:(NSArray<NSDictionary *> *)children; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#import "LayoutCreator.h" | ||
|
||
@implementation LayoutCreator | ||
|
||
+ (NSDictionary *)component:(NSString *)componentId options:(NSDictionary *)options { | ||
return @{ | ||
@"type": @"Component", | ||
@"id": componentId, | ||
@"data": @{ | ||
@"options": options | ||
} | ||
}; | ||
} | ||
|
||
+ (NSDictionary *)parentWithID:(NSString *)componentId type:(NSString *)type options:(NSDictionary *)options children:(NSArray<NSDictionary *> *)children { | ||
return @{ | ||
@"type": type, | ||
@"id": componentId, | ||
@"data": @{ | ||
@"options": options | ||
}, | ||
@"children": children | ||
}; | ||
} | ||
|
||
+ (NSDictionary *)stack:(NSDictionary *)options children:(NSArray<NSDictionary *> *)children { | ||
return @{ | ||
@"type": @"Stack", | ||
@"id": @"StackID", | ||
@"data": @{ | ||
@"options": options | ||
}, | ||
@"children": children | ||
}; | ||
} | ||
|
||
@end |
Oops, something went wrong.