mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
dd3a6eda70
Summary: This diff contains several tight to each other changes (which can/should not be split into several diffs): * The props parsing/conversion process was de-virtualized: we don't use virtual `apply` method to parse props anymore. Instead, we use old-fashioned constructors. * All fields of Props classes which represent props values were marked as `const` which make impossible to modify them after the objects were created (even if we have non-const value-of/pointer-to the whole Props object). Those fields are also `public` now. * All custom handwritten getters were removed (because we don't need them anymore). So, now we don't need all those custom getters which makes code much more compact, performant and codegen-friendly. Reviewed By: fkgozali Differential Revision: D7901245 fbshipit-source-id: 9f4b1fd2da64bf963b63215ed3bd74b9d3c58dd5
66 lines
2.4 KiB
C++
66 lines
2.4 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>();
|
|
|
|
ASSERT_EQ(descriptor->getComponentHandle(), typeid(TestShadowNode).hash_code());
|
|
ASSERT_STREQ(descriptor->getComponentName().c_str(), "Test");
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(9, 1, (void *)NULL, props);
|
|
|
|
ASSERT_EQ(node->getComponentHandle(), typeid(TestShadowNode).hash_code());
|
|
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>();
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node = descriptor->createShadowNode(9, 1, (void *)NULL, props);
|
|
SharedShadowNode cloned = descriptor->cloneShadowNode(node);
|
|
|
|
ASSERT_EQ(cloned->getComponentHandle(), typeid(TestShadowNode).hash_code());
|
|
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>();
|
|
|
|
RawProps raw;
|
|
raw["nativeID"] = "abc";
|
|
SharedProps props = descriptor->cloneProps(nullptr, raw);
|
|
SharedShadowNode node1 = descriptor->createShadowNode(1, 1, (void *)NULL, props);
|
|
SharedShadowNode node2 = descriptor->createShadowNode(2, 1, (void *)NULL, props);
|
|
SharedShadowNode node3 = descriptor->createShadowNode(3, 1, (void *)NULL, 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);
|
|
}
|