• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "test/unittest/core/manager/drag_animation_helper_test_ng.h"
17 #include "core/components_ng/manager/drag_drop/drag_drop_func_wrapper.h"
18 #include "test/mock/base/mock_pixel_map.h"
19 #include "test/mock/core/common/mock_theme_manager.h"
20 
21 using namespace testing;
22 using namespace testing::ext;
23 
24 namespace OHOS::Ace::NG {
25 namespace {
26 constexpr size_t DEFAULT_CHILD_COUNT = 4;
27 constexpr float GRID_WIDTH = 480.0f;
28 constexpr float GRID_HEIGHT = 800.0f;
29 constexpr float ITEM_WIDTH = 120.0f;
30 constexpr float ITEM_HEIGHT = 200.0f;
31 } // namespace
32 
SetUpTestSuite()33 void DragAnimationHelperTestNg::SetUpTestSuite()
34 {
35     TestNG::SetUpTestSuite();
36 }
37 
TearDownTestSuite()38 void DragAnimationHelperTestNg::TearDownTestSuite()
39 {
40     TestNG::TearDownTestSuite();
41 }
42 
SetUp()43 void DragAnimationHelperTestNg::SetUp()
44 {
45     ResetElmtId();
46     auto [gridNode, gridItemNodes] = CreateGridNodeWithChild(DEFAULT_CHILD_COUNT);
47     parentNode_ = gridNode;
48     auto pattern = gridNode->GetPattern<GridPattern>();
49     CHECK_NULL_VOID(pattern);
50     pattern->info_.endIndex_ = DEFAULT_CHILD_COUNT;
51     CHECK_NULL_VOID(parentNode_);
52     childNodes_ = gridItemNodes;
53 }
54 
TearDown()55 void DragAnimationHelperTestNg::TearDown()
56 {
57     parentNode_ = nullptr;
58     childNodes_.clear();
59 }
60 
CreateGridNodeWithChild(size_t childCount,const GridItemStyle & gridItemStyle)61 std::pair<RefPtr<FrameNode>, std::list<RefPtr<FrameNode>>> DragAnimationHelperTestNg::CreateGridNodeWithChild(
62     size_t childCount, const GridItemStyle& gridItemStyle)
63 {
64     ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(GetElmtId());
65     auto nodeId = ViewStackProcessor::GetInstance()->ClaimNodeId();
66     auto frameNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ETS_TAG, nodeId,
67         []() {return AceType::MakeRefPtr<GridPattern>(); });
68     ViewAbstract::SetWidth(Referenced::RawPtr(frameNode), CalcLength(GRID_WIDTH));
69     ViewAbstract::SetHeight(Referenced::RawPtr(frameNode), CalcLength(GRID_HEIGHT));
70     std::list<RefPtr<FrameNode>> childNodes;
71 
72     for (size_t i = 0; i < childCount; ++i) {
73         ViewStackProcessor::GetInstance()->StartGetAccessRecordingFor(GetElmtId());
74         auto itemNodeId = ViewStackProcessor::GetInstance()->ClaimNodeId();
75         auto childNode = FrameNode::GetOrCreateFrameNode(V2::GRID_ITEM_ETS_TAG, itemNodeId,
76             [itemStyle = gridItemStyle]() { return AceType::MakeRefPtr<GridItemPattern>(nullptr, itemStyle); });
77         if (!childNode) {
78             continue;
79         }
80         ViewAbstract::SetWidth(Referenced::RawPtr(childNode), CalcLength(ITEM_WIDTH));
81         ViewAbstract::SetHeight(Referenced::RawPtr(childNode), CalcLength(ITEM_HEIGHT));
82 
83         auto gridItemPattern = childNode->GetPattern<GridItemPattern>();
84         if (gridItemPattern) {
85             gridItemPattern->SetSelected(true);
86         }
87 
88         auto dragPreviewOption = childNode->GetDragPreviewOption();
89         dragPreviewOption.isMultiSelectionEnabled = true;
90         childNode->SetDragPreviewOptions(dragPreviewOption);
91 
92         auto dragPreviewInfo = childNode->GetDragPreview();
93         dragPreviewInfo.pixelMap = AceType::MakeRefPtr<MockPixelMap>();
94         childNode->SetDragPreview(dragPreviewInfo);
95 
96         auto gestureHub = childNode->GetOrCreateGestureEventHub();
97         if (!gestureHub) {
98             continue;
99         }
100         auto eventHub = gestureHub->eventHub_.Upgrade();
101         if (!eventHub) {
102             continue;
103         }
104         auto func = [](const RefPtr<OHOS::Ace::DragEvent>&, const std::string&) { return DragDropInfo(); };
105         eventHub->onDragStart_ = func;
106         childNode->MountToParent(frameNode);
107         childNodes.emplace_back(childNode);
108     }
109     return { frameNode, childNodes };
110 }
111 
112 /**
113  * @tc.name: PlayGatherAnimationBeforeLifting001
114  * @tc.desc: test PlayGatherAnimationBeforeLifting func.
115  * @tc.type: FUNC
116  */
117 HWTEST_F(DragAnimationHelperTestNg, PlayGatherAnimationBeforeLifting001, TestSize.Level1)
118 {
119     auto iter = childNodes_.begin();
120     ASSERT_TRUE(iter != childNodes_.end());
121     auto gestureHub = (*iter)->GetOrCreateGestureEventHub();
122     auto actuator = AceType::MakeRefPtr<DragEventActuator>(
123         AceType::WeakClaim(AceType::RawPtr(gestureHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
124     actuator->FindItemParentNode(*(childNodes_.begin()));
125     DragAnimationHelper::PlayGatherAnimationBeforeLifting(actuator);
126 
127     for (const auto& child : childNodes_) {
128         ASSERT_TRUE(child != nullptr);
129         auto gridItemPattern = child->GetPattern<GridItemPattern>();
130         ASSERT_TRUE(gridItemPattern != nullptr);
131         gridItemPattern->SetSelected(true);
132     }
133     actuator->isSelectedItemNode_ = true;
134     auto gridPattern = parentNode_->GetPattern<GridPattern>();
135     GatherNodeChildInfo gatherNodeInfo;
136     auto imageNodeId = GetElmtId();
137     auto gatherNodeId = GetElmtId();
138     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, imageNodeId,
__anon4ff6e6e70502() 139         []() { return AceType::MakeRefPtr<Pattern>(); });
140     auto gatherNode = FrameNode::GetOrCreateFrameNode("gatherNode", gatherNodeId,
__anon4ff6e6e70602() 141         []() { return AceType::MakeRefPtr<Pattern>(); });
142     gatherNodeInfo.imageNode =  AceType::WeakClaim(AceType::RawPtr(imageNode));
143     actuator->PushBackGatherNodeChild(gatherNodeInfo);
144     actuator->SetGatherNode(gatherNode);
145     ASSERT_TRUE(gridPattern != nullptr);
146     gridPattern->info_.endIndex_ = DEFAULT_CHILD_COUNT;
147     DragAnimationHelper::PlayGatherAnimationBeforeLifting(actuator);
148     ASSERT_NE(actuator->GetGatherNode(), nullptr);
149 }
150 
151 /**
152  * @tc.name: CalcOffsetToTarget001
153  * @tc.desc: test CalcOffsetToTarget func.
154  * @tc.type: FUNC
155  */
156 HWTEST_F(DragAnimationHelperTestNg, CalcOffsetToTarget001, TestSize.Level1)
157 {
158     CalcResult result;
159     auto offset = DragAnimationHelper::CalcOffsetToTarget(OffsetF(), OffsetF(), result);
160     EXPECT_TRUE(IsEqual(offset, OffsetF(0.0f, 0.0f)));
161 
162     result.maxDistance = 10.0f;
163     result.minDistance =5.0f;
164     result.maxTranslation =1.0f;
165     offset = DragAnimationHelper::CalcOffsetToTarget(OffsetF(), OffsetF(), result);
166     EXPECT_TRUE(IsEqual(offset, OffsetF(0.0f, 0.0f)));
167 
168     offset = DragAnimationHelper::CalcOffsetToTarget(OffsetF(), OffsetF(3.0f, 4.0f), result);
169     EXPECT_EQ(result.maxTranslation, 1.0f);
170 }
171 
172 /**
173  * @tc.name: PlayNodeAnimationBeforeLifting001
174  * @tc.desc: test PlayNodeAnimationBeforeLifting func.
175  * @tc.type: FUNC
176  */
177 HWTEST_F(DragAnimationHelperTestNg, PlayNodeAnimationBeforeLifting001, TestSize.Level1)
178 {
179     ASSERT_TRUE(parentNode_ != nullptr);
180     DragPreviewOption option;
181     option.defaultAnimationBeforeLifting = false;
182     parentNode_->SetDragPreviewOptions(option);
183     DragAnimationHelper::PlayNodeAnimationBeforeLifting(parentNode_);
184 
185     option.defaultAnimationBeforeLifting = true;
186     parentNode_->SetDragPreviewOptions(option);
187     DragAnimationHelper::PlayNodeAnimationBeforeLifting(parentNode_);
188     auto vector = parentNode_->GetRenderContext()->GetTransformScale();
189     ASSERT_TRUE(vector.has_value());
190 }
191 
192 /**
193  * @tc.name: PlayNodeAnimationBeforeLifting001
194  * @tc.desc: test PlayNodeResetAnimation func.
195  * @tc.type: FUNC
196  */
197 HWTEST_F(DragAnimationHelperTestNg, PlayNodeResetAnimation001, TestSize.Level1)
198 {
199     ASSERT_TRUE(parentNode_ != nullptr);
200     DragPreviewOption option;
201     option.defaultAnimationBeforeLifting = false;
202     parentNode_->SetDragPreviewOptions(option);
203     auto gestureHub = parentNode_->GetOrCreateGestureEventHub();
204     auto actuator = AceType::MakeRefPtr<DragEventActuator>(
205         AceType::WeakClaim(AceType::RawPtr(gestureHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
206     DragAnimationHelper::PlayNodeResetAnimation(actuator);
207 
208     option.defaultAnimationBeforeLifting = true;
209     parentNode_->SetDragPreviewOptions(option);
210     DragAnimationHelper::PlayNodeResetAnimation(actuator);
211     auto type = parentNode_->GetLayoutProperty()->GetVisibilityValue(VisibleType::INVISIBLE);
212     ASSERT_TRUE(type == VisibleType::VISIBLE);
213 }
214 
215 /**
216  * @tc.name: PlayGatherAnimation001
217  * @tc.desc: test PlayGatherAnimation func.
218  * @tc.type: FUNC
219  */
220 HWTEST_F(DragAnimationHelperTestNg, PlayGatherAnimation001, TestSize.Level1)
221 {
222     ASSERT_TRUE(parentNode_ != nullptr);
223     std::vector<GatherNodeChildInfo> gatherNodeInfos;
224     GatherNodeChildInfo gatherNodeInfo;
225     auto imageNodeId = GetElmtId();
226     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, imageNodeId,
__anon4ff6e6e70702() 227         []() { return AceType::MakeRefPtr<Pattern>(); });
228     gatherNodeInfo.imageNode =  AceType::WeakClaim(AceType::RawPtr(imageNode));
229     gatherNodeInfos.emplace_back(gatherNodeInfo);
230     auto pipelineContext = MockPipelineContext::GetCurrent();
231     ASSERT_TRUE(pipelineContext != nullptr);
232     auto overlayManager = pipelineContext->GetOverlayManager();
233     ASSERT_TRUE(overlayManager != nullptr);
234     overlayManager->MountGatherNodeToRootNode(parentNode_, gatherNodeInfos);
235     DragAnimationHelper::PlayGatherAnimation(parentNode_, overlayManager);
236 
237     auto renderContext = imageNode->GetRenderContext();
238     ASSERT_TRUE(renderContext != nullptr);
239     auto borderRadius = renderContext->GetBorderRadius();
240     ASSERT_TRUE(borderRadius.has_value());
241     EXPECT_FALSE(borderRadius.value().multiValued);
242 }
243 
244 /**
245  * @tc.name: ShowBadgeAnimation001
246  * @tc.desc: test ShowBadgeAnimation func.
247  * @tc.type: FUNC
248  */
249 HWTEST_F(DragAnimationHelperTestNg, ShowBadgeAnimation001, TestSize.Level1)
250 {
251     auto textNodeId = GetElmtId();
252     auto textNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, textNodeId,
__anon4ff6e6e70802() 253         []() { return AceType::MakeRefPtr<Pattern>(); });
254 
255     DragAnimationHelper::ShowBadgeAnimation(textNode);
256     auto renderContext = textNode->GetRenderContext();
257     ASSERT_TRUE(renderContext != nullptr);
258     auto transformScale = renderContext->GetTransformScale();
259     EXPECT_TRUE(transformScale.has_value());
260 }
261 
262 /**
263  * @tc.name: CalcBadgeTextPosition001
264  * @tc.desc: test CalcBadgeTextPosition func.
265  * @tc.type: FUNC
266  */
267 HWTEST_F(DragAnimationHelperTestNg, CalcBadgeTextPosition001, TestSize.Level1)
268 {
269     std::vector<GatherNodeChildInfo> gatherNodeInfos;
270     GatherNodeChildInfo gatherNodeInfo;
271     auto imageNodeId = GetElmtId();
272     auto textNodeId = GetElmtId();
273     auto frameNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, GetElmtId(), AceType::MakeRefPtr<Pattern>());
274     ASSERT_TRUE(frameNode != nullptr);
275     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(frameNode->GetId(), frameNode->GetTag(), MenuType::MENU);
276     auto textNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, textNodeId,
__anon4ff6e6e70902() 277         []() { return AceType::MakeRefPtr<TextPattern>(); });
278     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, imageNodeId,
__anon4ff6e6e70a02() 279         []() { return AceType::MakeRefPtr<Pattern>(); });
280 
281     gatherNodeInfo.imageNode =  AceType::WeakClaim(AceType::RawPtr(imageNode));
282     gatherNodeInfos.emplace_back(gatherNodeInfo);
283     auto pipelineContext = MockPipelineContext::GetCurrent();
284     ASSERT_TRUE(pipelineContext != nullptr);
285     auto overlayManager = pipelineContext->GetOverlayManager();
286     ASSERT_TRUE(overlayManager != nullptr);
287     overlayManager->MountGatherNodeToRootNode(textNode, gatherNodeInfos);
288     DragAnimationHelper::CalcBadgeTextPosition(menuPattern, overlayManager, imageNode, textNode);
289 
290     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
291     ASSERT_TRUE(textLayoutProperty != nullptr);
292     auto content = textLayoutProperty->GetContentValue();
293     EXPECT_STREQ(StringUtils::Str16ToStr8(content).c_str(),
294         std::to_string(overlayManager->GetGatherNodeChildrenInfo().size() + 1).c_str());
295 }
296 
297 /**
298  * @tc.name: CalcBadgeTextPosition002
299  * @tc.desc: test CalcBadgeTextPosition func.
300  * @tc.type: FUNC
301  */
302 HWTEST_F(DragAnimationHelperTestNg, CalcBadgeTextPosition002, TestSize.Level1)
303 {
304     std::vector<GatherNodeChildInfo> gatherNodeInfos;
305     GatherNodeChildInfo gatherNodeInfo;
306     auto imageNodeId = GetElmtId();
307     auto textNodeId = GetElmtId();
308     auto frameNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, GetElmtId(), AceType::MakeRefPtr<Pattern>());
309     ASSERT_NE(frameNode, nullptr);
310     auto menuPattern = AceType::MakeRefPtr<MenuPattern>(frameNode->GetId(), frameNode->GetTag(), MenuType::MENU);
311     auto textNode = FrameNode::GetOrCreateFrameNode(V2::TEXT_ETS_TAG, textNodeId,
__anon4ff6e6e70b02() 312         []() { return AceType::MakeRefPtr<TextPattern>(); });
313     auto imageNode = FrameNode::GetOrCreateFrameNode(V2::IMAGE_ETS_TAG, imageNodeId,
__anon4ff6e6e70c02() 314         []() { return AceType::MakeRefPtr<Pattern>(); });
315     ASSERT_NE(menuPattern, nullptr);
316 
317     gatherNodeInfo.imageNode =  AceType::WeakClaim(AceType::RawPtr(imageNode));
318     gatherNodeInfos.emplace_back(gatherNodeInfo);
319     frameNode->previewOption_.isNumber = true;
320     frameNode->previewOption_.badgeNumber = 3;
321 
322     auto pipelineContext = MockPipelineContext::GetCurrent();
323     ASSERT_NE(pipelineContext, nullptr);
324     auto overlayManager = pipelineContext->GetOverlayManager();
325     ASSERT_NE(overlayManager, nullptr);
326     overlayManager->MountGatherNodeToRootNode(textNode, gatherNodeInfos);
327     DragAnimationHelper::CalcBadgeTextPosition(menuPattern, overlayManager, imageNode, textNode);
328 
329     auto textLayoutProperty = textNode->GetLayoutProperty<TextLayoutProperty>();
330     ASSERT_NE(textLayoutProperty, nullptr);
331     auto content = textLayoutProperty->GetContentValue();
332 
333     EXPECT_STREQ(StringUtils::Str16ToStr8(content).c_str(),
334         std::to_string(3).c_str());
335 }
336 
337 /**
338  * @tc.name: CreateImageNode
339  * @tc.desc: test CreateImageNode func.
340  * @tc.type: FUNC
341  */
342 HWTEST_F(DragAnimationHelperTestNg, CreateImageNode, TestSize.Level1)
343 {
344     /**
345      * @tc.steps: step1. create pixelMap.
346      * @tc.expected: pixelMap is not null.
347      */
348     RefPtr<MockPixelMap> mockPixelMap = AceType::MakeRefPtr<MockPixelMap>();
349     ASSERT_NE(mockPixelMap, nullptr);
350 
351     /**
352      * @tc.steps: step2. create imageNode.
353      * @tc.expected: imageNode is not null.
354      */
355     auto imageNode = DragAnimationHelper::CreateImageNode(mockPixelMap);
356     ASSERT_NE(imageNode, nullptr);
357 
358     /**
359      * @tc.steps: step3. check imageNode attr
360      */
361     auto imageContext = imageNode->GetRenderContext();
362     ASSERT_NE(imageContext, nullptr);
363     auto opacity = imageContext->GetOpacity().value_or(0);
364     EXPECT_EQ(opacity, 1.0f);
365 }
366 
367 /**
368  * @tc.name: CreateGatherImageNode
369  * @tc.desc: test CreateGatherImageNode func.
370  * @tc.type: FUNC
371  */
372 HWTEST_F(DragAnimationHelperTestNg, CreateGatherImageNode, TestSize.Level1)
373 {
374     /**
375      * @tc.steps: step1. create gatherNode.
376      * @tc.expected: gatherChildNode is not null.
377      */
378     int32_t size = childNodes_.size();
379     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
380     auto iter = childNodes_.begin();
381     ASSERT_TRUE(iter != childNodes_.end());
382     auto itemNode = *(iter);
383     ASSERT_NE(itemNode, nullptr);
384     GatherNodeChildInfo gatherNodeChildInfo;
385     auto gatherChildNode = DragAnimationHelper::CreateGatherImageNode(itemNode, gatherNodeChildInfo);
386     ASSERT_NE(gatherChildNode, nullptr);
387 }
388 
389 /**
390  * @tc.name: CreateGatherNode
391  * @tc.desc: test CreateGatherNode func.
392  * @tc.type: FUNC
393  */
394 HWTEST_F(DragAnimationHelperTestNg, CreateGatherNode, TestSize.Level1)
395 {
396     /**
397      * @tc.steps: step1. create gatherNode.
398      * @tc.expected: gatherNode is not null.
399      */
400     int32_t size = childNodes_.size();
401     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
402     auto iter = childNodes_.begin();
403     ASSERT_TRUE(iter != childNodes_.end());
404     auto itemNode = *(iter);
405     ASSERT_NE(itemNode, nullptr);
406     std::vector<GatherNodeChildInfo> gatherNodeInfo;
407     auto gatherNode = DragAnimationHelper::CreateGatherNode(itemNode, gatherNodeInfo);
408     ASSERT_NE(gatherNode, nullptr);
409 
410     /**
411      * @tc.steps: step2. check gatherNodeInfo size
412      */
413     auto gatherChildSize = gatherNodeInfo.size();
414     EXPECT_EQ(gatherChildSize + 1, size);
415 }
416 
417 /**
418  * @tc.name: GetOrCreateGatherNode
419  * @tc.desc: test GetOrCreateGatherNode func.
420  * @tc.type: FUNC
421  */
422 HWTEST_F(DragAnimationHelperTestNg, GetOrCreateGatherNode001, TestSize.Level1)
423 {
424     /**
425      * @tc.steps: step1. create gatherNode.
426      * @tc.expected: gatherNode is not null.
427      */
428     int32_t size = childNodes_.size();
429     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
430     auto iter = childNodes_.begin();
431     ASSERT_TRUE(iter != childNodes_.end());
432     auto itemNode = *(iter);
433     ASSERT_NE(itemNode, nullptr);
434     std::vector<GatherNodeChildInfo> gatherNodeInfo;
435     auto gestureHub = itemNode->GetOrCreateGestureEventHub();
436     ASSERT_NE(gestureHub, nullptr);
437 
438     /**
439      * @tc.steps: step2. Get overlayManager
440      */
441     auto pipelineContext = MockPipelineContext::GetCurrent();
442     ASSERT_NE(pipelineContext, nullptr);
443     auto overlayManager = pipelineContext->GetOverlayManager();
444     ASSERT_NE(overlayManager, nullptr);
445     overlayManager->RemoveGatherNode();
446 
447     /**
448      * @tc.steps: step2. check gatherNodeInfo size
449      */
450     auto actuator = AceType::MakeRefPtr<DragEventActuator>(
451     AceType::WeakClaim(AceType::RawPtr(gestureHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
452     ASSERT_NE(actuator, nullptr);
453     actuator->itemParentNode_ = parentNode_;
454     actuator->isSelectedItemNode_ = true;
455     auto gatherNode = DragAnimationHelper::GetOrCreateGatherNode(overlayManager, actuator, gatherNodeInfo);
456     ASSERT_NE(gatherNode, nullptr);
457 
458     auto gatherChildSize = gatherNodeInfo.size();
459     EXPECT_EQ(gatherChildSize + 1, size);
460 }
461 
462 /**
463  * @tc.name: GetOrCreateGatherNode
464  * @tc.desc: test GetOrCreateGatherNode func.
465  * @tc.type: FUNC
466  */
467 HWTEST_F(DragAnimationHelperTestNg, GetOrCreateGatherNode002, TestSize.Level1)
468 {
469     /**
470      * @tc.steps: step1. create gatherNode.
471      * @tc.expected: gatherNode is not null.
472      */
473     int32_t size = childNodes_.size();
474     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
475     auto iter = childNodes_.begin();
476     ASSERT_TRUE(iter != childNodes_.end());
477     auto itemNode = *(iter);
478     ASSERT_NE(itemNode, nullptr);
479     std::vector<GatherNodeChildInfo> gatherNodeInfo;
480     auto gatherNode = DragAnimationHelper::CreateGatherNode(itemNode, gatherNodeInfo);
481     ASSERT_NE(gatherNode, nullptr);
482 
483     /**
484      * @tc.steps: step2. Get overlayManager
485      */
486     auto pipelineContext = MockPipelineContext::GetCurrent();
487     ASSERT_NE(pipelineContext, nullptr);
488     auto overlayManager = pipelineContext->GetOverlayManager();
489     ASSERT_NE(overlayManager, nullptr);
490     overlayManager->RemoveGatherNode();
491 
492     /**
493      * @tc.steps: step3. Call MountGatherNode
494      */
495     DragAnimationHelper::MountGatherNode(overlayManager, itemNode, gatherNode, gatherNodeInfo);
496     EXPECT_NE(overlayManager->GetGatherNode(), nullptr);
497     auto gatherChildSize = overlayManager->GetGatherNodeChildrenInfo().size();
498     EXPECT_EQ(gatherChildSize + 1, size);
499 
500     /**
501      * @tc.steps: step4. call GetOrCreateGatherNode
502      */
503     auto gestureHub = itemNode->GetOrCreateGestureEventHub();
504     ASSERT_NE(gestureHub, nullptr);
505     auto actuator = AceType::MakeRefPtr<DragEventActuator>(
506         AceType::WeakClaim(AceType::RawPtr(gestureHub)), DRAG_DIRECTION, FINGERS_NUMBER, DISTANCE);
507     ASSERT_NE(actuator, nullptr);
508     actuator->itemParentNode_ = parentNode_;
509     actuator->isSelectedItemNode_ = true;
510     auto newGatherNode = DragAnimationHelper::GetOrCreateGatherNode(overlayManager, actuator, gatherNodeInfo);
511     ASSERT_EQ(gatherNode, newGatherNode);
512 }
513 
514 
515 /**
516  * @tc.name: MountGatherNode
517  * @tc.desc: test MountGatherNode func.
518  * @tc.type: FUNC
519  */
520 HWTEST_F(DragAnimationHelperTestNg, MountGatherNode, TestSize.Level1)
521 {
522     /**
523      * @tc.steps: step1. create gatherNode.
524      * @tc.expected: gatherNode is not null.
525      */
526     int32_t size = childNodes_.size();
527     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
528     auto iter = childNodes_.begin();
529     ASSERT_TRUE(iter != childNodes_.end());
530     auto itemNode = *(iter);
531     ASSERT_NE(itemNode, nullptr);
532     std::vector<GatherNodeChildInfo> gatherNodeInfo;
533     auto gatherNode = DragAnimationHelper::CreateGatherNode(itemNode, gatherNodeInfo);
534     ASSERT_NE(gatherNode, nullptr);
535 
536     /**
537      * @tc.steps: step2. Get overlayManager
538      */
539     auto pipelineContext = MockPipelineContext::GetCurrent();
540     ASSERT_NE(pipelineContext, nullptr);
541     auto overlayManager = pipelineContext->GetOverlayManager();
542     ASSERT_NE(overlayManager, nullptr);
543 
544     /**
545      * @tc.steps: step3. Call MountGatherNode
546      */
547     DragAnimationHelper::MountGatherNode(overlayManager, itemNode, gatherNode, gatherNodeInfo);
548     EXPECT_NE(overlayManager->GetGatherNode(), nullptr);
549     auto gatherChildSize = overlayManager->GetGatherNodeChildrenInfo().size();
550     EXPECT_EQ(gatherChildSize + 1, size);
551 }
552 
553 /**
554  * @tc.name: InitGatherNodeAttr
555  * @tc.desc: test InitGatherNodeAttr func.
556  * @tc.type: FUNC
557  */
558 HWTEST_F(DragAnimationHelperTestNg, InitGatherNodeAttr, TestSize.Level1)
559 {
560     /**
561      * @tc.steps: step1. create gatherNode.
562      * @tc.expected: gatherNode is not null.
563      */
564     int32_t size = childNodes_.size();
565     ASSERT_EQ(DEFAULT_CHILD_COUNT, size);
566     auto iter = childNodes_.begin();
567     ASSERT_TRUE(iter != childNodes_.end());
568     auto itemNode = *(iter);
569     ASSERT_NE(itemNode, nullptr);
570     std::vector<GatherNodeChildInfo> gatherNodeInfo;
571     auto gatherNode = DragAnimationHelper::CreateGatherNode(itemNode, gatherNodeInfo);
572     ASSERT_NE(gatherNode, nullptr);
573 
574     /**
575      * @tc.steps: step2. InitGatherNodeAttr
576      */
577     DragAnimationHelper::InitGatherNodeAttr(gatherNode, gatherNodeInfo);
578     auto renderContext = gatherNode->GetRenderContext();
579     ASSERT_NE(renderContext, nullptr);
580     ASSERT_NE(renderContext->GetPosition(), std::nullopt);
581     EXPECT_EQ(renderContext->GetPosition()->GetX().Value(), 0);
582     EXPECT_EQ(renderContext->GetPosition()->GetY().Value(), 0);
583 }
584 
585 /**
586  * @tc.name: HideDragNodeCopy
587  * @tc.desc: test HideDragNodeCopy func.
588  * @tc.type: FUNC
589  */
590 HWTEST_F(DragAnimationHelperTestNg, HideDragNodeCopy, TestSize.Level1)
591 {
592     /**
593      * @tc.steps: step1. Create DragNodeCopy
594      */
595     auto frameNode = FrameNode::CreateFrameNode(V2::COLUMN_ETS_TAG, GetElmtId(), AceType::MakeRefPtr<Pattern>());
596     ASSERT_NE(frameNode, nullptr);
597     auto pipelineContext = MockPipelineContext::GetCurrent();
598     ASSERT_NE(pipelineContext, nullptr);
599     auto overlayManager = pipelineContext->GetOverlayManager();
600     ASSERT_NE(overlayManager, nullptr);
601     overlayManager->dragNodeCopyWeak_ = frameNode;
602     auto renderContext = frameNode->GetRenderContext();
603     renderContext->UpdateOpacity(1.0f);
604     ASSERT_NE(renderContext, nullptr);
605     auto opacity = renderContext->GetOpacity().value_or(0);
606     EXPECT_EQ(opacity, 1.0f);
607 
608     /**
609      * @tc.steps: step2. Call HideDragNodeCopy
610      */
611     DragAnimationHelper::HideDragNodeCopy(overlayManager);
612     opacity = renderContext->GetOpacity().value_or(0);
613     EXPECT_EQ(opacity, 0.0f);
614 }
615 
616 /**
617  * @tc.name: DragStartAnimation
618  * @tc.desc: Test DragStartAnimation func with Offset(10.0, 10.0). TranslateOptions value will be right after drag
619  * animation.
620  * @tc.type: FUNC
621  */
622 HWTEST_F(DragAnimationHelperTestNg, DragStartAnimation, TestSize.Level1)
623 {
624     /**
625      * @tc.steps: step1. Create overlayManager and dragDropManager.
626      * @tc.expected: overlayManager and dragDropManager is not null.
627      */
628     int32_t containerId = 100;
629     auto pipelineContext = PipelineContext::GetContextByContainerId(containerId);
630     ASSERT_NE(pipelineContext, nullptr);
631     auto overlayManager = pipelineContext->GetOverlayManager();
632     ASSERT_NE(overlayManager, nullptr);
633     auto dragDropManager = pipelineContext->GetDragDropManager();
634     ASSERT_NE(dragDropManager, nullptr);
635 
636     /**
637      * @tc.steps: step2. Create imageNode and dragPreviewInfo.
638      * @tc.expected: dragPreviewInfo's imageNode is not nullptr.
639      */
640     void* voidPtr = static_cast<void*>(new char[0]);
641     RefPtr<PixelMap> refPixelMap = PixelMap::CreatePixelMap(voidPtr);
642     auto imageNode = DragAnimationHelper::CreateImageNode(refPixelMap);
643     ASSERT_NE(imageNode, nullptr);
644     DragDropManager::DragPreviewInfo dragPreviewInfo;
645     dragPreviewInfo.imageNode = imageNode;
646     ASSERT_NE(dragPreviewInfo.imageNode, nullptr);
647     dragDropManager->SetDragPreviewInfo(dragPreviewInfo);
648 
649     /**
650      * @tc.steps: step3. Call DragStartAnimation with Offset(10.0, 10.0).
651      * @tc.expected: TranslateOptions x value is 10.0f.
652      */
653     auto newOffset = Offset(10.0, 10.0);
654     auto gatherNodeCenter =
655         NG::DragDropFuncWrapper::GetPaintRectCenter(dragDropManager->GetDragPreviewInfo().imageNode);
656     Point point = { 0, 0 };
657     DragAnimationHelper::DragStartAnimation(newOffset, overlayManager, gatherNodeCenter, point, containerId);
658     auto renderContext = imageNode->GetRenderContext();
659     TranslateOptions result = renderContext->GetTransformTranslate().value();
660     TranslateOptions expectValue { 10.0f, 10.0f, 0.0f };
661     EXPECT_EQ(result.x.CalcValue(), expectValue.x.CalcValue());
662 }
663 } // namespace OHOS::Ace::NG