Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions tools/valdi_web_devtools/test_utils/test_runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ function run(config) {
'--testMatch', '**/tests/**/*.integration.test.js',
'--runInBand',
'--verbose',
'--watchman=false',
'--haste',
'{"enableSymlinks":true}',
], {
cwd: process.cwd(),
env: { ...process.env, PUPPETEER_EXECUTABLE_PATH: chromePath, BASE_URL: `http://localhost:${port}` },
Expand Down
261 changes: 0 additions & 261 deletions valdi/test/integration/Runtime_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6719,267 +6719,6 @@ TEST_P(RuntimeFixture, inlineViewAttachmentSizeProviderTracksChildLayoutChanges)
ASSERT_GT(labelView->getInvalidateLayoutCount(), invalidateLayoutCountBeforeSizeChange);
}

static Ref<TextAttributeValue> getTextAttributeValueFromNode(ViewNode* viewNode) {
auto view = StandaloneView::unwrap(viewNode->getView());
EXPECT_TRUE(view != nullptr);
if (view == nullptr) {
return nullptr;
}

auto value = view->getAttribute(STRING_LITERAL("value"));
EXPECT_EQ(ValueType::ValdiObject, value.getType());
auto attributedText = value.getTypedRef<TextAttributeValue>();
EXPECT_TRUE(attributedText != nullptr);
return attributedText;
}

static std::vector<Ref<TextInlineAttachment>> getInlineViewAttachments(const Ref<TextAttributeValue>& attributedText) {
std::vector<Ref<TextInlineAttachment>> attachments;
if (attributedText == nullptr) {
return attachments;
}

for (size_t i = 0; i < attributedText->getPartsSize(); i++) {
const auto& attachment = attributedText->getStyleAtIndex(i).inlineViewAttachment;
if (attachment != nullptr) {
attachments.push_back(attachment);
}
}
return attachments;
}

static Value inlineViewDynamicSizeViewModel(double width, double height) {
return Value().setMapValue("childWidth", Value(width)).setMapValue("childHeight", Value(height));
}

TEST_P(RuntimeFixture, supportsManagedChildFrameViewClasses) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("ManagedChildFrameView"),
true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("ManagedChildFrames@test/src/ManagedChildFrames"), Value(), Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto managedNodes = findViewNodesWithId(tree->getRootViewNode(), "managed");
auto childNodes = findViewNodesWithId(tree->getRootViewNode(), "managedChild");
ASSERT_EQ(static_cast<size_t>(1), managedNodes.size());
ASSERT_EQ(static_cast<size_t>(1), childNodes.size());

auto* managedNode = managedNodes[0];
auto* childNode = childNodes[0];
ASSERT_TRUE(managedNode->managesChildFrames());
ASSERT_TRUE(childNode->parentManagesChildFrames());
ASSERT_EQ(YGPositionTypeAbsolute, YGNodeStyleGetPositionType(childNode->getYogaNode()));
ASSERT_EQ(Frame(10, 0, 30, 20), childNode->getCalculatedFrame());

auto childView = StandaloneView::unwrap(childNode->getView());
ASSERT_TRUE(childView != nullptr);
ASSERT_EQ(Frame(), childView->getFrame());
}

TEST_P(RuntimeFixture, resolvesInlineViewAttachmentsFromTextChildren) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("SCValdiLabel"), true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("InlineViewTextAttribute@test/src/ManagedChildFrames"), Value(), Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto labelNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineLabel");
auto childNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineChild");
ASSERT_EQ(static_cast<size_t>(1), labelNodes.size());
ASSERT_EQ(static_cast<size_t>(1), childNodes.size());

auto* labelNode = labelNodes[0];
auto* childNode = childNodes[0];
ASSERT_TRUE(labelNode->managesChildFrames());
ASSERT_TRUE(childNode->parentManagesChildFrames());
ASSERT_EQ(Frame(0, 0, 18, 12), childNode->getCalculatedFrame());

auto labelView = StandaloneView::unwrap(labelNode->getView());
ASSERT_TRUE(labelView != nullptr);

auto value = labelView->getAttribute(STRING_LITERAL("value"));
ASSERT_EQ(ValueType::ValdiObject, value.getType());

auto attributedText = value.getTypedRef<TextAttributeValue>();
ASSERT_TRUE(attributedText != nullptr);
ASSERT_EQ(static_cast<size_t>(3), attributedText->getPartsSize());
ASSERT_EQ(STRING_LITERAL("Before "), attributedText->getContentAtIndex(0));
ASSERT_EQ(STRING_LITERAL(" after"), attributedText->getContentAtIndex(2));

const auto& inlineStyle = attributedText->getStyleAtIndex(1);
ASSERT_TRUE(inlineStyle.inlineViewAttachment != nullptr);
ASSERT_EQ(static_cast<size_t>(0), inlineStyle.inlineViewAttachment->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Bottom, inlineStyle.inlineViewAttachment->getVerticalAlignment());
ASSERT_EQ(Size(18, 12), inlineStyle.inlineViewAttachment->getSize());

auto childView = StandaloneView::unwrap(childNode->getView());
ASSERT_TRUE(childView != nullptr);
ASSERT_EQ(Frame(), childView->getFrame());
}

TEST_P(RuntimeFixture, resolvesInlineViewVerticalAlignmentEnumValuesFromTS) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("SCValdiLabel"), true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("InlineViewVerticalAlignmentTextAttribute@test/src/ManagedChildFrames"), Value(), Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto labelNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineLabel");
auto topNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineTop");
auto centerNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineCenter");
auto bottomNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineBottom");
auto baselineNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineBaseline");
ASSERT_EQ(static_cast<size_t>(1), labelNodes.size());
ASSERT_EQ(static_cast<size_t>(1), topNodes.size());
ASSERT_EQ(static_cast<size_t>(1), centerNodes.size());
ASSERT_EQ(static_cast<size_t>(1), bottomNodes.size());
ASSERT_EQ(static_cast<size_t>(1), baselineNodes.size());

auto* labelNode = labelNodes[0];
ASSERT_TRUE(labelNode->managesChildFrames());
ASSERT_TRUE(topNodes[0]->parentManagesChildFrames());
ASSERT_TRUE(centerNodes[0]->parentManagesChildFrames());
ASSERT_TRUE(bottomNodes[0]->parentManagesChildFrames());
ASSERT_TRUE(baselineNodes[0]->parentManagesChildFrames());

ASSERT_EQ(Frame(0, 0, 11, 12), topNodes[0]->getCalculatedFrame());
ASSERT_EQ(Frame(0, 0, 22, 24), centerNodes[0]->getCalculatedFrame());
ASSERT_EQ(Frame(0, 0, 33, 36), bottomNodes[0]->getCalculatedFrame());
ASSERT_EQ(Frame(0, 0, 44, 14), baselineNodes[0]->getCalculatedFrame());

auto attributedText = getTextAttributeValueFromNode(labelNode);
ASSERT_TRUE(attributedText != nullptr);
ASSERT_EQ(static_cast<size_t>(9), attributedText->getPartsSize());
ASSERT_EQ(STRING_LITERAL("A"), attributedText->getContentAtIndex(0));
ASSERT_EQ(STRING_LITERAL("B"), attributedText->getContentAtIndex(2));
ASSERT_EQ(STRING_LITERAL("C"), attributedText->getContentAtIndex(4));
ASSERT_EQ(STRING_LITERAL("D"), attributedText->getContentAtIndex(6));
ASSERT_EQ(STRING_LITERAL("E"), attributedText->getContentAtIndex(8));

auto attachments = getInlineViewAttachments(attributedText);
ASSERT_EQ(static_cast<size_t>(4), attachments.size());
ASSERT_EQ(static_cast<size_t>(0), attachments[0]->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Top, attachments[0]->getVerticalAlignment());
ASSERT_EQ(Size(11, 12), attachments[0]->getSize());
ASSERT_EQ(static_cast<size_t>(1), attachments[1]->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Center, attachments[1]->getVerticalAlignment());
ASSERT_EQ(Size(22, 24), attachments[1]->getSize());
ASSERT_EQ(static_cast<size_t>(2), attachments[2]->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Bottom, attachments[2]->getVerticalAlignment());
ASSERT_EQ(Size(33, 36), attachments[2]->getSize());
ASSERT_EQ(static_cast<size_t>(3), attachments[3]->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Baseline, attachments[3]->getVerticalAlignment());
ASSERT_EQ(Size(44, 14), attachments[3]->getSize());
}

TEST_P(RuntimeFixture, resolvesInlineViewAttachmentsForTextViewChildren) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("SCValdiTextView"), true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("InlineViewTextViewAttribute@test/src/ManagedChildFrames"), Value(), Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto textViewNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineTextView");
auto childNodes = findViewNodesWithId(tree->getRootViewNode(), "textViewInlineChild");
ASSERT_EQ(static_cast<size_t>(1), textViewNodes.size());
ASSERT_EQ(static_cast<size_t>(1), childNodes.size());

auto* textViewNode = textViewNodes[0];
auto* childNode = childNodes[0];
ASSERT_TRUE(textViewNode->managesChildFrames());
ASSERT_TRUE(childNode->parentManagesChildFrames());
ASSERT_EQ(YGPositionTypeAbsolute, YGNodeStyleGetPositionType(childNode->getYogaNode()));
ASSERT_EQ(Frame(0, 0, 26, 16), childNode->getCalculatedFrame());

auto attributedText = getTextAttributeValueFromNode(textViewNode);
auto attachments = getInlineViewAttachments(attributedText);
ASSERT_EQ(static_cast<size_t>(1), attachments.size());
ASSERT_EQ(static_cast<size_t>(0), attachments[0]->getChildIndex());
ASSERT_EQ(InlineViewVerticalAlignment::Top, attachments[0]->getVerticalAlignment());
ASSERT_EQ(Size(26, 16), attachments[0]->getSize());

auto childView = StandaloneView::unwrap(childNode->getView());
ASSERT_TRUE(childView != nullptr);
ASSERT_EQ(Frame(), childView->getFrame());
}

TEST_P(RuntimeFixture, rejectsInvalidInlineViewChildIndexesFromTSAttributedText) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("SCValdiLabel"), true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("InlineViewInvalidChildIndexAttribute@test/src/ManagedChildFrames"), Value(), Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto labelNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineLabel");
auto childNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineChild");
ASSERT_EQ(static_cast<size_t>(1), labelNodes.size());
ASSERT_EQ(static_cast<size_t>(1), childNodes.size());
ASSERT_TRUE(labelNodes[0]->managesChildFrames());
ASSERT_TRUE(childNodes[0]->parentManagesChildFrames());

auto labelView = StandaloneView::unwrap(labelNodes[0]->getView());
ASSERT_TRUE(labelView != nullptr);
ASSERT_TRUE(labelView->getAttribute(STRING_LITERAL("value")).isUndefined());
}

TEST_P(RuntimeFixture, inlineViewAttachmentSizeProviderTracksChildLayoutChanges) {
wrapper.standaloneRuntime->getViewManager().setManagesChildFramesForClass(STRING_LITERAL("SCValdiLabel"), true);

auto tree = wrapper.createViewNodeTreeAndContext(
STRING_LITERAL("InlineViewDynamicSizeAttribute@test/src/ManagedChildFrames"),
inlineViewDynamicSizeViewModel(18, 12),
Value());

wrapper.waitUntilAllUpdatesCompleted();
tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto labelNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineLabel");
auto childNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineChild");
ASSERT_EQ(static_cast<size_t>(1), labelNodes.size());
ASSERT_EQ(static_cast<size_t>(1), childNodes.size());
ASSERT_EQ(Frame(0, 0, 18, 12), childNodes[0]->getCalculatedFrame());

auto attributedText = getTextAttributeValueFromNode(labelNodes[0]);
auto attachments = getInlineViewAttachments(attributedText);
ASSERT_EQ(static_cast<size_t>(1), attachments.size());
auto attachment = attachments[0];
ASSERT_EQ(Size(18, 12), attachment->getSize());

auto labelView = StandaloneView::unwrap(labelNodes[0]->getView());
ASSERT_TRUE(labelView != nullptr);
auto invalidateLayoutCountBeforeSizeChange = labelView->getInvalidateLayoutCount();

wrapper.setViewModel(tree->getContext(), inlineViewDynamicSizeViewModel(31, 17));
wrapper.waitUntilAllUpdatesCompleted();

ASSERT_EQ(Frame(0, 0, 31, 17), childNodes[0]->getCalculatedFrame());
ASSERT_EQ(Size(31, 17), attachment->getSize());

tree->setLayoutSpecs(Size(200, 200), LayoutDirectionLTR);

auto updatedChildNodes = findViewNodesWithId(tree->getRootViewNode(), "inlineChild");
ASSERT_EQ(static_cast<size_t>(1), updatedChildNodes.size());
ASSERT_EQ(Frame(0, 0, 31, 17), updatedChildNodes[0]->getCalculatedFrame());
ASSERT_EQ(Size(31, 17), attachment->getSize());

auto updatedAttributedText = getTextAttributeValueFromNode(labelNodes[0]);
auto updatedAttachments = getInlineViewAttachments(updatedAttributedText);
ASSERT_EQ(static_cast<size_t>(1), updatedAttachments.size());
ASSERT_EQ(Size(31, 17), updatedAttachments[0]->getSize());
ASSERT_GT(labelView->getInvalidateLayoutCount(), invalidateLayoutCountBeforeSizeChange);
}

TEST_P(RuntimeFixture, supportsAccesibilityValueInTextAttribute) {
auto tree =
wrapper.createViewNodeTreeAndContext(STRING_LITERAL("TextAttribute@test/src/TextAttribute"), Value(), Value());
Expand Down
Loading