Files
react-native/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp
T
Samuel SuslaandFacebook Github Bot 61f7639d38 Fabric: Remove eventEmitter from ShadowNodeFragment
Summary:
As part of the plan is splitting ShadowNodeFragment into two parts. ShadowNodeFamilyFragment is already in place. This diff removes use of `ShadowNodeFragment::eventEmitter` and goes over all call sites to change it to `ShadowNodeFamilyFragment::surfaceId`.
Changelog: [Internal]

Reviewed By: shergin

Differential Revision: D19146697

fbshipit-source-id: 22cae5404b0f3098feb86c0437a4aa256d5b773e
2019-12-19 13:48:22 -08:00

112 lines
3.8 KiB
C++

/*
* 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.
*/
#include <gtest/gtest.h>
#include "TestComponent.h"
using namespace facebook::react;
TEST(ComponentDescriptorTest, createShadowNode) {
auto eventDispatcher = std::shared_ptr<EventDispatcher const>();
SharedComponentDescriptor descriptor =
std::make_shared<TestComponentDescriptor>(eventDispatcher);
ASSERT_EQ(descriptor->getComponentHandle(), TestShadowNode::Handle());
ASSERT_STREQ(descriptor->getComponentName(), TestShadowNode::Name());
ASSERT_STREQ(descriptor->getComponentName(), "Test");
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node = descriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
ShadowNodeFamilyFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
ASSERT_EQ(node->getComponentHandle(), TestShadowNode::Handle());
ASSERT_STREQ(node->getComponentName(), TestShadowNode::Name());
ASSERT_STREQ(node->getComponentName(), "Test");
ASSERT_EQ(node->getTag(), 9);
ASSERT_EQ(node->getSurfaceId(), 1);
ASSERT_STREQ(node->getProps()->nativeId.c_str(), "abc");
}
TEST(ComponentDescriptorTest, cloneShadowNode) {
auto eventDispatcher = std::shared_ptr<EventDispatcher const>();
SharedComponentDescriptor descriptor =
std::make_shared<TestComponentDescriptor>(eventDispatcher);
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node = descriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
ShadowNodeFamilyFragment{
/* .tag = */ 9,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
SharedShadowNode cloned = descriptor->cloneShadowNode(*node, {});
ASSERT_STREQ(cloned->getComponentName(), "Test");
ASSERT_EQ(cloned->getTag(), 9);
ASSERT_EQ(cloned->getSurfaceId(), 1);
ASSERT_STREQ(cloned->getProps()->nativeId.c_str(), "abc");
}
TEST(ComponentDescriptorTest, appendChild) {
auto eventDispatcher = std::shared_ptr<EventDispatcher const>();
SharedComponentDescriptor descriptor =
std::make_shared<TestComponentDescriptor>(eventDispatcher);
const auto &raw = RawProps(folly::dynamic::object("nativeID", "abc"));
SharedProps props = descriptor->cloneProps(nullptr, raw);
SharedShadowNode node1 = descriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
ShadowNodeFamilyFragment{
/* .tag = */ 1,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
SharedShadowNode node2 = descriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
ShadowNodeFamilyFragment{
/* .tag = */ 2,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
SharedShadowNode node3 = descriptor->createShadowNode(
ShadowNodeFragment{
/* .props = */ props,
},
ShadowNodeFamilyFragment{
/* .tag = */ 3,
/* .surfaceId = */ 1,
/* .eventEmitter = */ descriptor->createEventEmitter(0, 9),
});
descriptor->appendChild(node1, node2);
descriptor->appendChild(node1, node3);
auto node1Children = node1->getChildren();
ASSERT_EQ(node1Children.size(), 2);
ASSERT_EQ(node1Children.at(0), node2);
ASSERT_EQ(node1Children.at(1), node3);
}