Additional differ test: flattening differ should not produce DELETE and CREATE mutation for the same tag in the same frame

Summary:
See additional assertion. Tests still pass, so no other change was necessary.

Changelog: [Internal]

Differential Revision: D23775553

fbshipit-source-id: 57d3191f25dd55ab4da189207f6d201a31b175e0
This commit is contained in:
Joshua Gross 2020-09-18 16:35:46 -07:00 коммит произвёл Facebook GitHub Bot
Родитель 03448715af
Коммит 752e709b51
1 изменённых файлов: 22 добавлений и 0 удалений

Просмотреть файл

@ -5,11 +5,14 @@
* LICENSE file in the root directory of this source tree.
*/
#include <vector>
#include <glog/logging.h>
#include <gtest/gtest.h>
#include <react/renderer/components/root/RootComponentDescriptor.h>
#include <react/renderer/components/view/ViewComponentDescriptor.h>
#include <react/renderer/mounting/ShadowViewMutation.h>
#include <react/renderer/mounting/Differentiator.h>
#include <react/renderer/mounting/stubs.h>
@ -102,6 +105,25 @@ static void testShadowNodeTreeLifeCycle(
auto mutations = calculateShadowViewMutations(
*currentRootNode, *nextRootNode, useFlattener);
// If using flattener: make sure that in a single frame, a DELETE for a view is not
// followed by a CREATE for the same view.
if (useFlattener) {
std::vector<int> deletedTags{};
for (auto const& mutation : mutations) {
if (mutation.type == ShadowViewMutation::Type::Delete) {
deletedTags.push_back(mutation.oldChildShadowView.tag);
}
}
for (auto const& mutation : mutations) {
if (mutation.type == ShadowViewMutation::Type::Create) {
if (std::find(deletedTags.begin(), deletedTags.end(), mutation.newChildShadowView.tag) != deletedTags.end()) {
LOG(ERROR) << "Deleted tag was recreated in mutations list: [" << mutation.newChildShadowView.tag << "]";
FAIL();
}
}
}
}
// Mutating the view tree.
viewTree.mutate(mutations);