From c03a6aba49e8ce360e52bc6fb8e858cd8a9d2c82 Mon Sep 17 00:00:00 2001 From: Jiayan Zhuang Date: Mon, 27 Jul 2020 15:35:29 -0700 Subject: [PATCH] Setup the ShadowNode tree for RCTParagraphComponentViewTests (#29470) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/29470 Changelog: [Internal] - Build the framework of the RCTParagraphComponentViewTests and do some setup. I built a shadowNode tree here for future tests. Reviewed By: shergin Differential Revision: D22536626 fbshipit-source-id: c74b63b3319693b90c9d64b7f782a1a922b0d499 --- React-Core.podspec | 1 + React/React-RCTFabric.podspec | 3 +- .../Text/RCTParagraphComponentViewTests.mm | 311 ++++++++++++++++++ 3 files changed, 314 insertions(+), 1 deletion(-) create mode 100644 React/Tests/Text/RCTParagraphComponentViewTests.mm diff --git a/React-Core.podspec b/React-Core.podspec index 94a4dea3c46..62529fb9fce 100644 --- a/React-Core.podspec +++ b/React-Core.podspec @@ -57,6 +57,7 @@ Pod::Spec.new do |s| ss.exclude_files = "React/CoreModules/**/*", "React/DevSupport/**/*", "React/Fabric/**/*", + "React/Tests/**/*", "React/Inspector/**/*" ss.ios.exclude_files = "React/**/RCTTV*.*" ss.tvos.exclude_files = "React/Modules/RCTClipboard*", diff --git a/React/React-RCTFabric.podspec b/React/React-RCTFabric.podspec index 9123da76ec7..139a51e6940 100644 --- a/React/React-RCTFabric.podspec +++ b/React/React-RCTFabric.podspec @@ -30,7 +30,8 @@ Pod::Spec.new do |s| s.author = "Facebook, Inc. and its affiliates" s.platforms = { :ios => "10.0", :tvos => "10.0" } s.source = source - s.source_files = "Fabric/**/*.{c,h,m,mm,S,cpp}" + s.source_files = "Fabric/**/*.{c,h,m,mm,S,cpp}", + "Tests/**/*.{mm}" s.exclude_files = "**/tests/*", "**/android/*", s.compiler_flags = folly_compiler_flags + ' ' + boost_compiler_flags diff --git a/React/Tests/Text/RCTParagraphComponentViewTests.mm b/React/Tests/Text/RCTParagraphComponentViewTests.mm new file mode 100644 index 00000000000..6ebaa41b471 --- /dev/null +++ b/React/Tests/Text/RCTParagraphComponentViewTests.mm @@ -0,0 +1,311 @@ +/* + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import +#import + +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import +#import + +@interface RCTParagraphComponentAccessibilityProviderTests : XCTestCase + +@end + +using namespace facebook::react; + +//┌── RootShadowNode ─────────────────────────────┐ +//│ │ +//│┌─── ParagraphShadowNodeA ─────────────────────────┐ │ +//││ ┌─AA(AAA) ─────────┐ ┌─AB(ABA) ─┐ ┌─AC(ACA)────┐ │ │ +//││ │ Please check out │ │ Facebook │ │ and │ │ │ +//││ └──────────────────┘ └──────────┘ └────────────┘ │ │ +//││ ┌─AD(ADA) ──┐ ┌──AE(AEA) ──────────────────────┐ │ │ +//││ │ Instagram │ │ for a full description. │ │ │ +//││ └───────────┘ └────────────────────────────────┘ │ │ +//│└──────────────────────────────────────────────────┘ │ +//│ │ +//│ │ +//│┌── ParagraphShadowNodeB ──────────────────────────┐ │ +//││ ┌───BA(BAA) ───────────────────────────────────┐ │ │ +//││ │ Lorem ipsum dolor sit amet, consectetur │ │ │ +//││ │ adipiscing elit. Maecenas ut risus et sapien │ │ │ +//││ │ bibendum volutpat. Nulla facilisi. Cras │ │ │ +//││ │ imperdiet gravida tincidunt. │ │ │ +//││ └──────────────────────────────────────────────┘ │ │ +//││ ┌─BB(BBA) ─────────────────────────────────────┐ │ │ +//││ │ In tempor, tellus et vestibulum venenatis, │ │ │ +//││ │ lorem nunc eleifend lectus, a consectetur │ │ │ +//││ │ magna augue at arcu. │ │ │ +//││ └──────────────────────────────────────────────┘ │ │ +//│└──────────────────────────────────────────────────┘ │ +//│ │ +//│┌── ParagraphShadowNodeC ──────────────────────────┐ │ +//││ ┌─CA(CAA) ────────┐ │ │ +//││ │ Lorem ipsum │ │ │ +//││ └─────────────────┘ │ │ +//││ ┌─CB(CBA) ─────────────────────────────────────┐ │ │ +//││ │ dolor sit amet, consectetur adipiscing elit. │ │ │ +//││ │Maecenas ut risus et sapien bibendum volutpat.│ │ │ +//││ │ Nulla facilisi. Cras imperdiet gravida │ │ │ +//││ │ tincidunt. In tempor, tellus et vestibulum │ │ │ +//││ │ venenatis, lorem nunc eleifend lectus, a │ │ │ +//││ │ consectetur magna augue at arcu. │ │ │ +//││ └──────────────────────────────────────────────┘ │ │ +//││ ┌─CC(CCA) ────────┐ │ │ +//││ │ See Less │ │ │ +//││ └─────────────────┘ │ │ +//│└──────────────────────────────────────────────────┘ │ +//│ │ +//└─────────────────────────────────────────────────────┘ + +@implementation RCTParagraphComponentAccessibilityProviderTests { + std::shared_ptr builder_; + std::shared_ptr rootShadowNode_; + std::shared_ptr ParagrahShadowNodeA_; + std::shared_ptr ParagrahShadowNodeB_; + std::shared_ptr ParagrahShadowNodeC_; + std::shared_ptr TextShadowNodeAA_; + std::shared_ptr TextShadowNodeAB_; + std::shared_ptr TextShadowNodeAC_; + std::shared_ptr TextShadowNodeAD_; + std::shared_ptr TextShadowNodeAE_; + std::shared_ptr TextShadowNodeBA_; + std::shared_ptr TextShadowNodeBB_; + std::shared_ptr TextShadowNodeCA_; + std::shared_ptr TextShadowNodeCB_; + std::shared_ptr TextShadowNodeCC_; + std::shared_ptr RawTextShadowNodeAAA_; + std::shared_ptr RawTextShadowNodeABA_; + std::shared_ptr RawTextShadowNodeACA_; + std::shared_ptr RawTextShadowNodeADA_; + std::shared_ptr RawTextShadowNodeAEA_; + std::shared_ptr RawTextShadowNodeBAA_; + std::shared_ptr RawTextShadowNodeBBA_; + std::shared_ptr RawTextShadowNodeCAA_; + std::shared_ptr RawTextShadowNodeCBA_; + std::shared_ptr RawTextShadowNodeCCA_; +} + +- (void)setUp +{ + [super setUp]; + builder_ = std::make_shared((simpleComponentBuilder())); + auto element = + Element() + .reference(rootShadowNode_) + .tag(1) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.layoutConstraints = LayoutConstraints{{0, 0}, {500, 500}}; + auto &yogaStyle = props.yogaStyle; + yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionHeight] = YGValue{200, YGUnitPoint}; + return sharedProps; + }) + .children({ + Element() + .reference(ParagrahShadowNodeA_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + auto &yogaStyle = props.yogaStyle; + yogaStyle.positionType() = YGPositionTypeAbsolute; + yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint}; + yogaStyle.position()[YGEdgeTop] = YGValue{0, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionHeight] = YGValue{20, YGUnitPoint}; + return sharedProps; + }) + .children({ + Element() + .reference(TextShadowNodeAA_) + .props([] { + auto sharedProps = std::make_shared(); + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeAAA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = "Please check out "; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeAB_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.textAttributes.accessibilityRole = AccessibilityRole::Link; + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeABA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = "facebook"; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeAC_) + .props([] { + auto sharedProps = std::make_shared(); + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeACA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = " and "; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeAD_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.textAttributes.accessibilityRole = AccessibilityRole::Link; + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeADA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = "instagram"; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeAE_) + .props([] { + auto sharedProps = std::make_shared(); + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeAEA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = " for a full description."; + return sharedProps; + })}), + }), + Element() + .reference(ParagrahShadowNodeB_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + auto &yogaStyle = props.yogaStyle; + yogaStyle.positionType() = YGPositionTypeAbsolute; + yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint}; + yogaStyle.position()[YGEdgeTop] = YGValue{30, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionHeight] = YGValue{50, YGUnitPoint}; + return sharedProps; + }) + .children({ + Element() + .reference(TextShadowNodeBA_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.textAttributes.accessibilityRole = AccessibilityRole::Link; + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeBAA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = + "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ut risus et sapien bibendum volutpat. Nulla facilisi. Cras imperdiet gravida tincidunt. "; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeBB_) + .props([] { + auto sharedProps = std::make_shared(); + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeBBA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = + "In tempor, tellus et vestibulum venenatis, lorem nunc eleifend lectus, a consectetur magna augue at arcu."; + return sharedProps; + })}), + }), + Element() + .reference(ParagrahShadowNodeC_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + auto &yogaStyle = props.yogaStyle; + yogaStyle.positionType() = YGPositionTypeAbsolute; + yogaStyle.position()[YGEdgeLeft] = YGValue{0, YGUnitPoint}; + yogaStyle.position()[YGEdgeTop] = YGValue{90, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionWidth] = YGValue{200, YGUnitPoint}; + yogaStyle.dimensions()[YGDimensionHeight] = YGValue{50, YGUnitPoint}; + return sharedProps; + }) + .children({ + Element() + .reference(TextShadowNodeCA_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.textAttributes.accessibilityRole = AccessibilityRole::Link; + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeCAA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = "Lorem ipsum"; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeCB_) + .props([] { + auto sharedProps = std::make_shared(); + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeCBA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = + " dolor sit amet, consectetur adipiscing elit. Maecenas ut risus et sapien bibendum volutpat. Nulla facilisi. Cras imperdiet gravida tincidunt. In tempor, tellus et vestibulum venenatis, lorem nunc eleifend lectus, a consectetur magna augue at arcu. "; + return sharedProps; + })}), + Element() + .reference(TextShadowNodeCC_) + .props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.textAttributes.accessibilityRole = AccessibilityRole::Button; + return sharedProps; + }) + .children({Element().reference(RawTextShadowNodeCCA_).props([] { + auto sharedProps = std::make_shared(); + auto &props = *sharedProps; + props.text = "See Less"; + return sharedProps; + })}), + }), + }); + builder_->build(element); + rootShadowNode_->layoutIfNeeded(); +} + +@end