mirror of
https://github.com/status-im/react-native.git
synced 2025-01-22 15:29:07 +00:00
67a79010ca
Summary: @public Previously, all ConcreteShadowNode subclasses had to override `getComponentName()` function to specialize a name of the component. And often it was all that those subclasses do. Now, it's a template argument; and many ShadowNode classes can be created as oneliners via *just* specializing ConcreteShadowNode template. Unfortunately, C++ does not allow to use `std::string`s or string literals as template arguments, but it allows to use pointers. Moreover, those pointers must point to some linked data, hence, those values must be declared in .cpp (not .h) files. For simplicity, we put those constants in Props classes, (but this is not a strong requirement). Reviewed By: mdvacca Differential Revision: D8942826 fbshipit-source-id: 4fd517e2485eb8f8c20a51df9b3496941856d8a5
67 lines
2.6 KiB
C++
67 lines
2.6 KiB
C++
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* 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) {
|
|
SharedComponentDescriptor descriptor = std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
ASSERT_EQ(descriptor->getComponentHandle(), TestShadowNode::Handle());
|
|
ASSERT_STREQ(descriptor->getComponentName().c_str(), TestShadowNode::Name().c_str());
|
|
ASSERT_STREQ(descriptor->getComponentName().c_str(), "Test");
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(9, 1, descriptor->createEventEmitter(0, 9), props);
|
|
|
|
ASSERT_EQ(node->getComponentHandle(), TestShadowNode::Handle());
|
|
ASSERT_STREQ(node->getComponentName().c_str(), TestShadowNode::Name().c_str());
|
|
ASSERT_STREQ(node->getComponentName().c_str(), "Test");
|
|
ASSERT_EQ(node->getTag(), 9);
|
|
ASSERT_EQ(node->getRootTag(), 1);
|
|
ASSERT_STREQ(node->getProps()->nativeId.c_str(), "abc");
|
|
}
|
|
|
|
TEST(ComponentDescriptorTest, cloneShadowNode) {
|
|
SharedComponentDescriptor descriptor = std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(9, 1, descriptor->createEventEmitter(0, 9), props);
|
|
SharedShadowNode cloned = descriptor->cloneShadowNode(node);
|
|
|
|
ASSERT_STREQ(cloned->getComponentName().c_str(), "Test");
|
|
ASSERT_EQ(cloned->getTag(), 9);
|
|
ASSERT_EQ(cloned->getRootTag(), 1);
|
|
ASSERT_STREQ(cloned->getProps()->nativeId.c_str(), "abc");
|
|
}
|
|
|
|
TEST(ComponentDescriptorTest, appendChild) {
|
|
SharedComponentDescriptor descriptor = std::make_shared<TestComponentDescriptor>(nullptr);
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node1 = descriptor->createShadowNode(1, 1, descriptor->createEventEmitter(0, 1), props);
|
|
SharedShadowNode node2 = descriptor->createShadowNode(2, 1, descriptor->createEventEmitter(0, 2), props);
|
|
SharedShadowNode node3 = descriptor->createShadowNode(3, 1, descriptor->createEventEmitter(0, 3), props);
|
|
|
|
descriptor->appendChild(node1, node2);
|
|
descriptor->appendChild(node1, node3);
|
|
|
|
SharedShadowNodeSharedList node1Children = node1->getChildren();
|
|
ASSERT_EQ(node1Children->size(), 2);
|
|
ASSERT_EQ(node1Children->at(0), node2);
|
|
ASSERT_EQ(node1Children->at(1), node3);
|
|
}
|