forked from facebook/react-native
-
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.
test RCTView with c swizzling example
Summary: writing a test that has an example of c swizzling in oss. testing this: https://www.internalfb.com/code/fbsource/[c58818169205f1e0fa816968efdb4c3fac8333e9]/xplat/js/react-native-github/React/Views/RCTView.m?lines=452-454%2C460-468 Changelog: [Internal] Reviewed By: RSNara Differential Revision: D31949237 fbshipit-source-id: f16c98ec1a736f3f2152d1e411b693083519a7b9
- Loading branch information
1 parent
8b24ce6
commit 7cece34
Showing
4 changed files
with
60 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#import <XCTest/XCTest.h> | ||
#import "OCMock/OCMock.h" | ||
|
||
#import <React/RCTAutoInsetsProtocol.h> | ||
#import <React/RCTMockDef.h> | ||
#import <React/RCTScrollView.h> | ||
#import <React/RCTView.h> | ||
#import <React/RCTViewUtils.h> | ||
|
||
RCT_MOCK_REF(RCTView, RCTContentInsets); | ||
|
||
UIEdgeInsets gContentInsets; | ||
static UIEdgeInsets RCTContentInsetsMock(UIView *view) | ||
{ | ||
return gContentInsets; | ||
} | ||
|
||
@interface RCTViewTests : XCTestCase | ||
@end | ||
|
||
@implementation RCTViewTests | ||
|
||
- (void)testAutoAdjustInsetsUpdateOffsetNo | ||
{ | ||
RCT_MOCK_SET(RCTView, RCTContentInsets, RCTContentInsetsMock); | ||
|
||
RCTScrollView *parentView = OCMClassMock([RCTScrollView class]); | ||
OCMStub([parentView contentInset]).andReturn(UIEdgeInsetsMake(1, 1, 1, 1)); | ||
OCMStub([parentView automaticallyAdjustContentInsets]).andReturn(YES); | ||
UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectZero]; | ||
|
||
gContentInsets = UIEdgeInsetsMake(1, 2, 3, 4); | ||
[RCTView autoAdjustInsetsForView:parentView withScrollView:scrollView updateOffset:NO]; | ||
|
||
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.contentInset, UIEdgeInsetsMake(2, 3, 4, 5))); | ||
XCTAssertTrue(UIEdgeInsetsEqualToEdgeInsets(scrollView.scrollIndicatorInsets, UIEdgeInsetsMake(2, 3, 4, 5))); | ||
|
||
RCT_MOCK_RESET(RCTView, RCTContentInsets); | ||
} | ||
|
||
@end |