mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-24 04:16:00 +08:00
RCTRootView integration tests
Reviewed By: javache Differential Revision: D2631527 fb-gh-sync-id: 377471d9e8546d7c05a045286a6ef7c5277ded16
This commit is contained in:
committed by
facebook-github-bot-0
parent
2faf8632d3
commit
0d17d6a8c0
@@ -50,8 +50,9 @@
|
||||
14D6D7281B2222EF001FB087 /* libRCTWebSocket.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 139FDED91B0651EA00C62182 /* libRCTWebSocket.a */; };
|
||||
14D6D7291B2222EF001FB087 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14AADF041AC3DB95002390C9 /* libReact.a */; };
|
||||
14DC67F41AB71881001358AB /* libRCTPushNotification.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 14DC67F11AB71876001358AB /* libRCTPushNotification.a */; };
|
||||
272E6B3F1BEA849E001FCF37 /* UpdatePropertiesExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 272E6B3C1BEA849E001FCF37 /* UpdatePropertiesExampleView.m */; };
|
||||
27F441EC1BEBE5030039B79C /* FlexibleSizeExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F441E81BEBE5030039B79C /* FlexibleSizeExampleView.m */; };
|
||||
272E6B3F1BEA849E001FCF37 /* UpdatePropertiesExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 272E6B3C1BEA849E001FCF37 /* UpdatePropertiesExampleView.m */; settings = {ASSET_TAGS = (); }; };
|
||||
27F441EC1BEBE5030039B79C /* FlexibleSizeExampleView.m in Sources */ = {isa = PBXBuildFile; fileRef = 27F441E81BEBE5030039B79C /* FlexibleSizeExampleView.m */; settings = {ASSET_TAGS = (); }; };
|
||||
27B885561BED29AF00008352 /* RCTRootViewIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 27B885551BED29AF00008352 /* RCTRootViewIntegrationTests.m */; settings = {ASSET_TAGS = (); }; };
|
||||
3578590A1B28D2CF00341EDB /* libRCTLinking.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 357859011B28D2C500341EDB /* libRCTLinking.a */; };
|
||||
3D36915B1BDA8CBB007B22D8 /* uie_thumb_big.png in Resources */ = {isa = PBXBuildFile; fileRef = 3D36915A1BDA8CBB007B22D8 /* uie_thumb_big.png */; };
|
||||
3DB99D0C1BA0340600302749 /* UIExplorerIntegrationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB99D0B1BA0340600302749 /* UIExplorerIntegrationTests.m */; };
|
||||
@@ -228,6 +229,7 @@
|
||||
272E6B3C1BEA849E001FCF37 /* UpdatePropertiesExampleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = UpdatePropertiesExampleView.m; path = UIExplorer/NativeExampleViews/UpdatePropertiesExampleView.m; sourceTree = "<group>"; };
|
||||
27F441E81BEBE5030039B79C /* FlexibleSizeExampleView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FlexibleSizeExampleView.m; path = UIExplorer/NativeExampleViews/FlexibleSizeExampleView.m; sourceTree = "<group>"; };
|
||||
27F441EA1BEBE5030039B79C /* FlexibleSizeExampleView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = FlexibleSizeExampleView.h; path = UIExplorer/NativeExampleViews/FlexibleSizeExampleView.h; sourceTree = "<group>"; };
|
||||
27B885551BED29AF00008352 /* RCTRootViewIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTRootViewIntegrationTests.m; sourceTree = "<group>"; };
|
||||
357858F81B28D2C400341EDB /* RCTLinking.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTLinking.xcodeproj; path = ../../Libraries/LinkingIOS/RCTLinking.xcodeproj; sourceTree = "<group>"; };
|
||||
3D36915A1BDA8CBB007B22D8 /* uie_thumb_big.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = uie_thumb_big.png; path = UIExplorer/Images.xcassets/uie_thumb_big.imageset/uie_thumb_big.png; sourceTree = SOURCE_ROOT; };
|
||||
3DB99D0B1BA0340600302749 /* UIExplorerIntegrationTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = UIExplorerIntegrationTests.m; sourceTree = "<group>"; };
|
||||
@@ -434,6 +436,7 @@
|
||||
143BC5961B21E3E100462512 /* UIExplorerIntegrationTests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
27B885551BED29AF00008352 /* RCTRootViewIntegrationTests.m */,
|
||||
3DB99D0B1BA0340600302749 /* UIExplorerIntegrationTests.m */,
|
||||
143BC5A01B21E45C00462512 /* UIExplorerSnapshotTests.m */,
|
||||
83636F8E1B53F22C009F943E /* RCTUIManagerScenarioTests.m */,
|
||||
@@ -886,6 +889,7 @@
|
||||
3DB99D0C1BA0340600302749 /* UIExplorerIntegrationTests.m in Sources */,
|
||||
83636F8F1B53F22C009F943E /* RCTUIManagerScenarioTests.m in Sources */,
|
||||
143BC5A11B21E45C00462512 /* UIExplorerSnapshotTests.m in Sources */,
|
||||
27B885561BED29AF00008352 /* RCTRootViewIntegrationTests.m in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
/**
|
||||
* Copyright (c) 2015-present, Facebook, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This source code is licensed under the BSD-style license found in the
|
||||
* LICENSE file in the root directory of this source tree. An additional grant
|
||||
* of patent rights can be found in the PATENTS file in the same directory.
|
||||
*/
|
||||
|
||||
//vs
|
||||
|
||||
/**
|
||||
* The examples provided by Facebook are for non-commercial testing and
|
||||
* evaluation purposes only.
|
||||
*
|
||||
* Facebook reserves all rights not expressly granted.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
||||
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
||||
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import <XCTest/XCTest.h>
|
||||
|
||||
#import "RCTAssert.h"
|
||||
|
||||
#import "RCTEventDispatcher.h"
|
||||
#import "RCTRootView.h"
|
||||
#import "RCTRootViewDelegate.h"
|
||||
|
||||
#import <RCTTest/RCTTestRunner.h>
|
||||
|
||||
#define RCT_TEST_DATA_CONFIGURATION_BLOCK(appName, testType, input, block) \
|
||||
- (void)test##appName##_##testType##_##input \
|
||||
{ \
|
||||
[_runner runTest:_cmd \
|
||||
module:@#appName \
|
||||
initialProps:@{@#input:@YES} \
|
||||
configurationBlock:block]; \
|
||||
}
|
||||
|
||||
#define RCT_TEST_CONFIGURATION_BLOCK(appName, block) \
|
||||
- (void)test##appName \
|
||||
{ \
|
||||
[_runner runTest:_cmd \
|
||||
module:@#appName \
|
||||
initialProps:nil \
|
||||
configurationBlock:block]; \
|
||||
}
|
||||
|
||||
#define RCTNone RCTRootViewSizeFlexibilityNone
|
||||
#define RCTHeight RCTRootViewSizeFlexibilityHeight
|
||||
#define RCTWidth RCTRootViewSizeFlexibilityWidth
|
||||
#define RCTBoth RCTRootViewSizeFlexibilityWidthAndHeight
|
||||
|
||||
typedef void (^ControlBlock)(RCTRootView*);
|
||||
|
||||
@interface SizeFlexibilityTestDelegate : NSObject<RCTRootViewDelegate>
|
||||
@end
|
||||
|
||||
@implementation SizeFlexibilityTestDelegate
|
||||
|
||||
- (void)rootViewDidChangeIntrinsicSize:(RCTRootView *)rootView
|
||||
{
|
||||
[rootView.bridge.eventDispatcher sendAppEventWithName:@"rootViewDidChangeIntrinsicSize"
|
||||
body:@{@"width": @(rootView.intrinsicSize.width),
|
||||
@"height": @(rootView.intrinsicSize.height)}];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
static SizeFlexibilityTestDelegate *sizeFlexibilityDelegate()
|
||||
{
|
||||
static SizeFlexibilityTestDelegate *delegate;
|
||||
if (delegate == nil) {
|
||||
delegate = [SizeFlexibilityTestDelegate new];
|
||||
}
|
||||
|
||||
return delegate;
|
||||
}
|
||||
|
||||
static ControlBlock simpleSizeFlexibilityBlock(RCTRootViewSizeFlexibility sizeFlexibility)
|
||||
{
|
||||
return ^(RCTRootView *rootView){
|
||||
rootView.delegate = sizeFlexibilityDelegate();
|
||||
rootView.sizeFlexibility = sizeFlexibility;
|
||||
};
|
||||
}
|
||||
|
||||
static ControlBlock multipleSizeFlexibilityUpdatesBlock(RCTRootViewSizeFlexibility finalSizeFlexibility)
|
||||
{
|
||||
return ^(RCTRootView *rootView){
|
||||
|
||||
NSInteger arr[4] = {RCTNone,
|
||||
RCTHeight,
|
||||
RCTWidth,
|
||||
RCTBoth};
|
||||
|
||||
rootView.delegate = sizeFlexibilityDelegate();
|
||||
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
if (arr[i] != finalSizeFlexibility) {
|
||||
rootView.sizeFlexibility = arr[i];
|
||||
}
|
||||
}
|
||||
|
||||
rootView.sizeFlexibility = finalSizeFlexibility;
|
||||
};
|
||||
}
|
||||
|
||||
static ControlBlock reactContentSizeUpdateBlock(RCTRootViewSizeFlexibility sizeFlexibility)
|
||||
{
|
||||
return ^(RCTRootView *rootView){
|
||||
rootView.delegate = sizeFlexibilityDelegate();
|
||||
rootView.sizeFlexibility = sizeFlexibility;
|
||||
};
|
||||
}
|
||||
|
||||
static ControlBlock propertiesUpdateBlock()
|
||||
{
|
||||
return ^(RCTRootView *rootView){
|
||||
rootView.appProperties = @{@"markTestPassed":@YES};
|
||||
};
|
||||
}
|
||||
|
||||
@interface RCTRootViewIntegrationTests : XCTestCase
|
||||
|
||||
@end
|
||||
|
||||
@implementation RCTRootViewIntegrationTests
|
||||
{
|
||||
RCTTestRunner *_runner;
|
||||
}
|
||||
|
||||
- (void)setUp
|
||||
{
|
||||
#if __LP64__
|
||||
RCTAssert(NO, @"Tests should be run on 32-bit device simulators (e.g. iPhone 5)");
|
||||
#endif
|
||||
|
||||
NSOperatingSystemVersion version = [NSProcessInfo processInfo].operatingSystemVersion;
|
||||
RCTAssert((version.majorVersion == 8 && version.minorVersion >= 3) || version.majorVersion >= 9, @"Tests should be run on iOS 8.3+, found %zd.%zd.%zd", version.majorVersion, version.minorVersion, version.patchVersion);
|
||||
_runner = RCTInitRunnerForApp(@"IntegrationTests/RCTRootViewIntegrationTestApp", nil);
|
||||
}
|
||||
|
||||
#pragma mark Logic Tests
|
||||
|
||||
// This list should be kept in sync with RCTRootViewIntegrationTestApp.js
|
||||
|
||||
// Simple size flexibility tests - test if the content is measured properly
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, none, simpleSizeFlexibilityBlock(RCTNone));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, height, simpleSizeFlexibilityBlock(RCTHeight));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, width, simpleSizeFlexibilityBlock(RCTWidth));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, SingleUpdate, both, simpleSizeFlexibilityBlock(RCTBoth));
|
||||
|
||||
// Consider multiple size flexibility updates in a row. Test if the view's flexibility mode eventually is set to the expected value
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, MultipleUpdates, none, multipleSizeFlexibilityUpdatesBlock(RCTNone));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, MultipleUpdates, height, multipleSizeFlexibilityUpdatesBlock(RCTHeight));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, MultipleUpdates, width, multipleSizeFlexibilityUpdatesBlock(RCTWidth));
|
||||
RCT_TEST_DATA_CONFIGURATION_BLOCK(SizeFlexibilityUpdateTest, MultipleUpdates, both, multipleSizeFlexibilityUpdatesBlock(RCTBoth));
|
||||
|
||||
// Test if the 'rootViewDidChangeIntrinsicSize' delegate method is called after the RN app decides internally to resize
|
||||
RCT_TEST_CONFIGURATION_BLOCK(ReactContentSizeUpdateTest, reactContentSizeUpdateBlock(RCTBoth))
|
||||
|
||||
// Test if setting 'appProperties' property updates the RN app
|
||||
RCT_TEST_CONFIGURATION_BLOCK(PropertiesUpdateTest, propertiesUpdateBlock())
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user