From 541b3f602f88f5b8366dd1b49aaef25f9c418121 Mon Sep 17 00:00:00 2001 From: zhanghang Date: Wed, 25 Jun 2025 20:44:19 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20tips=E5=88=86=E6=94=AF=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghang Change-Id: Ia6fa1bb6ff97ef1ce814466f8f5f9e707d46b8bf --- .../pattern/bubble/bubble_tips_test_ng.cpp | 137 ++++++++++++++++++ 1 file changed, 137 insertions(+) diff --git a/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp b/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp index 4375e845a2e..3510c9907d5 100755 --- a/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp +++ b/test/unittest/core/pattern/bubble/bubble_tips_test_ng.cpp @@ -337,6 +337,42 @@ HWTEST_F(BubbleTipsTestNg, ResetTipsMaxLines002, TestSize.Level1) EXPECT_NE(layoutProps->GetMaxLinesValue(0), DOUBLE); } +/** + * @tc.name: ResetTipsMaxLines003 + * @tc.desc: Test ResetTipsMaxLines. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, ResetTipsMaxLines003, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto param = CreateTipsParamForCursor(); + param->SetAnchorType(TipsAnchorType::TARGET); + auto tipsNode = CreateTipsNode(param, TIPS_MSG_1); + ASSERT_NE(tipsNode, nullptr); + auto bubbleProp = AceType::DynamicCast(tipsNode->GetLayoutProperty()); + bubbleProp->layoutConstraint_ = LayoutConstraintF(); + bubbleProp->contentConstraint_ = LayoutConstraintF(); + bubbleProp->UpdateShowAtAnchor(TipsAnchorType::TARGET); + + auto layoutAlgorithm = + AceType::DynamicCast(tipsNode->layoutAlgorithm_->GetLayoutAlgorithm()); + ASSERT_NE(layoutAlgorithm, nullptr); + const auto& children = tipsNode->GetAllChildrenWithBuild(); + auto childWrapper = children.front(); + ASSERT_NE(childWrapper, nullptr); + auto text = childWrapper->GetAllChildrenWithBuild().front(); + ASSERT_NE(text, nullptr); + auto layoutProps = AceType::DynamicCast(text->GetLayoutProperty()); + /** + * @tc.steps: step2. test ResetTipsMaxLines. + */ + layoutProps->UpdateMaxLines(DOUBLE); + layoutAlgorithm->Measure(AceType::RawPtr(tipsNode)); + EXPECT_NE(layoutProps->GetMaxLinesValue(0), DOUBLE); +} + /** * @tc.name: TipsFitAvailableRect001 * @tc.desc: Test FitAvailableRect for tips. @@ -864,4 +900,105 @@ HWTEST_F(BubbleTipsTestNg, MeasureTipsFollowTarget001, TestSize.Level1) layoutAlgorithm->MeasureTipsFollowTarget(childWrapper, childConstraint); EXPECT_TRUE(layoutProps->HasMaxLines()); } + +/** + * @tc.name: OnAttachToFrameNode001 + * @tc.desc: Test OnAttachToFrameNode. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, OnAttachToFrameNode001, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto targetNode = CreateTargetNode(); + auto id = targetNode->GetId(); + auto targetTag = targetNode->GetTag(); + auto popupId = ElementRegister::GetInstance()->MakeUniqueId(); + auto tipsNode = + FrameNode::CreateFrameNode(V2::POPUP_ETS_TAG, popupId, AceType::MakeRefPtr(id, targetTag)); + auto bubblePattern = tipsNode->GetPattern(); + ASSERT_NE(bubblePattern, nullptr); + auto eventHub = targetNode->GetEventHub(); + + /** + * @tc.steps: step2. expect onAreaChangedFunc add. + */ + EXPECT_TRUE(eventHub->onAreaChangedInnerCallbacks_.count(tipsNode->nodeId_)); + eventHub->onAreaChangedInnerCallbacks_[tipsNode->nodeId_]({}, {}, {}, {}); +} + +/** + * @tc.name: PopBubble001 + * @tc.desc: Test PopBubble. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, PopBubble001, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto targetNode = CreateTargetNode(); + auto id = targetNode->GetId(); + auto targetTag = targetNode->GetTag(); + auto popupId = ElementRegister::GetInstance()->MakeUniqueId(); + auto tipsNode = + FrameNode::CreateFrameNode(V2::POPUP_ETS_TAG, popupId, AceType::MakeRefPtr(id, targetTag)); + auto bubblePattern = tipsNode->GetPattern(); + ASSERT_NE(bubblePattern, nullptr); + auto overlayManager = MockPipelineContext::GetCurrent()->GetOverlayManager(); + PopupInfo popupInfo; + popupInfo.isCurrentOnShow = false; + overlayManager->UpdatePopupMap(id, popupInfo); + bubblePattern->PopBubble(); + + popupInfo.isCurrentOnShow = true; + overlayManager->UpdatePopupMap(id, popupInfo); + auto layoutProp = tipsNode->GetLayoutProperty(); + layoutProp->UpdateShowInSubWindow(true); + layoutProp->UpdateIsTips(true); + bubblePattern->PopBubble(); + + layoutProp->UpdateIsTips(false); + bubblePattern->PopBubble(); + + layoutProp->UpdateShowInSubWindow(false); + layoutProp->UpdateIsTips(true); + bubblePattern->PopBubble(); + + layoutProp->UpdateIsTips(false); + bubblePattern->PopBubble(); + EXPECT_EQ(overlayManager->GetPopupInfo(id).markNeedUpdate, false); +} + +/** + * @tc.name: PopBubble002 + * @tc.desc: Test PopBubble. + * @tc.type: FUNC + */ +HWTEST_F(BubbleTipsTestNg, PopBubble002, TestSize.Level1) +{ + /** + * @tc.steps: step1. create bubble and get frameNode. + */ + auto targetNode = CreateTargetNode(); + auto id = targetNode->GetId(); + auto targetTag = targetNode->GetTag(); + auto popupId = ElementRegister::GetInstance()->MakeUniqueId(); + auto tipsNode = + FrameNode::CreateFrameNode(V2::POPUP_ETS_TAG, popupId, AceType::MakeRefPtr(id, targetTag)); + auto bubblePattern = tipsNode->GetPattern(); + ASSERT_NE(bubblePattern, nullptr); + auto overlayManager = MockPipelineContext::GetCurrent()->GetOverlayManager(); + PopupInfo popupInfo; + popupInfo.isCurrentOnShow = true; + popupInfo.isTips = false; + overlayManager->UpdatePopupMap(id, popupInfo); + bubblePattern->PopBubble(true); + + popupInfo.isTips = true; + overlayManager->UpdatePopupMap(id, popupInfo); + bubblePattern->PopBubble(true); + EXPECT_EQ(overlayManager->GetPopupInfo(id).markNeedUpdate, false); +} } // namespace OHOS::Ace::NG -- Gitee