Skip to content

Commit

Permalink
Add unit tests for RootShadowNode
Browse files Browse the repository at this point in the history
Summary:
Changelog: [internal]

Add unit tests to prevent bug with `RootShadowNode::clone`.

Reviewed By: mdvacca

Differential Revision: D28378456

fbshipit-source-id: 8564835e5dfe677b17111162ccad40d975615cf9
  • Loading branch information
sammy-SC authored and facebook-github-bot committed May 12, 2021
1 parent 52b45a4 commit b2dbde3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
1 change: 1 addition & 0 deletions ReactCommon/react/renderer/components/root/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,6 @@ fb_xplat_cxx_test(
":root",
"//xplat/folly:molly",
"//xplat/third-party/gmock:gtest",
react_native_xplat_target("react/renderer/element:element"),
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,38 @@
* LICENSE file in the root directory of this source tree.
*/

#include <memory>
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/element/ComponentBuilder.h>
#include <react/renderer/element/Element.h>
#include <react/renderer/element/testUtils.h>

#include <gtest/gtest.h>

TEST(RootShadowNodeTest, testSomething) {
// TODO
namespace facebook::react {

TEST(RootShadowNodeTest, cloneWithLayoutConstraints) {
auto builder = simpleComponentBuilder();
std::shared_ptr<RootShadowNode> rootShadowNode;
LayoutConstraints defaultLayoutConstraints = {};

auto element =
Element<RootShadowNode>().reference(rootShadowNode).tag(1).props([&] {
auto sharedProps = std::make_shared<RootProps>();
sharedProps->layoutConstraints = defaultLayoutConstraints;
return sharedProps;
});

builder.build(element);

EXPECT_FALSE(rootShadowNode->getIsLayoutClean());
EXPECT_TRUE(rootShadowNode->layoutIfNeeded());
EXPECT_TRUE(rootShadowNode->getIsLayoutClean());

auto clonedWithDiffentLayoutConstraints =
rootShadowNode->clone(LayoutConstraints{{0, 0}, {10, 10}}, {});

EXPECT_FALSE(clonedWithDiffentLayoutConstraints->getIsLayoutClean());
EXPECT_TRUE(clonedWithDiffentLayoutConstraints->layoutIfNeeded());
}

} // namespace facebook::react

0 comments on commit b2dbde3

Please sign in to comment.