1 /*
2 * Copyright (c) 2024-2025 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 <cstdint>
17 #include <iostream>
18 #include <optional>
19 #include <string>
20
21 #include "gtest/gtest.h"
22
23 #define protected public
24 #define private public
25
26 #include "test/mock/base/mock_system_properties.h"
27 #include "test/mock/core/common/mock_theme_manager.h"
28 #include "test/mock/core/pipeline/mock_pipeline_context.h"
29
30 #include "core/common/ace_application_info.h"
31 #include "core/components/common/layout/constants.h"
32 #include "core/components/select/select_theme.h"
33 #include "core/components/text/text_theme.h"
34 #include "core/components/text_field/textfield_theme.h"
35 #include "core/components/theme/icon_theme.h"
36 #include "core/components_ng/base/view_stack_processor.h"
37 #include "core/components_ng/base/view_abstract.h"
38 #include "core/components_ng/layout/layout_wrapper.h"
39 #include "core/components_ng/pattern/flex/flex_layout_property.h"
40 #include "core/components_ng/pattern/image/image_pattern.h"
41 #include "core/components_ng/pattern/linear_layout/linear_layout_pattern.h"
42 #include "core/components_ng/pattern/menu/menu_item/menu_item_pattern.h"
43 #include "core/components_ng/pattern/menu/menu_layout_property.h"
44 #include "core/components_ng/pattern/menu/menu_pattern.h"
45 #include "core/components_ng/pattern/menu/menu_view.h"
46 #include "core/components_ng/pattern/scroll/scroll_layout_property.h"
47 #include "core/components_ng/pattern/scroll/scroll_pattern.h"
48 #include "core/components_ng/pattern/select/select_model_ng.h"
49 #include "core/components_ng/pattern/select/select_pattern.h"
50 #include "core/components_ng/pattern/text/text_layout_property.h"
51 #include "core/components_ng/pattern/text/text_pattern.h"
52 #include "core/components_v2/inspector/inspector_constants.h"
53 #include "core/components_ng/syntax/lazy_for_each_model.h"
54 #include "core/components_ng/syntax/lazy_for_each_node.h"
55 #include "core/components_ng/syntax/lazy_layout_wrapper_builder.h"
56
57 using namespace testing;
58 using namespace testing::ext;
59 using namespace OHOS::Ace::Framework;
60
61 namespace OHOS::Ace::NG {
62 namespace {
63 const InspectorFilter filter;
64 const std::string EMPTY_TEXT = "";
65 const std::string SELECT_TEXT = "select";
66 const std::string ITEM_TEXT = "menuItem";
67 const std::string OPTION_TEXT = "aaa";
68 const std::string OPTION_TEXT_2 = "BBB";
69 const std::string OPTION_TEXT_3 = "CCC";
70 const std::string INTERNAL_SOURCE = "$r('app.media.icon')";
71 const std::string FILE_SOURCE = "/common/icon.png";
72 const std::string DEFAULT_STR("2.0");
73 const std::string TEXT_VALUE = "test";
74 const CalcLength MARGIN_LENGTH = CalcLength("8vp");
75 const CalcSize TEXT_IDEAL_SIZE = CalcSize(CalcLength("50vp"), std::nullopt);
76 constexpr float FULL_SCREEN_WIDTH = 720.0f;
77 constexpr float FULL_SCREEN_HEIGHT = 1136.0f;
78 constexpr float SELECT_WIDTH = 100.0f;
79 constexpr float SELECT_HEIGHT = 200.0f;
80 constexpr Dimension OPTION_MARGIN = 8.0_vp;
81 const SizeF FULL_SCREEN_SIZE(FULL_SCREEN_WIDTH, FULL_SCREEN_HEIGHT);
82 const std::vector<std::string> FONT_FAMILY_VALUE = { "cursive" };
83 const Color TEXT_COLOR_VALUE = Color::FromRGB(255, 100, 100);
84 const Color BG_COLOR_VALUE = Color::FromRGB(100, 255, 100);
85 const Color SELECT_TEXT_COLOR_VALUE = Color::FromRGB(255, 255, 100);
86 const Color SELECT_BG_COLOR_VALUE = Color::FromRGB(100, 255, 255);
87 const std::vector<SelectParam> CREATE_VALUE = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
88 { OPTION_TEXT_3, INTERNAL_SOURCE } };
89 const Ace::FontWeight FONT_WEIGHT_VALUE = Ace::FontWeight::W100;
90 const Dimension FONT_SIZE_VALUE = Dimension(20.1, DimensionUnit::PX);
91 const Ace::FontStyle ITALIC_FONT_STYLE_VALUE = Ace::FontStyle::ITALIC;
92 } // namespace
93 struct TestProperty {
94 std::optional<Dimension> FontSize = std::nullopt;
95 std::optional<Ace::FontStyle> FontStyle = std::nullopt;
96 std::optional<FontWeight> FontWeight = std::nullopt;
97 std::optional<std::vector<std::string>> FontFamily = std::nullopt;
98 std::optional<Color> FontColor = std::nullopt;
99 };
100 class SelectPatternTestNg : public testing::Test {
101 public:
102 static void SetUpTestCase();
103 static void TearDownTestCase();
104 void SetUp() override;
105 void TearDown() override;
106 void InitSelectPatternTestNg();
107 RefPtr<FrameNode> frameNode_;
108 RefPtr<SelectPattern> selectPattern_;
109 RefPtr<SelectAccessibilityProperty> selectAccessibilityProperty_;
110
111 protected:
112 static RefPtr<FrameNode> CreateSelect(const std::vector<SelectParam>& value, const TestProperty& test);
113 static FrameNode* CreateSelect(const std::vector<SelectParam>& value);
114 };
115
SetUpTestCase()116 void SelectPatternTestNg::SetUpTestCase()
117 {
118 MockPipelineContext::SetUp();
119 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
120 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
121 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(AceType::MakeRefPtr<SelectTheme>()));
122 EXPECT_CALL(*themeManager, GetTheme(_, _)).WillRepeatedly(Return(AceType::MakeRefPtr<SelectTheme>()));
123 }
124
TearDownTestCase()125 void SelectPatternTestNg::TearDownTestCase()
126 {
127 MockPipelineContext::TearDown();
128 }
129
SetUp()130 void SelectPatternTestNg::SetUp() {}
131
TearDown()132 void SelectPatternTestNg::TearDown()
133 {
134 frameNode_ = nullptr;
135 selectPattern_ = nullptr;
136 selectAccessibilityProperty_ = nullptr;
137 }
138
InitSelectPatternTestNg()139 void SelectPatternTestNg::InitSelectPatternTestNg()
140 {
141 frameNode_ = FrameNode::GetOrCreateFrameNode(V2::SELECT_ETS_TAG, ViewStackProcessor::GetInstance()->ClaimNodeId(),
142 []() { return AceType::MakeRefPtr<SelectPattern>(); });
143 ASSERT_NE(frameNode_, nullptr);
144
145 selectPattern_ = frameNode_->GetPattern<SelectPattern>();
146 ASSERT_NE(selectPattern_, nullptr);
147
148 selectAccessibilityProperty_ = frameNode_->GetAccessibilityProperty<SelectAccessibilityProperty>();
149 ASSERT_NE(selectAccessibilityProperty_, nullptr);
150 }
151
CreateSelect(const std::vector<SelectParam> & value,const TestProperty & test)152 RefPtr<FrameNode> SelectPatternTestNg::CreateSelect(const std::vector<SelectParam>& value, const TestProperty& test)
153 {
154 SelectModelNG selectModelInstance;
155 selectModelInstance.Create(value);
156 if (test.FontSize.has_value()) {
157 selectModelInstance.SetFontSize(test.FontSize.value());
158 }
159 if (test.FontColor.has_value()) {
160 selectModelInstance.SetFontColor(test.FontColor.value());
161 }
162 if (test.FontStyle.has_value()) {
163 selectModelInstance.SetItalicFontStyle(test.FontStyle.value());
164 }
165 if (test.FontWeight.has_value()) {
166 selectModelInstance.SetFontWeight(test.FontWeight.value());
167 }
168 if (test.FontFamily.has_value()) {
169 selectModelInstance.SetFontFamily(test.FontFamily.value());
170 }
171
172 RefPtr<UINode> element = ViewStackProcessor::GetInstance()->Finish();
173 return AceType::DynamicCast<FrameNode>(element);
174 }
175
CreateSelect(const std::vector<SelectParam> & value)176 FrameNode* SelectPatternTestNg::CreateSelect(const std::vector<SelectParam>& value)
177 {
178 SelectModelNG selectModelInstance;
179 selectModelInstance.Create(value);
180 return ViewStackProcessor::GetInstance()->GetMainFrameNode();
181 }
182
183 /**
184 * @tc.name: OnModifyDone002
185 * @tc.desc: Test SelectPattern OnModifyDone
186 * @tc.type: FUNC
187 */
188 HWTEST_F(SelectPatternTestNg, OnModifyDone002, TestSize.Level1)
189 {
190 SelectModelNG selectModelInstance;
191 /**
192 * @tc.steps: step1. Create select.
193 */
194 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
195 selectModelInstance.Create(params);
196 /**
197 * @tc.steps: step2. Get frameNode and pattern.
198 */
199 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
200 ASSERT_NE(select, nullptr);
201 auto selectPattern = select->GetPattern<SelectPattern>();
202 ASSERT_NE(selectPattern, nullptr);
203 auto menuNode = selectPattern->GetMenuNode();
204 ASSERT_NE(menuNode, nullptr);
205 auto menuPattern = menuNode->GetPattern<MenuPattern>();
206 ASSERT_NE(menuPattern, nullptr);
207 /**
208 * @tc.steps: step3. Call OnModifyDone.
209 * @tc.expected: the function runs normally
210 */
211 selectPattern->OnModifyDone();
212 auto val = menuPattern->IsSelectMenu();
213
214 EXPECT_EQ(val, true);
215 }
216
217 /**
218 * @tc.name: RemoveParentRestrictionsForFixIdeal001
219 * @tc.desc: Test Select RemoveParentRestrictionsForFixIdeal.
220 * @tc.type: FUNC
221 */
222 HWTEST_F(SelectPatternTestNg, RemoveParentRestrictionsForFixIdeal001, TestSize.Level1)
223 {
224 /**
225 * @tc.steps: step1. Create select.
226 */
227 auto selectPattern = AceType::MakeRefPtr<SelectPattern>();
228 auto selectNode = FrameNode::CreateFrameNode(V2::SELECT_ETS_TAG, -1, selectPattern);
229 auto algorithm = AceType::MakeRefPtr<SelectLayoutAlgorithm>();
230 ASSERT_TRUE(algorithm);
231 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
232 auto layoutProp = AceType::MakeRefPtr<LayoutProperty>();
233 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(selectNode, geometryNode, layoutProp);
234 ASSERT_NE(layoutWrapper, nullptr);
235 /**
236 * @tc.steps: step2. LayoutCalPolicy is FIX_AT_IDEAL_SIZE and set maxSize to FULL_SCREEN_SIZE.
237 * @tc.expected: childConstraint.maxSize is infinity.
238 */
239 LayoutConstraintF childConstraint;
240 LayoutPolicyProperty layoutPolicyProperty;
241 layoutPolicyProperty.widthLayoutPolicy_ = LayoutCalPolicy::FIX_AT_IDEAL_SIZE;
242 layoutPolicyProperty.heightLayoutPolicy_ = LayoutCalPolicy::FIX_AT_IDEAL_SIZE;
243 layoutProp->layoutPolicy_ = layoutPolicyProperty;
244 algorithm->RemoveParentRestrictionsForFixIdeal(layoutProp, childConstraint);
245 EXPECT_TRUE(std::isinf(childConstraint.maxSize.Width()));
246 EXPECT_TRUE(std::isinf(childConstraint.maxSize.Height()));
247 }
248
249 /**
250 * @tc.name: RemoveParentRestrictionsForFixIdeal002
251 * @tc.desc: Test Select RemoveParentRestrictionsForFixIdeal.
252 * @tc.type: FUNC
253 */
254 HWTEST_F(SelectPatternTestNg, RemoveParentRestrictionsForFixIdeal002, TestSize.Level1)
255 {
256 /**
257 * @tc.steps: step1. Create select.
258 */
259 auto selectPattern = AceType::MakeRefPtr<SelectPattern>();
260 auto selectNode = FrameNode::CreateFrameNode(V2::SELECT_ETS_TAG, -1, selectPattern);
261 auto algorithm = AceType::MakeRefPtr<SelectLayoutAlgorithm>();
262 ASSERT_TRUE(algorithm);
263 auto geometryNode = AceType::MakeRefPtr<GeometryNode>();
264 auto layoutProp = AceType::MakeRefPtr<LayoutProperty>();
265 auto layoutWrapper = AceType::MakeRefPtr<LayoutWrapperNode>(selectNode, geometryNode, layoutProp);
266 ASSERT_NE(layoutWrapper, nullptr);
267 /**
268 * @tc.steps: step2. LayoutCalPolicy is NO_MATCH and set maxSize to FULL_SCREEN_SIZE.
269 * @tc.expected: childConstraint.maxSize is equal to FULL_SCREEN_SIZE.
270 */
271 LayoutConstraintF childConstraint;
272 childConstraint.maxSize = FULL_SCREEN_SIZE;
273 LayoutPolicyProperty layoutPolicyProperty;
274 layoutPolicyProperty.widthLayoutPolicy_ = LayoutCalPolicy::NO_MATCH;
275 layoutPolicyProperty.heightLayoutPolicy_ = LayoutCalPolicy::NO_MATCH;
276 layoutProp->layoutPolicy_ = layoutPolicyProperty;
277 algorithm->RemoveParentRestrictionsForFixIdeal(layoutProp, childConstraint);
278 EXPECT_EQ(childConstraint.maxSize.Width(), FULL_SCREEN_SIZE.Width());
279 EXPECT_EQ(childConstraint.maxSize.Height(), FULL_SCREEN_SIZE.Height());
280 }
281
282 /**
283 * @tc.name: OnModifyDone003
284 * @tc.desc: Test SelectPattern OnModifyDone
285 * @tc.type: FUNC
286 */
287 HWTEST_F(SelectPatternTestNg, OnModifyDone003, TestSize.Level1)
288 {
289 SelectModelNG selectModelInstance;
290 /**
291 * @tc.steps: step1. Create select.
292 */
293 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
294 selectModelInstance.Create(params);
295 /**
296 * @tc.steps: step2. Get frameNode and pattern.
297 */
298 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
299 ASSERT_NE(select, nullptr);
300 auto selectPattern = select->GetPattern<SelectPattern>();
301 ASSERT_NE(selectPattern, nullptr);
302 auto menuNode = selectPattern->GetMenuNode();
303 ASSERT_NE(menuNode, nullptr);
304 auto menuPattern = menuNode->GetPattern<MenuPattern>();
305 ASSERT_NE(menuPattern, nullptr);
306 /**
307 * @tc.steps: step3. Call OnModifyDone.
308 * @tc.expected: the function runs normally
309 */
310 selectPattern->OnModifyDone();
311 auto val = menuPattern->IsSelectMenu();
312
313 EXPECT_EQ(val, true);
314 }
315
316 /**
317 * @tc.name: OnModifyDone004
318 * @tc.desc: Test SelectPattern OnModifyDone
319 * @tc.type: FUNC
320 */
321 HWTEST_F(SelectPatternTestNg, OnModifyDone004, TestSize.Level1)
322 {
323 SelectModelNG selectModelInstance;
324 /**
325 * @tc.steps: step1. Create select.
326 */
327 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
328 selectModelInstance.Create(params);
329 /**
330 * @tc.steps: step2. Get frameNode and pattern.
331 */
332 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
333 ASSERT_NE(select, nullptr);
334 auto selectPattern = select->GetPattern<SelectPattern>();
335 ASSERT_NE(selectPattern, nullptr);
336 auto menuNode = selectPattern->GetMenuNode();
337 ASSERT_NE(menuNode, nullptr);
338 auto menuPattern = menuNode->GetPattern<MenuPattern>();
339 ASSERT_NE(menuPattern, nullptr);
340 /**
341 * @tc.steps: step3. Call OnModifyDone.
342 * @tc.expected: the function runs normally
343 */
344 selectPattern->OnModifyDone();
345 auto val = menuPattern->IsSelectMenu();
346
347 EXPECT_EQ(val, true);
348 }
349
350 /**
351 * @tc.name: OnModifyDone005
352 * @tc.desc: Test SelectPattern OnModifyDone
353 * @tc.type: FUNC
354 */
355 HWTEST_F(SelectPatternTestNg, OnModifyDone005, TestSize.Level1)
356 {
357 SelectModelNG selectModelInstance;
358 /**
359 * @tc.steps: step1. Create select.
360 */
361 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
362 { OPTION_TEXT_3, INTERNAL_SOURCE } };
363 selectModelInstance.Create(params);
364 /**
365 * @tc.steps: step2. Get frameNode and pattern.
366 */
367 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
368 ASSERT_NE(select, nullptr);
369 auto selectPattern = select->GetPattern<SelectPattern>();
370 ASSERT_NE(selectPattern, nullptr);
371 auto menuNode = selectPattern->GetMenuNode();
372 ASSERT_NE(menuNode, nullptr);
373 auto menuPattern = menuNode->GetPattern<MenuPattern>();
374 ASSERT_NE(menuPattern, nullptr);
375 /**
376 * @tc.steps: step3. Call OnModifyDone.
377 * @tc.expected: the function runs normally
378 */
379 selectPattern->OnModifyDone();
380 auto val = menuPattern->IsSelectMenu();
381
382 EXPECT_EQ(val, true);
383 }
384 /**
385 * @tc.name: OnModifyDone006
386 * @tc.desc: Test SelectPattern OnModifyDone
387 * @tc.type: FUNC
388 */
389 HWTEST_F(SelectPatternTestNg, OnModifyDone006, TestSize.Level1)
390 {
391 SelectModelNG selectModelInstance;
392 /**
393 * @tc.steps: step1. Create select.
394 */
395 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
396 selectModelInstance.Create(params);
397 /**
398 * @tc.steps: step2. Get frameNode and pattern.
399 */
400 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
401 ASSERT_NE(select, nullptr);
402 auto selectPattern = select->GetPattern<SelectPattern>();
403 ASSERT_NE(selectPattern, nullptr);
404 auto menuNode = selectPattern->GetMenuNode();
405 ASSERT_NE(menuNode, nullptr);
406 auto menuPattern = menuNode->GetPattern<MenuPattern>();
407 ASSERT_NE(menuPattern, nullptr);
408 /**
409 * @tc.steps: step3. Call OnModifyDone.
410 * @tc.expected: the function runs normally
411 */
412 selectPattern->OnModifyDone();
413 auto val = menuNode->isRestoreInfoUsed_;
414
415 EXPECT_NE(val, false);
416 }
417
418 /**
419 * @tc.name: OnModifyDone007
420 * @tc.desc: Test SelectPattern OnModifyDone
421 * @tc.type: FUNC
422 */
423 HWTEST_F(SelectPatternTestNg, OnModifyDone007, TestSize.Level1)
424 {
425 SelectModelNG selectModelInstance;
426 /**
427 * @tc.steps: step1. Create select.
428 */
429 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
430 selectModelInstance.Create(params);
431 /**
432 * @tc.steps: step2. Get frameNode and pattern.
433 */
434 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
435 ASSERT_NE(select, nullptr);
436 auto selectPattern = select->GetPattern<SelectPattern>();
437 ASSERT_NE(selectPattern, nullptr);
438 auto menuNode = selectPattern->GetMenuNode();
439 ASSERT_NE(menuNode, nullptr);
440 auto menuPattern = menuNode->GetPattern<MenuPattern>();
441 ASSERT_NE(menuPattern, nullptr);
442 /**
443 * @tc.steps: step3. Call OnModifyDone.
444 * @tc.expected: the function runs normally
445 */
446 selectPattern->OnModifyDone();
447 auto val = menuNode->isRestoreInfoUsed_;
448
449 EXPECT_NE(val, false);
450 }
451
452 /**
453 * @tc.name: OnModifyDone008
454 * @tc.desc: Test SelectPattern OnModifyDone
455 * @tc.type: FUNC
456 */
457 HWTEST_F(SelectPatternTestNg, OnModifyDone008, TestSize.Level1)
458 {
459 SelectModelNG selectModelInstance;
460 /**
461 * @tc.steps: step1. Create select.
462 */
463 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
464 selectModelInstance.Create(params);
465 /**
466 * @tc.steps: step2. Get frameNode and pattern.
467 */
468 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
469 ASSERT_NE(select, nullptr);
470 auto selectPattern = select->GetPattern<SelectPattern>();
471 ASSERT_NE(selectPattern, nullptr);
472 auto menuNode = selectPattern->GetMenuNode();
473 ASSERT_NE(menuNode, nullptr);
474 auto menuPattern = menuNode->GetPattern<MenuPattern>();
475 ASSERT_NE(menuPattern, nullptr);
476 /**
477 * @tc.steps: step3. Call OnModifyDone.
478 * @tc.expected: the function runs normally
479 */
480 selectPattern->OnModifyDone();
481 auto val = menuNode->isRestoreInfoUsed_;
482
483 EXPECT_NE(val, false);
484 }
485
486 /**
487 * @tc.name: OnModifyDone009
488 * @tc.desc: Test SelectPattern OnModifyDone
489 * @tc.type: FUNC
490 */
491 HWTEST_F(SelectPatternTestNg, OnModifyDone009, TestSize.Level1)
492 {
493 SelectModelNG selectModelInstance;
494 /**
495 * @tc.steps: step1. Create select.
496 */
497 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
498 { OPTION_TEXT_3, INTERNAL_SOURCE } };
499 selectModelInstance.Create(params);
500 /**
501 * @tc.steps: step2. Get frameNode and pattern.
502 */
503 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
504 ASSERT_NE(select, nullptr);
505 auto selectPattern = select->GetPattern<SelectPattern>();
506 ASSERT_NE(selectPattern, nullptr);
507 auto menuNode = selectPattern->GetMenuNode();
508 ASSERT_NE(menuNode, nullptr);
509 auto menuPattern = menuNode->GetPattern<MenuPattern>();
510 ASSERT_NE(menuPattern, nullptr);
511 /**
512 * @tc.steps: step3. Call OnModifyDone.
513 * @tc.expected: the function runs normally
514 */
515 selectPattern->OnModifyDone();
516 auto val = menuNode->isRestoreInfoUsed_;
517
518 EXPECT_NE(val, false);
519 }
520
521 /**
522 * @tc.name: OnModifyDone010
523 * @tc.desc: Test SelectPattern OnModifyDone
524 * @tc.type: FUNC
525 */
526 HWTEST_F(SelectPatternTestNg, OnModifyDone010, TestSize.Level1)
527 {
528 SelectModelNG selectModelInstance;
529 /**
530 * @tc.steps: step1. Create select.
531 */
532 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
533 selectModelInstance.Create(params);
534 /**
535 * @tc.steps: step2. Get frameNode and pattern.
536 */
537 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
538 ASSERT_NE(select, nullptr);
539 auto selectPattern = select->GetPattern<SelectPattern>();
540 ASSERT_NE(selectPattern, nullptr);
541 auto menuNode = selectPattern->GetMenuNode();
542 ASSERT_NE(menuNode, nullptr);
543 auto menuPattern = menuNode->GetPattern<MenuPattern>();
544 ASSERT_NE(menuPattern, nullptr);
545 /**
546 * @tc.steps: step3. Call OnModifyDone.
547 * @tc.expected: the function runs normally
548 */
549 selectPattern->OnModifyDone();
550 auto val = selectPattern->isSelected_;
551
552 EXPECT_NE(val, true);
553 }
554
555 /**
556 * @tc.name: OnModifyDone011
557 * @tc.desc: Test SelectPattern OnModifyDone
558 * @tc.type: FUNC
559 */
560 HWTEST_F(SelectPatternTestNg, OnModifyDone011, TestSize.Level1)
561 {
562 SelectModelNG selectModelInstance;
563 /**
564 * @tc.steps: step1. Create select.
565 */
566 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
567 selectModelInstance.Create(params);
568 /**
569 * @tc.steps: step2. Get frameNode and pattern.
570 */
571 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
572 ASSERT_NE(select, nullptr);
573 auto selectPattern = select->GetPattern<SelectPattern>();
574 ASSERT_NE(selectPattern, nullptr);
575 auto menuNode = selectPattern->GetMenuNode();
576 ASSERT_NE(menuNode, nullptr);
577 auto menuPattern = menuNode->GetPattern<MenuPattern>();
578 ASSERT_NE(menuPattern, nullptr);
579 /**
580 * @tc.steps: step3. Call OnModifyDone.
581 * @tc.expected: the function runs normally
582 */
583 selectPattern->OnModifyDone();
584 auto val = selectPattern->isSelected_;
585
586 EXPECT_NE(val, true);
587 }
588
589 /**
590 * @tc.name: OnModifyDone012
591 * @tc.desc: Test SelectPattern OnModifyDone
592 * @tc.type: FUNC
593 */
594 HWTEST_F(SelectPatternTestNg, OnModifyDone0012, TestSize.Level1)
595 {
596 SelectModelNG selectModelInstance;
597 /**
598 * @tc.steps: step1. Create select.
599 */
600 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
601 selectModelInstance.Create(params);
602 /**
603 * @tc.steps: step2. Get frameNode and pattern.
604 */
605 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
606 ASSERT_NE(select, nullptr);
607 auto selectPattern = select->GetPattern<SelectPattern>();
608 ASSERT_NE(selectPattern, nullptr);
609 auto menuNode = selectPattern->GetMenuNode();
610 ASSERT_NE(menuNode, nullptr);
611 auto menuPattern = menuNode->GetPattern<MenuPattern>();
612 ASSERT_NE(menuPattern, nullptr);
613 /**
614 * @tc.steps: step3. Call OnModifyDone.
615 * @tc.expected: the function runs normally
616 */
617 selectPattern->OnModifyDone();
618 auto val = selectPattern->isSelected_;
619
620 EXPECT_NE(val, true);
621 }
622
623 /**
624 * @tc.name: OnModifyDone013
625 * @tc.desc: Test SelectPattern OnModifyDone
626 * @tc.type: FUNC
627 */
628 HWTEST_F(SelectPatternTestNg, OnModifyDone013, TestSize.Level1)
629 {
630 SelectModelNG selectModelInstance;
631 /**
632 * @tc.steps: step1. Create select.
633 */
634 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
635 { OPTION_TEXT_3, INTERNAL_SOURCE } };
636 selectModelInstance.Create(params);
637 /**
638 * @tc.steps: step2. Get frameNode and pattern.
639 */
640 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
641 ASSERT_NE(select, nullptr);
642 auto selectPattern = select->GetPattern<SelectPattern>();
643 ASSERT_NE(selectPattern, nullptr);
644 auto menuNode = selectPattern->GetMenuNode();
645 ASSERT_NE(menuNode, nullptr);
646 auto menuPattern = menuNode->GetPattern<MenuPattern>();
647 ASSERT_NE(menuPattern, nullptr);
648 /**
649 * @tc.steps: step3. Call OnModifyDone.
650 * @tc.expected: the function runs normally
651 */
652 selectPattern->OnModifyDone();
653 auto val = selectPattern->isSelected_;
654
655 EXPECT_NE(val, true);
656 }
657
658
659 /**
660 * @tc.name: SetItemSelected001
661 * @tc.desc: Test SelectPattern SetItemSelected
662 * @tc.type: FUNC
663 */
664 HWTEST_F(SelectPatternTestNg, SetItemSelected001, TestSize.Level1)
665 {
666 SelectModelNG selectModelInstance;
667 /**
668 * @tc.steps: step1. Create select.
669 */
670 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
671 selectModelInstance.Create(params);
672 /**
673 * @tc.steps: step2. Get frameNode and pattern.
674 */
675 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
676 ASSERT_NE(select, nullptr);
677 auto selectPattern = select->GetPattern<SelectPattern>();
678 ASSERT_NE(selectPattern, nullptr);
679 auto menuNode = selectPattern->GetMenuNode();
680 ASSERT_NE(menuNode, nullptr);
681 auto menuPattern = menuNode->GetPattern<MenuPattern>();
682 ASSERT_NE(menuPattern, nullptr);
683 /**
684 * @tc.steps: step3. Call SetItemSelected.
685 * @tc.expected: the function runs normally
686 */
687 selectPattern->SetItemSelected(0, "content");
688 auto val = selectPattern->isSelected_;
689
690 EXPECT_NE(val, false);
691 }
692
693 /**
694 * @tc.name: SetItemSelected002
695 * @tc.desc: Test SelectPattern SetItemSelected
696 * @tc.type: FUNC
697 */
698 HWTEST_F(SelectPatternTestNg, SetItemSelected002, TestSize.Level1)
699 {
700 SelectModelNG selectModelInstance;
701 /**
702 * @tc.steps: step1. Create select.
703 */
704 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
705 selectModelInstance.Create(params);
706 /**
707 * @tc.steps: step2. Get frameNode and pattern.
708 */
709 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
710 ASSERT_NE(select, nullptr);
711 auto selectPattern = select->GetPattern<SelectPattern>();
712 ASSERT_NE(selectPattern, nullptr);
713 auto menuNode = selectPattern->GetMenuNode();
714 ASSERT_NE(menuNode, nullptr);
715 auto menuPattern = menuNode->GetPattern<MenuPattern>();
716 ASSERT_NE(menuPattern, nullptr);
717 /**
718 * @tc.steps: step3. Call SetItemSelected.
719 * @tc.expected: the function runs normally
720 */
721 selectPattern->SetItemSelected(0, "content");
722 auto val = selectPattern->isSelected_;
723
724 EXPECT_NE(val, false);
725 }
726
727 /**
728 * @tc.name: SetItemSelected003
729 * @tc.desc: Test SelectPattern SetItemSelected
730 * @tc.type: FUNC
731 */
732 HWTEST_F(SelectPatternTestNg, SetItemSelected003, TestSize.Level1)
733 {
734 SelectModelNG selectModelInstance;
735 /**
736 * @tc.steps: step1. Create select.
737 */
738 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
739 selectModelInstance.Create(params);
740 /**
741 * @tc.steps: step2. Get frameNode and pattern.
742 */
743 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
744 ASSERT_NE(select, nullptr);
745 auto selectPattern = select->GetPattern<SelectPattern>();
746 ASSERT_NE(selectPattern, nullptr);
747 auto menuNode = selectPattern->GetMenuNode();
748 ASSERT_NE(menuNode, nullptr);
749 auto menuPattern = menuNode->GetPattern<MenuPattern>();
750 ASSERT_NE(menuPattern, nullptr);
751 /**
752 * @tc.steps: step3. Call SetItemSelected.
753 * @tc.expected: the function runs normally
754 */
755 selectPattern->SetItemSelected(0, "content");
756 auto val = selectPattern->isSelected_;
757
758 EXPECT_NE(val, false);
759 }
760
761 /**
762 * @tc.name: SetItemSelected004
763 * @tc.desc: Test SelectPattern SetItemSelected
764 * @tc.type: FUNC
765 */
766 HWTEST_F(SelectPatternTestNg, SetItemSelected004, TestSize.Level1)
767 {
768 SelectModelNG selectModelInstance;
769 /**
770 * @tc.steps: step1. Create select.
771 */
772 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
773 { OPTION_TEXT_3, INTERNAL_SOURCE } };
774 selectModelInstance.Create(params);
775 /**
776 * @tc.steps: step2. Get frameNode and pattern.
777 */
778 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
779 ASSERT_NE(select, nullptr);
780 auto selectPattern = select->GetPattern<SelectPattern>();
781 ASSERT_NE(selectPattern, nullptr);
782 auto menuNode = selectPattern->GetMenuNode();
783 ASSERT_NE(menuNode, nullptr);
784 auto menuPattern = menuNode->GetPattern<MenuPattern>();
785 ASSERT_NE(menuPattern, nullptr);
786 /**
787 * @tc.steps: step3. Call SetItemSelected.
788 * @tc.expected: the function runs normally
789 */
790 selectPattern->SetItemSelected(0, "content");
791 auto val = selectPattern->isSelected_;
792
793 EXPECT_NE(val, false);
794 }
795
796 /**
797 * @tc.name: SetItemSelected005
798 * @tc.desc: Test SelectPattern SetItemSelected
799 * @tc.type: FUNC
800 */
801 HWTEST_F(SelectPatternTestNg, SetItemSelected005, TestSize.Level1)
802 {
803 SelectModelNG selectModelInstance;
804 /**
805 * @tc.steps: step1. Create select.
806 */
807 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
808 selectModelInstance.Create(params);
809 /**
810 * @tc.steps: step2. Get frameNode and pattern.
811 */
812 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
813 ASSERT_NE(select, nullptr);
814 auto selectPattern = select->GetPattern<SelectPattern>();
815 ASSERT_NE(selectPattern, nullptr);
816 auto menuNode = selectPattern->GetMenuNode();
817 ASSERT_NE(menuNode, nullptr);
818 auto menuPattern = menuNode->GetPattern<MenuPattern>();
819 ASSERT_NE(menuPattern, nullptr);
820 /**
821 * @tc.steps: step3. Call SetItemSelected.
822 * @tc.expected: the function runs normally
823 */
824 selectPattern->SetItemSelected(1, "content");
825 auto val = selectPattern->isSelected_;
826
827 EXPECT_NE(val, false);
828 }
829
830 /**
831 * @tc.name: SetItemSelected006
832 * @tc.desc: Test SelectPattern SetItemSelected
833 * @tc.type: FUNC
834 */
835 HWTEST_F(SelectPatternTestNg, SetItemSelected006, TestSize.Level1)
836 {
837 SelectModelNG selectModelInstance;
838 /**
839 * @tc.steps: step1. Create select.
840 */
841 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
842 selectModelInstance.Create(params);
843 /**
844 * @tc.steps: step2. Get frameNode and pattern.
845 */
846 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
847 ASSERT_NE(select, nullptr);
848 auto selectPattern = select->GetPattern<SelectPattern>();
849 ASSERT_NE(selectPattern, nullptr);
850 auto menuNode = selectPattern->GetMenuNode();
851 ASSERT_NE(menuNode, nullptr);
852 auto menuPattern = menuNode->GetPattern<MenuPattern>();
853 ASSERT_NE(menuPattern, nullptr);
854 /**
855 * @tc.steps: step3. Call SetItemSelected.
856 * @tc.expected: the function runs normally
857 */
858 selectPattern->SetItemSelected(1, "content");
859 auto val = selectPattern->isSelected_;
860
861 EXPECT_NE(val, false);
862 }
863
864 /**
865 * @tc.name: SetItemSelected007
866 * @tc.desc: Test SelectPattern SetItemSelected
867 * @tc.type: FUNC
868 */
869 HWTEST_F(SelectPatternTestNg, SetItemSelected007, TestSize.Level1)
870 {
871 SelectModelNG selectModelInstance;
872 /**
873 * @tc.steps: step1. Create select.
874 */
875 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
876 selectModelInstance.Create(params);
877 /**
878 * @tc.steps: step2. Get frameNode and pattern.
879 */
880 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
881 ASSERT_NE(select, nullptr);
882 auto selectPattern = select->GetPattern<SelectPattern>();
883 ASSERT_NE(selectPattern, nullptr);
884 auto menuNode = selectPattern->GetMenuNode();
885 ASSERT_NE(menuNode, nullptr);
886 auto menuPattern = menuNode->GetPattern<MenuPattern>();
887 ASSERT_NE(menuPattern, nullptr);
888 /**
889 * @tc.steps: step3. Call SetItemSelected.
890 * @tc.expected: the function runs normally
891 */
892 selectPattern->SetItemSelected(1, "content");
893 auto val = selectPattern->isSelected_;
894
895 EXPECT_NE(val, false);
896 }
897
898 /**
899 * @tc.name: SetItemSelected008
900 * @tc.desc: Test SelectPattern SetItemSelected
901 * @tc.type: FUNC
902 */
903 HWTEST_F(SelectPatternTestNg, SetItemSelected008, TestSize.Level1)
904 {
905 SelectModelNG selectModelInstance;
906 /**
907 * @tc.steps: step1. Create select.
908 */
909 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
910 { OPTION_TEXT_3, INTERNAL_SOURCE } };
911 selectModelInstance.Create(params);
912 /**
913 * @tc.steps: step2. Get frameNode and pattern.
914 */
915 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
916 ASSERT_NE(select, nullptr);
917 auto selectPattern = select->GetPattern<SelectPattern>();
918 ASSERT_NE(selectPattern, nullptr);
919 auto menuNode = selectPattern->GetMenuNode();
920 ASSERT_NE(menuNode, nullptr);
921 auto menuPattern = menuNode->GetPattern<MenuPattern>();
922 ASSERT_NE(menuPattern, nullptr);
923 /**
924 * @tc.steps: step3. Call SetItemSelected.
925 * @tc.expected: the function runs normally
926 */
927 selectPattern->SetItemSelected(1, "content");
928 auto val = selectPattern->isSelected_;
929
930 EXPECT_NE(val, false);
931 }
932
933 /**
934 * @tc.name: SetItemSelected009
935 * @tc.desc: Test SelectPattern SetItemSelected
936 * @tc.type: FUNC
937 */
938 HWTEST_F(SelectPatternTestNg, SetItemSelected009, TestSize.Level1)
939 {
940 SelectModelNG selectModelInstance;
941 /**
942 * @tc.steps: step1. Create select.
943 */
944 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
945 selectModelInstance.Create(params);
946 /**
947 * @tc.steps: step2. Get frameNode and pattern.
948 */
949 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
950 ASSERT_NE(select, nullptr);
951 auto selectPattern = select->GetPattern<SelectPattern>();
952 ASSERT_NE(selectPattern, nullptr);
953 auto menuNode = selectPattern->GetMenuNode();
954 ASSERT_NE(menuNode, nullptr);
955 auto menuPattern = menuNode->GetPattern<MenuPattern>();
956 ASSERT_NE(menuPattern, nullptr);
957 /**
958 * @tc.steps: step3. Call SetItemSelected.
959 * @tc.expected: the function runs normally
960 */
961 selectPattern->SetItemSelected(2, ITEM_TEXT);
962 auto val = selectPattern->isSelected_;
963
964 EXPECT_NE(val, false);
965 }
966
967 /**
968 * @tc.name: SetItemSelected010
969 * @tc.desc: Test SelectPattern SetItemSelected
970 * @tc.type: FUNC
971 */
972 HWTEST_F(SelectPatternTestNg, SetItemSelected010, TestSize.Level1)
973 {
974 SelectModelNG selectModelInstance;
975 /**
976 * @tc.steps: step1. Create select.
977 */
978 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
979 selectModelInstance.Create(params);
980 /**
981 * @tc.steps: step2. Get frameNode and pattern.
982 */
983 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
984 ASSERT_NE(select, nullptr);
985 auto selectPattern = select->GetPattern<SelectPattern>();
986 ASSERT_NE(selectPattern, nullptr);
987 auto menuNode = selectPattern->GetMenuNode();
988 ASSERT_NE(menuNode, nullptr);
989 auto menuPattern = menuNode->GetPattern<MenuPattern>();
990 ASSERT_NE(menuPattern, nullptr);
991 /**
992 * @tc.steps: step3. Call SetItemSelected.
993 * @tc.expected: the function runs normally
994 */
995 selectPattern->SetItemSelected(2, ITEM_TEXT);
996 auto val = selectPattern->isSelected_;
997
998 EXPECT_NE(val, false);
999 }
1000
1001 /**
1002 * @tc.name: SetItemSelected011
1003 * @tc.desc: Test SelectPattern SetItemSelected
1004 * @tc.type: FUNC
1005 */
1006 HWTEST_F(SelectPatternTestNg, SetItemSelected011, TestSize.Level1)
1007 {
1008 SelectModelNG selectModelInstance;
1009 /**
1010 * @tc.steps: step1. Create select.
1011 */
1012 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1013 selectModelInstance.Create(params);
1014 /**
1015 * @tc.steps: step2. Get frameNode and pattern.
1016 */
1017 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1018 ASSERT_NE(select, nullptr);
1019 auto selectPattern = select->GetPattern<SelectPattern>();
1020 ASSERT_NE(selectPattern, nullptr);
1021 auto menuNode = selectPattern->GetMenuNode();
1022 ASSERT_NE(menuNode, nullptr);
1023 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1024 ASSERT_NE(menuPattern, nullptr);
1025 /**
1026 * @tc.steps: step3. Call SetItemSelected.
1027 * @tc.expected: the function runs normally
1028 */
1029 selectPattern->SetItemSelected(2, ITEM_TEXT);
1030 auto val = selectPattern->isSelected_;
1031
1032 EXPECT_NE(val, false);
1033 }
1034
1035 /**
1036 * @tc.name: SetItemSelected012
1037 * @tc.desc: Test SelectPattern SetItemSelected
1038 * @tc.type: FUNC
1039 */
1040 HWTEST_F(SelectPatternTestNg, SetItemSelected012, TestSize.Level1)
1041 {
1042 SelectModelNG selectModelInstance;
1043 /**
1044 * @tc.steps: step1. Create select.
1045 */
1046 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1047 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1048 selectModelInstance.Create(params);
1049 /**
1050 * @tc.steps: step2. Get frameNode and pattern.
1051 */
1052 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1053 ASSERT_NE(select, nullptr);
1054 auto selectPattern = select->GetPattern<SelectPattern>();
1055 ASSERT_NE(selectPattern, nullptr);
1056 auto menuNode = selectPattern->GetMenuNode();
1057 ASSERT_NE(menuNode, nullptr);
1058 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1059 ASSERT_NE(menuPattern, nullptr);
1060 /**
1061 * @tc.steps: step3. Call SetItemSelected.
1062 * @tc.expected: the function runs normally
1063 */
1064 selectPattern->SetItemSelected(2, ITEM_TEXT);
1065 auto val = selectPattern->isSelected_;
1066
1067 EXPECT_NE(val, false);
1068 }
1069
1070 /**
1071 * @tc.name: SetItemSelected013
1072 * @tc.desc: Test SelectPattern SetItemSelected
1073 * @tc.type: FUNC
1074 */
1075 HWTEST_F(SelectPatternTestNg, SetItemSelected013, TestSize.Level1)
1076 {
1077 SelectModelNG selectModelInstance;
1078 /**
1079 * @tc.steps: step1. Create select.
1080 */
1081 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1082 selectModelInstance.Create(params);
1083 /**
1084 * @tc.steps: step2. Get frameNode and pattern.
1085 */
1086 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1087 ASSERT_NE(select, nullptr);
1088 auto selectPattern = select->GetPattern<SelectPattern>();
1089 ASSERT_NE(selectPattern, nullptr);
1090 auto menuNode = selectPattern->GetMenuNode();
1091 ASSERT_NE(menuNode, nullptr);
1092 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1093 ASSERT_NE(menuPattern, nullptr);
1094 /**
1095 * @tc.steps: step3. Call SetItemSelected.
1096 * @tc.expected: the function runs normally
1097 */
1098 selectPattern->SetItemSelected(3, ITEM_TEXT);
1099 auto val = selectPattern->isSelected_;
1100
1101 EXPECT_NE(val, false);
1102 }
1103
1104 /**
1105 * @tc.name: SetItemSelected014
1106 * @tc.desc: Test SelectPattern SetItemSelected
1107 * @tc.type: FUNC
1108 */
1109 HWTEST_F(SelectPatternTestNg, SetItemSelected014, TestSize.Level1)
1110 {
1111 SelectModelNG selectModelInstance;
1112 /**
1113 * @tc.steps: step1. Create select.
1114 */
1115 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
1116 selectModelInstance.Create(params);
1117 /**
1118 * @tc.steps: step2. Get frameNode and pattern.
1119 */
1120 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1121 ASSERT_NE(select, nullptr);
1122 auto selectPattern = select->GetPattern<SelectPattern>();
1123 ASSERT_NE(selectPattern, nullptr);
1124 auto menuNode = selectPattern->GetMenuNode();
1125 ASSERT_NE(menuNode, nullptr);
1126 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1127 ASSERT_NE(menuPattern, nullptr);
1128 /**
1129 * @tc.steps: step3. Call SetItemSelected.
1130 * @tc.expected: the function runs normally
1131 */
1132 selectPattern->SetItemSelected(3, ITEM_TEXT);
1133 auto val = selectPattern->isSelected_;
1134
1135 EXPECT_NE(val, false);
1136 }
1137
1138 /**
1139 * @tc.name: SetItemSelected015
1140 * @tc.desc: Test SelectPattern SetItemSelected
1141 * @tc.type: FUNC
1142 */
1143 HWTEST_F(SelectPatternTestNg, SetItemSelected015, TestSize.Level1)
1144 {
1145 SelectModelNG selectModelInstance;
1146 /**
1147 * @tc.steps: step1. Create select.
1148 */
1149 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1150 selectModelInstance.Create(params);
1151 /**
1152 * @tc.steps: step2. Get frameNode and pattern.
1153 */
1154 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1155 ASSERT_NE(select, nullptr);
1156 auto selectPattern = select->GetPattern<SelectPattern>();
1157 ASSERT_NE(selectPattern, nullptr);
1158 auto menuNode = selectPattern->GetMenuNode();
1159 ASSERT_NE(menuNode, nullptr);
1160 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1161 ASSERT_NE(menuPattern, nullptr);
1162 /**
1163 * @tc.steps: step3. Call SetItemSelected.
1164 * @tc.expected: the function runs normally
1165 */
1166 selectPattern->SetItemSelected(3, ITEM_TEXT);
1167 auto val = selectPattern->isSelected_;
1168
1169 EXPECT_NE(val, false);
1170 }
1171
1172 /**
1173 * @tc.name: SetItemSelected016
1174 * @tc.desc: Test SelectPattern SetItemSelected
1175 * @tc.type: FUNC
1176 */
1177 HWTEST_F(SelectPatternTestNg, SetItemSelected016, TestSize.Level1)
1178 {
1179 SelectModelNG selectModelInstance;
1180 /**
1181 * @tc.steps: step1. Create select.
1182 */
1183 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1184 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1185 selectModelInstance.Create(params);
1186 /**
1187 * @tc.steps: step2. Get frameNode and pattern.
1188 */
1189 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1190 ASSERT_NE(select, nullptr);
1191 auto selectPattern = select->GetPattern<SelectPattern>();
1192 ASSERT_NE(selectPattern, nullptr);
1193 auto menuNode = selectPattern->GetMenuNode();
1194 ASSERT_NE(menuNode, nullptr);
1195 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1196 ASSERT_NE(menuPattern, nullptr);
1197 /**
1198 * @tc.steps: step3. Call SetItemSelected.
1199 * @tc.expected: the function runs normally
1200 */
1201 selectPattern->SetItemSelected(3, ITEM_TEXT);
1202 auto val = selectPattern->isSelected_;
1203
1204 EXPECT_NE(val, false);
1205 }
1206
1207 /**
1208 * @tc.name: SetItemSelected017
1209 * @tc.desc: Test SelectPattern SetItemSelected
1210 * @tc.type: FUNC
1211 */
1212 HWTEST_F(SelectPatternTestNg, SetItemSelected017, TestSize.Level1)
1213 {
1214 SelectModelNG selectModelInstance;
1215 /**
1216 * @tc.steps: step1. Create select.
1217 */
1218 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1219 selectModelInstance.Create(params);
1220 /**
1221 * @tc.steps: step2. Get frameNode and pattern.
1222 */
1223 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1224 ASSERT_NE(select, nullptr);
1225 auto selectPattern = select->GetPattern<SelectPattern>();
1226 ASSERT_NE(selectPattern, nullptr);
1227 auto menuNode = selectPattern->GetMenuNode();
1228 ASSERT_NE(menuNode, nullptr);
1229 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1230 ASSERT_NE(menuPattern, nullptr);
1231 /**
1232 * @tc.steps: step3. Call SetItemSelected.
1233 * @tc.expected: the function runs normally
1234 */
1235 selectPattern->SetItemSelected(0, "content");
1236 auto val = selectPattern->GetSelected();
1237
1238 EXPECT_EQ(val, 0);
1239 }
1240
1241 /**
1242 * @tc.name: SetItemSelected018
1243 * @tc.desc: Test SelectPattern SetItemSelected
1244 * @tc.type: FUNC
1245 */
1246 HWTEST_F(SelectPatternTestNg, SetItemSelected018, TestSize.Level1)
1247 {
1248 SelectModelNG selectModelInstance;
1249 /**
1250 * @tc.steps: step1. Create select.
1251 */
1252 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
1253 selectModelInstance.Create(params);
1254 /**
1255 * @tc.steps: step2. Get frameNode and pattern.
1256 */
1257 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1258 ASSERT_NE(select, nullptr);
1259 auto selectPattern = select->GetPattern<SelectPattern>();
1260 ASSERT_NE(selectPattern, nullptr);
1261 auto menuNode = selectPattern->GetMenuNode();
1262 ASSERT_NE(menuNode, nullptr);
1263 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1264 ASSERT_NE(menuPattern, nullptr);
1265 /**
1266 * @tc.steps: step3. Call SetItemSelected.
1267 * @tc.expected: the function runs normally
1268 */
1269 selectPattern->SetItemSelected(0, "content");
1270 auto val = selectPattern->GetSelected();
1271
1272 EXPECT_EQ(val, 0);
1273 }
1274
1275 /**
1276 * @tc.name: SetItemSelected019
1277 * @tc.desc: Test SelectPattern SetItemSelected
1278 * @tc.type: FUNC
1279 */
1280 HWTEST_F(SelectPatternTestNg, SetItemSelected019, TestSize.Level1)
1281 {
1282 SelectModelNG selectModelInstance;
1283 /**
1284 * @tc.steps: step1. Create select.
1285 */
1286 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1287 selectModelInstance.Create(params);
1288 /**
1289 * @tc.steps: step2. Get frameNode and pattern.
1290 */
1291 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1292 ASSERT_NE(select, nullptr);
1293 auto selectPattern = select->GetPattern<SelectPattern>();
1294 ASSERT_NE(selectPattern, nullptr);
1295 auto menuNode = selectPattern->GetMenuNode();
1296 ASSERT_NE(menuNode, nullptr);
1297 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1298 ASSERT_NE(menuPattern, nullptr);
1299 /**
1300 * @tc.steps: step3. Call SetItemSelected.
1301 * @tc.expected: the function runs normally
1302 */
1303 selectPattern->SetItemSelected(0, "content");
1304 auto val = selectPattern->GetSelected();
1305
1306 EXPECT_EQ(val, 0);
1307 }
1308
1309 /**
1310 * @tc.name: SetItemSelected020
1311 * @tc.desc: Test SelectPattern SetItemSelected
1312 * @tc.type: FUNC
1313 */
1314 HWTEST_F(SelectPatternTestNg, SetItemSelected020, TestSize.Level1)
1315 {
1316 SelectModelNG selectModelInstance;
1317 /**
1318 * @tc.steps: step1. Create select.
1319 */
1320 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1321 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1322 selectModelInstance.Create(params);
1323 /**
1324 * @tc.steps: step2. Get frameNode and pattern.
1325 */
1326 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1327 ASSERT_NE(select, nullptr);
1328 auto selectPattern = select->GetPattern<SelectPattern>();
1329 ASSERT_NE(selectPattern, nullptr);
1330 auto menuNode = selectPattern->GetMenuNode();
1331 ASSERT_NE(menuNode, nullptr);
1332 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1333 ASSERT_NE(menuPattern, nullptr);
1334 /**
1335 * @tc.steps: step3. Call SetItemSelected.
1336 * @tc.expected: the function runs normally
1337 */
1338 selectPattern->SetItemSelected(0, "content");
1339 auto val = selectPattern->GetSelected();
1340
1341 EXPECT_EQ(val, 0);
1342 }
1343
1344 /**
1345 * @tc.name: SetItemSelected021
1346 * @tc.desc: Test SelectPattern SetItemSelected
1347 * @tc.type: FUNC
1348 */
1349 HWTEST_F(SelectPatternTestNg, SetItemSelected021, TestSize.Level1)
1350 {
1351 SelectModelNG selectModelInstance;
1352 /**
1353 * @tc.steps: step1. Create select.
1354 */
1355 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1356 selectModelInstance.Create(params);
1357 /**
1358 * @tc.steps: step2. Get frameNode and pattern.
1359 */
1360 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1361 ASSERT_NE(select, nullptr);
1362 auto selectPattern = select->GetPattern<SelectPattern>();
1363 ASSERT_NE(selectPattern, nullptr);
1364 auto menuNode = selectPattern->GetMenuNode();
1365 ASSERT_NE(menuNode, nullptr);
1366 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1367 ASSERT_NE(menuPattern, nullptr);
1368 /**
1369 * @tc.steps: step3. Call SetItemSelected.
1370 * @tc.expected: the function runs normally
1371 */
1372 selectPattern->SetItemSelected(1, "content");
1373 auto val = selectPattern->GetSelected();
1374
1375 EXPECT_EQ(val, -1);
1376 }
1377
1378 /**
1379 * @tc.name: SetItemSelected022
1380 * @tc.desc: Test SelectPattern SetItemSelected
1381 * @tc.type: FUNC
1382 */
1383 HWTEST_F(SelectPatternTestNg, SetItemSelected022, TestSize.Level1)
1384 {
1385 SelectModelNG selectModelInstance;
1386 /**
1387 * @tc.steps: step1. Create select.
1388 */
1389 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
1390 selectModelInstance.Create(params);
1391 /**
1392 * @tc.steps: step2. Get frameNode and pattern.
1393 */
1394 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1395 ASSERT_NE(select, nullptr);
1396 auto selectPattern = select->GetPattern<SelectPattern>();
1397 ASSERT_NE(selectPattern, nullptr);
1398 auto menuNode = selectPattern->GetMenuNode();
1399 ASSERT_NE(menuNode, nullptr);
1400 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1401 ASSERT_NE(menuPattern, nullptr);
1402 /**
1403 * @tc.steps: step3. Call SetItemSelected.
1404 * @tc.expected: the function runs normally
1405 */
1406 selectPattern->SetItemSelected(1, "content");
1407 auto val = selectPattern->GetSelected();
1408
1409 EXPECT_EQ(val, -1);
1410 }
1411
1412 /**
1413 * @tc.name: SetItemSelected023
1414 * @tc.desc: Test SelectPattern SetItemSelected
1415 * @tc.type: FUNC
1416 */
1417 HWTEST_F(SelectPatternTestNg, SetItemSelected023, TestSize.Level1)
1418 {
1419 SelectModelNG selectModelInstance;
1420 /**
1421 * @tc.steps: step1. Create select.
1422 */
1423 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1424 selectModelInstance.Create(params);
1425 /**
1426 * @tc.steps: step2. Get frameNode and pattern.
1427 */
1428 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1429 ASSERT_NE(select, nullptr);
1430 auto selectPattern = select->GetPattern<SelectPattern>();
1431 ASSERT_NE(selectPattern, nullptr);
1432 auto menuNode = selectPattern->GetMenuNode();
1433 ASSERT_NE(menuNode, nullptr);
1434 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1435 ASSERT_NE(menuPattern, nullptr);
1436 /**
1437 * @tc.steps: step3. Call SetItemSelected.
1438 * @tc.expected: the function runs normally
1439 */
1440 selectPattern->SetItemSelected(1, "content");
1441 auto val = selectPattern->GetSelected();
1442
1443 EXPECT_EQ(val, -1);
1444 }
1445
1446 /**
1447 * @tc.name: SetItemSelected024
1448 * @tc.desc: Test SelectPattern SetItemSelected
1449 * @tc.type: FUNC
1450 */
1451 HWTEST_F(SelectPatternTestNg, SetItemSelected024, TestSize.Level1)
1452 {
1453 SelectModelNG selectModelInstance;
1454 /**
1455 * @tc.steps: step1. Create select.
1456 */
1457 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1458 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1459 selectModelInstance.Create(params);
1460 /**
1461 * @tc.steps: step2. Get frameNode and pattern.
1462 */
1463 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1464 ASSERT_NE(select, nullptr);
1465 auto selectPattern = select->GetPattern<SelectPattern>();
1466 ASSERT_NE(selectPattern, nullptr);
1467 auto menuNode = selectPattern->GetMenuNode();
1468 ASSERT_NE(menuNode, nullptr);
1469 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1470 ASSERT_NE(menuPattern, nullptr);
1471 /**
1472 * @tc.steps: step3. Call SetItemSelected.
1473 * @tc.expected: the function runs normally
1474 */
1475 selectPattern->SetItemSelected(1, "content");
1476 auto val = selectPattern->GetSelected();
1477
1478 EXPECT_EQ(val, 1);
1479 }
1480
1481 /**
1482 * @tc.name: SetItemSelected025
1483 * @tc.desc: Test SelectPattern SetItemSelected
1484 * @tc.type: FUNC
1485 */
1486 HWTEST_F(SelectPatternTestNg, SetItemSelected025, TestSize.Level1)
1487 {
1488 SelectModelNG selectModelInstance;
1489 /**
1490 * @tc.steps: step1. Create select.
1491 */
1492 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1493 selectModelInstance.Create(params);
1494 /**
1495 * @tc.steps: step2. Get frameNode and pattern.
1496 */
1497 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1498 ASSERT_NE(select, nullptr);
1499 auto selectPattern = select->GetPattern<SelectPattern>();
1500 ASSERT_NE(selectPattern, nullptr);
1501 auto menuNode = selectPattern->GetMenuNode();
1502 ASSERT_NE(menuNode, nullptr);
1503 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1504 ASSERT_NE(menuPattern, nullptr);
1505 /**
1506 * @tc.steps: step3. Call SetItemSelected.
1507 * @tc.expected: the function runs normally
1508 */
1509 selectPattern->SetItemSelected(2, ITEM_TEXT);
1510 auto val = selectPattern->GetSelected();
1511
1512 EXPECT_EQ(val, -1);
1513 }
1514
1515 /**
1516 * @tc.name: SetItemSelected026
1517 * @tc.desc: Test SelectPattern SetItemSelected
1518 * @tc.type: FUNC
1519 */
1520 HWTEST_F(SelectPatternTestNg, SetItemSelected026, TestSize.Level1)
1521 {
1522 SelectModelNG selectModelInstance;
1523 /**
1524 * @tc.steps: step1. Create select.
1525 */
1526 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
1527 selectModelInstance.Create(params);
1528 /**
1529 * @tc.steps: step2. Get frameNode and pattern.
1530 */
1531 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1532 ASSERT_NE(select, nullptr);
1533 auto selectPattern = select->GetPattern<SelectPattern>();
1534 ASSERT_NE(selectPattern, nullptr);
1535 auto menuNode = selectPattern->GetMenuNode();
1536 ASSERT_NE(menuNode, nullptr);
1537 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1538 ASSERT_NE(menuPattern, nullptr);
1539 /**
1540 * @tc.steps: step3. Call SetItemSelected.
1541 * @tc.expected: the function runs normally
1542 */
1543 selectPattern->SetItemSelected(2, ITEM_TEXT);
1544 auto val = selectPattern->GetSelected();
1545
1546 EXPECT_EQ(val, -1);
1547 }
1548
1549 /**
1550 * @tc.name: SetItemSelected027
1551 * @tc.desc: Test SelectPattern SetItemSelected
1552 * @tc.type: FUNC
1553 */
1554 HWTEST_F(SelectPatternTestNg, SetItemSelected027, TestSize.Level1)
1555 {
1556 SelectModelNG selectModelInstance;
1557 /**
1558 * @tc.steps: step1. Create select.
1559 */
1560 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1561 selectModelInstance.Create(params);
1562 /**
1563 * @tc.steps: step2. Get frameNode and pattern.
1564 */
1565 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1566 ASSERT_NE(select, nullptr);
1567 auto selectPattern = select->GetPattern<SelectPattern>();
1568 ASSERT_NE(selectPattern, nullptr);
1569 auto menuNode = selectPattern->GetMenuNode();
1570 ASSERT_NE(menuNode, nullptr);
1571 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1572 ASSERT_NE(menuPattern, nullptr);
1573 /**
1574 * @tc.steps: step3. Call SetItemSelected.
1575 * @tc.expected: the function runs normally
1576 */
1577 selectPattern->SetItemSelected(2, ITEM_TEXT);
1578 auto val = selectPattern->GetSelected();
1579
1580 EXPECT_EQ(val, -1);
1581 }
1582
1583 /**
1584 * @tc.name: SetItemSelected028
1585 * @tc.desc: Test SelectPattern SetItemSelected
1586 * @tc.type: FUNC
1587 */
1588 HWTEST_F(SelectPatternTestNg, SetItemSelected028, TestSize.Level1)
1589 {
1590 SelectModelNG selectModelInstance;
1591 /**
1592 * @tc.steps: step1. Create select.
1593 */
1594 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1595 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1596 selectModelInstance.Create(params);
1597 /**
1598 * @tc.steps: step2. Get frameNode and pattern.
1599 */
1600 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1601 ASSERT_NE(select, nullptr);
1602 auto selectPattern = select->GetPattern<SelectPattern>();
1603 ASSERT_NE(selectPattern, nullptr);
1604 auto menuNode = selectPattern->GetMenuNode();
1605 ASSERT_NE(menuNode, nullptr);
1606 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1607 ASSERT_NE(menuPattern, nullptr);
1608 /**
1609 * @tc.steps: step3. Call SetItemSelected.
1610 * @tc.expected: the function runs normally
1611 */
1612 selectPattern->SetItemSelected(2, ITEM_TEXT);
1613 auto val = selectPattern->GetSelected();
1614
1615 EXPECT_EQ(val, 2);
1616 }
1617
1618 /**
1619 * @tc.name: SetItemSelected029
1620 * @tc.desc: Test SelectPattern SetItemSelected
1621 * @tc.type: FUNC
1622 */
1623 HWTEST_F(SelectPatternTestNg, SetItemSelected029, TestSize.Level1)
1624 {
1625 SelectModelNG selectModelInstance;
1626 /**
1627 * @tc.steps: step1. Create select.
1628 */
1629 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1630 selectModelInstance.Create(params);
1631 /**
1632 * @tc.steps: step2. Get frameNode and pattern.
1633 */
1634 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1635 ASSERT_NE(select, nullptr);
1636 auto selectPattern = select->GetPattern<SelectPattern>();
1637 ASSERT_NE(selectPattern, nullptr);
1638 auto menuNode = selectPattern->GetMenuNode();
1639 ASSERT_NE(menuNode, nullptr);
1640 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1641 ASSERT_NE(menuPattern, nullptr);
1642 /**
1643 * @tc.steps: step3. Call SetItemSelected.
1644 * @tc.expected: the function runs normally
1645 */
1646 selectPattern->SetItemSelected(3, ITEM_TEXT);
1647 auto val = selectPattern->GetSelected();
1648
1649 EXPECT_EQ(val, -1);
1650 }
1651
1652 /**
1653 * @tc.name: SetItemSelected030
1654 * @tc.desc: Test SelectPattern SetItemSelected
1655 * @tc.type: FUNC
1656 */
1657 HWTEST_F(SelectPatternTestNg, SetItemSelected030, TestSize.Level1)
1658 {
1659 SelectModelNG selectModelInstance;
1660 /**
1661 * @tc.steps: step1. Create select.
1662 */
1663 std::vector<SelectParam> params = { { OPTION_TEXT_2, INTERNAL_SOURCE } };
1664 selectModelInstance.Create(params);
1665 /**
1666 * @tc.steps: step2. Get frameNode and pattern.
1667 */
1668 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1669 ASSERT_NE(select, nullptr);
1670 auto selectPattern = select->GetPattern<SelectPattern>();
1671 ASSERT_NE(selectPattern, nullptr);
1672 auto menuNode = selectPattern->GetMenuNode();
1673 ASSERT_NE(menuNode, nullptr);
1674 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1675 ASSERT_NE(menuPattern, nullptr);
1676 /**
1677 * @tc.steps: step3. Call SetItemSelected.
1678 * @tc.expected: the function runs normally
1679 */
1680 selectPattern->SetItemSelected(3, ITEM_TEXT);
1681 auto val = selectPattern->GetSelected();
1682
1683 EXPECT_EQ(val, -1);
1684 }
1685
1686 /**
1687 * @tc.name: SetItemSelected031
1688 * @tc.desc: Test SelectPattern SetItemSelected
1689 * @tc.type: FUNC
1690 */
1691 HWTEST_F(SelectPatternTestNg, SetItemSelected031, TestSize.Level1)
1692 {
1693 SelectModelNG selectModelInstance;
1694 /**
1695 * @tc.steps: step1. Create select.
1696 */
1697 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
1698 selectModelInstance.Create(params);
1699 /**
1700 * @tc.steps: step2. Get frameNode and pattern.
1701 */
1702 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1703 ASSERT_NE(select, nullptr);
1704 auto selectPattern = select->GetPattern<SelectPattern>();
1705 ASSERT_NE(selectPattern, nullptr);
1706 auto menuNode = selectPattern->GetMenuNode();
1707 ASSERT_NE(menuNode, nullptr);
1708 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1709 ASSERT_NE(menuPattern, nullptr);
1710 /**
1711 * @tc.steps: step3. Call SetItemSelected.
1712 * @tc.expected: the function runs normally
1713 */
1714 selectPattern->SetItemSelected(3, ITEM_TEXT);
1715 auto val = selectPattern->GetSelected();
1716
1717 EXPECT_EQ(val, -1);
1718 }
1719
1720 /**
1721 * @tc.name: SetItemSelected032
1722 * @tc.desc: Test SelectPattern SetItemSelected
1723 * @tc.type: FUNC
1724 */
1725 HWTEST_F(SelectPatternTestNg, SetItemSelected032, TestSize.Level1)
1726 {
1727 SelectModelNG selectModelInstance;
1728 /**
1729 * @tc.steps: step1. Create select.
1730 */
1731 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1732 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1733 selectModelInstance.Create(params);
1734 /**
1735 * @tc.steps: step2. Get frameNode and pattern.
1736 */
1737 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1738 ASSERT_NE(select, nullptr);
1739 auto selectPattern = select->GetPattern<SelectPattern>();
1740 ASSERT_NE(selectPattern, nullptr);
1741 auto menuNode = selectPattern->GetMenuNode();
1742 ASSERT_NE(menuNode, nullptr);
1743 auto menuPattern = menuNode->GetPattern<MenuPattern>();
1744 ASSERT_NE(menuPattern, nullptr);
1745 /**
1746 * @tc.steps: step3. Call SetItemSelected.
1747 * @tc.expected: the function runs normally
1748 */
1749 selectPattern->SetItemSelected(3, ITEM_TEXT);
1750 auto val = selectPattern->GetSelected();
1751
1752 EXPECT_EQ(val, -1);
1753 }
1754
1755 /**
1756 * @tc.name: SetControlSize001
1757 * @tc.desc: Test SelectPattern SetControlSize
1758 * @tc.type: FUNC
1759 */
1760 HWTEST_F(SelectPatternTestNg, SetControlSize001, TestSize.Level1)
1761 {
1762 int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
1763 AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
1764 SelectModelNG selectModelInstance;
1765 /**
1766 * @tc.steps: step1. Get frameNode and pattern.
1767 */
1768 auto *selectFrameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1769 ASSERT_NE(selectFrameNode, nullptr);
1770 auto selectPattern = selectFrameNode->GetPattern<SelectPattern>();
1771 ASSERT_NE(selectPattern, nullptr);
1772
1773 /**
1774 * @tc.steps: step2. Call SetControlSize.
1775 * @tc.expected: the function runs normally
1776 */
1777 selectPattern->SetControlSize(ControlSize::SMALL);
1778 auto controlSize = selectPattern->GetControlSize();
1779 EXPECT_EQ(ControlSize::SMALL, controlSize);
1780 AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
1781 }
1782
1783 /**
1784 * @tc.name: UpdateTargetSize
1785 * @tc.desc: Test SelectPattern UpdateTargetSize
1786 * @tc.type: FUNC
1787 */
1788 HWTEST_F(SelectPatternTestNg, UpdateTargetSize001, TestSize.Level1)
1789 {
1790 SelectModelNG selectModelInstance;
1791 /**
1792 * @tc.steps: step1. Create select.
1793 */
1794 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
1795 selectModelInstance.Create(params);
1796 /**
1797 * @tc.steps: step2. Get frameNode and pattern.
1798 */
1799 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1800 ASSERT_NE(select, nullptr);
1801 auto selectPattern = select->GetPattern<SelectPattern>();
1802 ASSERT_NE(selectPattern, nullptr);
1803 /**
1804 * @tc.steps: step3. Call UpdateTargetSize.
1805 * @tc.expected: the menu targetSize equal selectSize_
1806 */
1807 selectPattern->SetSelectSize(SizeF(SELECT_WIDTH, SELECT_HEIGHT));
1808 selectPattern->UpdateTargetSize();
1809 auto menu = selectPattern->GetMenuNode();
1810 ASSERT_NE(menu, nullptr);
1811 auto menuLayoutProps = menu->GetLayoutProperty<MenuLayoutProperty>();
1812 ASSERT_NE(menuLayoutProps, nullptr);
1813 auto targetSize = menuLayoutProps->GetTargetSizeValue(SizeF());
1814 EXPECT_EQ(targetSize, SizeF(SELECT_WIDTH, SELECT_HEIGHT));
1815
1816 /**
1817 * @tc.steps: step4. Get a option.
1818 * @tc.expected: IsWidthModifiedBySelect false
1819 */
1820 auto optionCount = selectPattern->options_.size();
1821 ASSERT_NE(optionCount, 0);
1822 auto option = selectPattern->options_[0];
1823 auto optionPattern = option->GetPattern<MenuItemPattern>();
1824 ASSERT_NE(optionPattern, nullptr);
1825 EXPECT_FALSE(optionPattern->IsWidthModifiedBySelect());
1826 /**
1827 * @tc.steps: step5. make fitTrigger_ true and call UpdateTargetSize.
1828 * @tc.expected: IsWidthModifiedBySelect true
1829 */
1830 selectPattern->SetOptionWidthFitTrigger(true);
1831 selectPattern->UpdateTargetSize();
1832 EXPECT_TRUE(optionPattern->IsWidthModifiedBySelect());
1833 auto scroll = AceType::DynamicCast<FrameNode>(menu->GetFirstChild());
1834 ASSERT_NE(scroll, nullptr);
1835 auto scrollPattern = scroll->GetPattern<ScrollPattern>();
1836 ASSERT_NE(scrollPattern, nullptr);
1837 EXPECT_TRUE(scrollPattern->IsWidthModifiedBySelect());
1838 /**
1839 * @tc.steps: step6. get option paint property.
1840 * @tc.expected: GetSelectModifiedWidthValue equal SELECT_WIDTH
1841 */
1842 auto optionPaintProperty = option->GetPaintProperty<MenuItemPaintProperty>();
1843 CHECK_NULL_VOID(optionPaintProperty);
1844 auto selectModifiedWidth = optionPaintProperty->GetSelectModifiedWidthValue(0.0f);
1845 EXPECT_EQ(selectModifiedWidth, SELECT_WIDTH - OPTION_MARGIN.ConvertToPx());
1846 }
1847
1848 /**
1849 * @tc.name: InitFocusEventTest001
1850 * @tc.desc: Test SelectPattern::InitFocusEvent.
1851 * @tc.type: FUNC
1852 */
1853 HWTEST_F(SelectPatternTestNg, InitFocusEventTest001, TestSize.Level1)
1854 {
1855 /**
1856 * @tc.steps: step0. Create mock theme manager
1857 */
1858 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1859 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1860 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1861 selectTheme->optionApplyFocusedStyle_ = 1;
1862 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1863 EXPECT_CALL(*themeManager, GetTheme(_, _)).WillRepeatedly(Return(selectTheme));
1864 /**
1865 * @tc.steps: step1. Create select.
1866 */
1867 SelectModelNG selectModelInstance;
1868 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1869 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1870 selectModelInstance.Create(params);
1871 /**
1872 * @tc.steps: step2. Get frameNode and pattern.
1873 */
1874 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1875 ASSERT_NE(select, nullptr);
1876 auto selectPattern = select->GetPattern<SelectPattern>();
1877 ASSERT_NE(selectPattern, nullptr);
1878 auto renderContext = select->GetRenderContext();
1879 ASSERT_NE(renderContext, nullptr);
1880 renderContext->UpdateBackgroundColor(selectTheme->GetButtonBackgroundColor());
1881
1882 selectPattern->InitFocusEvent();
1883 selectPattern->HandleFocusStyleTask();
1884 selectPattern->AddIsFocusActiveUpdateEvent();
1885 selectPattern->SetFocusStyle();
1886 EXPECT_TRUE(selectPattern->shadowModify_);
1887 EXPECT_TRUE(selectPattern->scaleModify_);
1888 EXPECT_TRUE(selectPattern->bgColorModify_);
1889 EXPECT_EQ(renderContext->GetBackgroundColor(), selectTheme->GetSelectFocusedBackground());
1890 }
1891
1892 /**
1893 * @tc.name: InitFocusEventTest002
1894 * @tc.desc: Test SelectPattern::InitFocusEvent.
1895 * @tc.type: FUNC
1896 */
1897 HWTEST_F(SelectPatternTestNg, InitFocusEventTest002, TestSize.Level1)
1898 {
1899 /**
1900 * @tc.steps: step0. Create mock theme manager
1901 */
1902 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1903 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1904 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1905 selectTheme->optionApplyFocusedStyle_ = 1;
1906 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1907 EXPECT_CALL(*themeManager, GetTheme(_, _)).WillRepeatedly(Return(selectTheme));
1908 /**
1909 * @tc.steps: step1. Create select.
1910 */
1911 SelectModelNG selectModelInstance;
1912 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE }, { OPTION_TEXT_2, INTERNAL_SOURCE },
1913 { OPTION_TEXT_3, INTERNAL_SOURCE } };
1914 selectModelInstance.Create(params);
1915 /**
1916 * @tc.steps: step2. Get frameNode and pattern.
1917 */
1918 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
1919 ASSERT_NE(select, nullptr);
1920 auto selectPattern = select->GetPattern<SelectPattern>();
1921 ASSERT_NE(selectPattern, nullptr);
1922 auto renderContext = select->GetRenderContext();
1923 ASSERT_NE(renderContext, nullptr);
1924
1925 selectPattern->shadowModify_ = true;
1926 selectPattern->scaleModify_ = true;
1927 selectPattern->bgColorModify_ = true;
1928 selectPattern->focusTextColorModify_ = true;
1929 selectPattern->InitFocusEvent();
1930 selectPattern->HandleBlurStyleTask();
1931 selectPattern->RemoveIsFocusActiveUpdateEvent();
1932 selectPattern->ClearFocusStyle();
1933 EXPECT_FALSE(selectPattern->shadowModify_);
1934 EXPECT_FALSE(selectPattern->scaleModify_);
1935 EXPECT_FALSE(selectPattern->bgColorModify_);
1936 EXPECT_FALSE(selectPattern->focusTextColorModify_);
1937 EXPECT_EQ(renderContext->GetBackgroundColor(), selectTheme->GetButtonBackgroundColor());
1938 }
1939
1940 /**
1941 * @tc.name: SelectPatternTest001
1942 * @tc.desc: Test SelectPattern::BuildChild
1943 * @tc.type: FUNC
1944 */
1945 HWTEST_F(SelectPatternTestNg, SelectPatternTest001, TestSize.Level1)
1946 {
1947 /**
1948 * @tc.steps: step0. Create mock theme manager
1949 */
1950 auto themeManager = AceType::MakeRefPtr<MockThemeManager>();
1951 MockPipelineContext::GetCurrent()->SetThemeManager(themeManager);
1952 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
1953 selectTheme->optionApplyFocusedStyle_ = 1;
1954 EXPECT_CALL(*themeManager, GetTheme(_)).WillRepeatedly(Return(selectTheme));
1955 EXPECT_CALL(*themeManager, GetTheme(_, _)).WillRepeatedly(Return(selectTheme));
1956 /**
1957 * @tc.steps: step1. Create select model and select event.
1958 * @tc.expected: Objects are created successfully.
1959 */
1960 InspectorFilter filter;
1961 TestProperty testProperty;
1962 testProperty.FontSize = std::make_optional(FONT_SIZE_VALUE);
1963 auto selectNode = CreateSelect(CREATE_VALUE, testProperty);
1964 ASSERT_NE(selectNode, nullptr);
1965 auto childNode = FrameNode::CreateFrameNode(V2::ROW_ETS_TAG, 1, AceType::MakeRefPtr<Pattern>());
1966 childNode->MountToParent(selectNode);
1967 auto selectPattern = selectNode->GetPattern<SelectPattern>();
1968 ASSERT_NE(selectPattern, nullptr);
1969
1970 int32_t backupApiVersion = AceApplicationInfo::GetInstance().GetApiTargetVersion();
1971 AceApplicationInfo::GetInstance().SetApiTargetVersion(static_cast<int32_t>(PlatformVersion::VERSION_TWELVE));
1972 selectPattern->BuildChild();
1973 AceApplicationInfo::GetInstance().SetApiTargetVersion(backupApiVersion);
1974 auto renderContext = selectNode->GetRenderContext();
1975 EXPECT_EQ(selectNode->GetFirstChild()->GetTag(), V2::ROW_ETS_TAG);
1976 BorderColorProperty borderColor;
1977 borderColor.SetColor(selectTheme->GetSelectNormalBorderColor());
1978 EXPECT_EQ(renderContext->GetBorderColor(), borderColor);
1979 BorderWidthProperty borderWidth;
1980 borderWidth.SetBorderWidth(selectTheme->GetSelectNormalBorderWidth());
1981 EXPECT_EQ(renderContext->GetBorderWidth(), borderWidth);
1982 }
1983
1984 /**
1985 * @tc.name: SelectPatternTest002
1986 * @tc.desc: Test SetSelectOptionStyle.
1987 * @tc.type: FUNC
1988 */
1989 HWTEST_F(SelectPatternTestNg, SelectPatternTest002, TestSize.Level1)
1990 {
1991 /**
1992 * @tc.steps: step1. Get frameNode and pattern.
1993 */
1994 TestProperty testProperty;
1995 testProperty.FontSize = std::make_optional(FONT_SIZE_VALUE);
1996 testProperty.FontStyle = std::make_optional(ITALIC_FONT_STYLE_VALUE);
1997 testProperty.FontWeight = std::make_optional(FONT_WEIGHT_VALUE);
1998 testProperty.FontColor = std::make_optional(TEXT_COLOR_VALUE);
1999 testProperty.FontFamily = std::make_optional(FONT_FAMILY_VALUE);
2000 auto frameNode = CreateSelect(CREATE_VALUE, testProperty);
2001 ASSERT_NE(frameNode, nullptr);
2002 auto pattern = frameNode->GetPattern<SelectPattern>();
2003 EXPECT_TRUE(pattern);
2004 /**
2005 * @tc.steps: step2. Get options and Set option style.
2006 * @tc.expected: option style is updated successfully
2007 */
2008 auto options = pattern->GetOptions();
2009 EXPECT_EQ(options.size(), CREATE_VALUE.size());
2010 for (size_t i = 0; i < options.size(); ++i) {
2011 pattern->SetSelected(i);
2012 auto optionPattern = options[i]->GetPattern<MenuItemPattern>();
2013 ASSERT_NE(optionPattern, nullptr);
2014 optionPattern->selectTheme_ = AceType::MakeRefPtr<SelectTheme>();
2015 optionPattern->textTheme_ = AceType::MakeRefPtr<TextTheme>();
2016 EXPECT_EQ(optionPattern->GetText(), CREATE_VALUE[i].text);
2017 pattern->SetOptionBgColor(BG_COLOR_VALUE);
2018 pattern->OnModifyDone();
2019 EXPECT_EQ(optionPattern->bgColor_, BG_COLOR_VALUE);
2020 pattern->SetSelectedOptionBgColor(SELECT_BG_COLOR_VALUE);
2021 optionPattern->isSelected_ = true;
2022 pattern->OnModifyDone();
2023 EXPECT_EQ(optionPattern->bgColor_, SELECT_BG_COLOR_VALUE);
2024 pattern->SetOptionFontColor(TEXT_COLOR_VALUE);
2025 optionPattern->isSelected_ = false;
2026 pattern->OnModifyDone();
2027 EXPECT_EQ(optionPattern->GetFontColor(), TEXT_COLOR_VALUE);
2028 pattern->SetSelectedOptionFontColor(SELECT_TEXT_COLOR_VALUE);
2029 optionPattern->isSelected_ = true;
2030 pattern->OnModifyDone();
2031 EXPECT_EQ(optionPattern->GetFontColor(), SELECT_TEXT_COLOR_VALUE);
2032 pattern->InitSelected();
2033 }
2034 }
2035
2036 /**
2037 * @tc.name: InitSpinner001
2038 * @tc.desc: Test SelectPattern InitSpinner with valid parameters.
2039 * @tc.type: FUNC
2040 */
2041 HWTEST_F(SelectPatternTestNg, InitSpinner001, TestSize.Level1)
2042 {
2043 /**
2044 * @tc.steps: step1.Create a FrameNode with TextPattern to represent the Spinner control.
2045 */
2046 auto spinner = AceType::MakeRefPtr<FrameNode>("spinner", 0, AceType::MakeRefPtr<TextPattern>());
2047 ASSERT_NE(spinner, nullptr);
2048 /**
2049 * @tc.steps: step2.Create a SelectTheme instance and set its font size to 16px.
2050 */
2051 auto selectTheme = AceType::MakeRefPtr<SelectTheme>();
2052 ASSERT_NE(selectTheme, nullptr);
2053 selectTheme->SetFontSize(Dimension(16.0, DimensionUnit::PX));
2054 /**
2055 * @tc.steps: step3.Invoke the InitSpinner method of SelectPattern with the created FrameNode and SelectTheme
2056 */
2057 SelectPattern selectPattern;
2058 selectPattern.InitSpinner(spinner, selectTheme);
2059 auto spinnerLayoutProperty = spinner->GetLayoutProperty<TextLayoutProperty>();
2060 ASSERT_NE(spinnerLayoutProperty, nullptr);
2061 /**
2062 * @tc.steps: step4.Expecting the theme's font size and rendering strategy to be applied to layout properties.
2063 */
2064 auto fontSize = spinnerLayoutProperty->GetFontSize();
2065 EXPECT_EQ(fontSize.value(), Dimension(16.0, DimensionUnit::PX));
2066
2067 auto renderingStrategy = spinnerLayoutProperty->GetSymbolRenderingStrategy();
2068 EXPECT_EQ(renderingStrategy.value(), 1);
2069 }
2070
2071 /**
2072 * @tc.name: BindMenuTouch001
2073 * @tc.desc: Test BindMenuTouch with null targetNode
2074 * @tc.type: FUNC
2075 */
2076 HWTEST_F(SelectPatternTestNg, BindMenuTouch001, TestSize.Level1)
2077 {
2078 /**
2079 * @tc.steps: step1. Create select pattern and gesture hub
2080 */
2081 auto select = CreateSelect(CREATE_VALUE);
2082 ASSERT_NE(select, nullptr);
2083 auto selectPattern = select->GetPattern<SelectPattern>();
2084 auto gestureHub = select->GetOrCreateGestureEventHub();
2085 ASSERT_NE(gestureHub, nullptr);
2086
2087 /**
2088 * @tc.steps: step2. Call BindMenuTouch with null targetNode
2089 * @tc.expected: Function should return early without crash
2090 */
2091 selectPattern->BindMenuTouch(nullptr, gestureHub);
2092
2093 /**
2094 * @tc.steps: step3. Verify no touch callback is registered
2095 * @tc.expected: gestureHub should have no touch event registered
2096 */
2097 auto touchEventActuator = gestureHub->touchEventActuator_;
2098 ASSERT_NE(touchEventActuator, nullptr);
2099 ViewStackProcessor::GetInstance()->ClearStack();
2100 }
2101
2102 /**
2103 * @tc.name: BindMenuTouch002
2104 * @tc.desc: Test BindMenuTouch with valid targetNode
2105 * @tc.type: FUNC
2106 */
2107 HWTEST_F(SelectPatternTestNg, BindMenuTouch002, TestSize.Level1)
2108 {
2109 /**
2110 * @tc.steps: step1. Create select with valid targetNode
2111 */
2112 auto select = CreateSelect(CREATE_VALUE);
2113 ASSERT_NE(select, nullptr);
2114 auto selectPattern = select->GetPattern<SelectPattern>();
2115 ASSERT_NE(selectPattern, nullptr);
2116 auto gestureHub = select->GetOrCreateGestureEventHub();
2117 ASSERT_NE(gestureHub, nullptr);
2118
2119 /**
2120 * @tc.steps: step2. Call BindMenuTouch with valid targetNode
2121 * @tc.expected: Touch callback should be registered
2122 */
2123 selectPattern->BindMenuTouch(select, gestureHub);
2124
2125 /**
2126 * @tc.steps: step3. Verify touch callback is registered
2127 * @tc.expected: gestureHub should have touch event registered
2128 */
2129 auto touchEventActuator = gestureHub->touchEventActuator_;
2130 ASSERT_NE(touchEventActuator, nullptr);
2131 auto touchEvents = touchEventActuator->touchEvents_;
2132 ASSERT_FALSE(touchEvents.empty());
2133 ViewStackProcessor::GetInstance()->ClearStack();
2134 }
2135
2136 /**
2137 * @tc.name: BindMenuTouch003
2138 * @tc.desc: Test BindMenuTouch touch callback with TouchType::DOWN
2139 * @tc.type: FUNC
2140 */
2141 HWTEST_F(SelectPatternTestNg, BindMenuTouch003, TestSize.Level1)
2142 {
2143 /**
2144 * @tc.steps: step1. Create select and setup
2145 */
2146 auto select = CreateSelect(CREATE_VALUE);
2147 ASSERT_NE(select, nullptr);
2148 auto selectPattern = select->GetPattern<SelectPattern>();
2149 ASSERT_NE(selectPattern, nullptr);
2150 auto gestureHub = select->GetOrCreateGestureEventHub();
2151 ASSERT_NE(gestureHub, nullptr);
2152
2153 /**
2154 * @tc.steps: step2. Call BindMenuTouch and get the callback
2155 */
2156 selectPattern->BindMenuTouch(select, gestureHub);
2157 auto touchEventActuator = gestureHub->touchEventActuator_;
2158 ASSERT_NE(touchEventActuator, nullptr);
2159 auto touchEvents = touchEventActuator->touchEvents_;
2160 ASSERT_FALSE(touchEvents.empty());
2161
2162 /**
2163 * @tc.steps: step3. Trigger DOWN event
2164 * @tc.expected: Callback should be executed without crash
2165 */
2166 TouchEventInfo touchInfo("test");
2167 TouchLocationInfo touchLocationInfo(0);
2168 touchLocationInfo.SetTouchType(TouchType::DOWN);
2169 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2170
2171 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2172 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2173 ViewStackProcessor::GetInstance()->ClearStack();
2174 }
2175
2176 /**
2177 * @tc.name: BindMenuTouch004
2178 * @tc.desc: Test BindMenuTouch touch callback with TouchType::CANCEL
2179 * @tc.type: FUNC
2180 */
2181 HWTEST_F(SelectPatternTestNg, BindMenuTouch004, TestSize.Level1)
2182 {
2183 /**
2184 * @tc.steps: step1. Create select and setup
2185 */
2186 auto select = CreateSelect(CREATE_VALUE);
2187 ASSERT_NE(select, nullptr);
2188 auto selectPattern = select->GetPattern<SelectPattern>();
2189 ASSERT_NE(selectPattern, nullptr);
2190 auto gestureHub = select->GetOrCreateGestureEventHub();
2191 ASSERT_NE(gestureHub, nullptr);
2192
2193 /**
2194 * @tc.steps: step2. Call BindMenuTouch and get the callback
2195 */
2196 selectPattern->BindMenuTouch(select, gestureHub);
2197 auto touchEventActuator = gestureHub->touchEventActuator_;
2198 ASSERT_NE(touchEventActuator, nullptr);
2199 auto touchEvents = touchEventActuator->touchEvents_;
2200 ASSERT_FALSE(touchEvents.empty());
2201
2202 /**
2203 * @tc.steps: step3. Trigger CANCEL event
2204 * @tc.expected: Callback should be executed and handle cancel appropriately
2205 */
2206 TouchEventInfo touchInfo("test");
2207 TouchLocationInfo touchLocationInfo(0);
2208 touchLocationInfo.SetTouchType(TouchType::CANCEL);
2209 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2210
2211 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2212 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2213 ViewStackProcessor::GetInstance()->ClearStack();
2214 }
2215
2216 /**
2217 * @tc.name: BindMenuTouch005
2218 * @tc.desc: Test BindMenuTouch touch callback with empty touches
2219 * @tc.type: FUNC
2220 */
2221 HWTEST_F(SelectPatternTestNg, BindMenuTouch005, TestSize.Level1)
2222 {
2223 /**
2224 * @tc.steps: step1. Create select and setup
2225 */
2226 auto select = CreateSelect(CREATE_VALUE);
2227 ASSERT_NE(select, nullptr);
2228 auto selectPattern = select->GetPattern<SelectPattern>();
2229 ASSERT_NE(selectPattern, nullptr);
2230 auto gestureHub = select->GetOrCreateGestureEventHub();
2231 ASSERT_NE(gestureHub, nullptr);
2232
2233 /**
2234 * @tc.steps: step2. Call BindMenuTouch and get the callback
2235 */
2236 selectPattern->BindMenuTouch(select, gestureHub);
2237 auto touchEventActuator = gestureHub->touchEventActuator_;
2238 ASSERT_NE(touchEventActuator, nullptr);
2239 auto touchEvents = touchEventActuator->touchEvents_;
2240 ASSERT_FALSE(touchEvents.empty());
2241
2242 /**
2243 * @tc.steps: step3. Trigger event with empty touches
2244 * @tc.expected: Callback should handle empty touches gracefully
2245 */
2246 TouchEventInfo touchInfo("test");
2247 // Don't add any touch location info to simulate empty touches
2248
2249 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2250 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2251 ViewStackProcessor::GetInstance()->ClearStack();
2252 }
2253
2254 /**
2255 * @tc.name: BindMenuTouch006
2256 * @tc.desc: Test BindMenuTouch with menu wrapper node
2257 * @tc.type: FUNC
2258 */
2259 HWTEST_F(SelectPatternTestNg, BindMenuTouch006, TestSize.Level1)
2260 {
2261 /**
2262 * @tc.steps: step1. Create select and setup
2263 */
2264 auto select = CreateSelect(CREATE_VALUE);
2265 ASSERT_NE(select, nullptr);
2266 auto selectPattern = select->GetPattern<SelectPattern>();
2267 ASSERT_NE(selectPattern, nullptr);
2268 auto gestureHub = select->GetOrCreateGestureEventHub();
2269 ASSERT_NE(gestureHub, nullptr);
2270
2271 /**
2272 * @tc.steps: step2. Create and set menu wrapper
2273 */
2274 std::vector<OptionParam> emptyParams;
2275 auto menuWrapper = MenuView::Create(std::move(emptyParams), select->GetId(), "test");
2276 ASSERT_NE(menuWrapper, nullptr);
2277 selectPattern->SetMenuNode(menuWrapper);
2278
2279 /**
2280 * @tc.steps: step3. Call BindMenuTouch and verify wrapper is set
2281 */
2282 selectPattern->BindMenuTouch(select, gestureHub);
2283 auto wrapperNode = selectPattern->GetMenuWrapper();
2284 EXPECT_EQ(wrapperNode, menuWrapper);
2285
2286 /**
2287 * @tc.steps: step4. Verify touch callback is registered
2288 */
2289 auto touchEventActuator = gestureHub->touchEventActuator_;
2290 ASSERT_NE(touchEventActuator, nullptr);
2291 auto touchEvents = touchEventActuator->touchEvents_;
2292 EXPECT_FALSE(touchEvents.empty());
2293 ViewStackProcessor::GetInstance()->ClearStack();
2294 }
2295
2296 /**
2297 * @tc.name: BindMenuTouch007
2298 * @tc.desc: Test BindMenuTouch with multiple consecutive calls
2299 * @tc.type: FUNC
2300 */
2301 HWTEST_F(SelectPatternTestNg, BindMenuTouch007, TestSize.Level1)
2302 {
2303 /**
2304 * @tc.steps: step1. Create select and setup
2305 */
2306 auto select = CreateSelect(CREATE_VALUE);
2307 ASSERT_NE(select, nullptr);
2308 auto selectPattern = select->GetPattern<SelectPattern>();
2309 ASSERT_NE(selectPattern, nullptr);
2310 auto gestureHub = select->GetOrCreateGestureEventHub();
2311 ASSERT_NE(gestureHub, nullptr);
2312
2313 /**
2314 * @tc.steps: step2. Call BindMenuTouch multiple times
2315 * @tc.expected: Should not cause issues with multiple registrations
2316 */
2317 selectPattern->BindMenuTouch(select, gestureHub);
2318 auto touchEventActuator1 = gestureHub->touchEventActuator_;
2319 auto touchEventsCount1 = touchEventActuator1 ? touchEventActuator1->touchEvents_.size() : 0;
2320
2321 selectPattern->BindMenuTouch(select, gestureHub);
2322 auto touchEventActuator2 = gestureHub->touchEventActuator_;
2323 auto touchEventsCount2 = touchEventActuator2 ? touchEventActuator2->touchEvents_.size() : 0;
2324
2325 /**
2326 * @tc.steps: step3. Verify touch events are properly managed
2327 */
2328 EXPECT_NE(touchEventActuator1, nullptr);
2329 EXPECT_NE(touchEventActuator2, nullptr);
2330 EXPECT_GE(touchEventsCount2, touchEventsCount1);
2331 ViewStackProcessor::GetInstance()->ClearStack();
2332 }
2333
2334 /**
2335 * @tc.name: BindMenuTouch008
2336 * @tc.desc: Test BindMenuTouch with different touch event types sequence
2337 * @tc.type: FUNC
2338 */
2339 HWTEST_F(SelectPatternTestNg, BindMenuTouch008, TestSize.Level1)
2340 {
2341 /**
2342 * @tc.steps: step1. Create select and setup
2343 */
2344 auto select = CreateSelect(CREATE_VALUE);
2345 ASSERT_NE(select, nullptr);
2346 auto selectPattern = select->GetPattern<SelectPattern>();
2347 ASSERT_NE(selectPattern, nullptr);
2348 auto gestureHub = select->GetOrCreateGestureEventHub();
2349 ASSERT_NE(gestureHub, nullptr);
2350
2351 /**
2352 * @tc.steps: step2. Call BindMenuTouch and get callback
2353 */
2354 selectPattern->BindMenuTouch(select, gestureHub);
2355 auto touchEventActuator = gestureHub->touchEventActuator_;
2356 ASSERT_NE(touchEventActuator, nullptr);
2357 auto touchEvents = touchEventActuator->touchEvents_;
2358 ASSERT_FALSE(touchEvents.empty());
2359 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2360
2361 /**
2362 * @tc.steps: step3. Test sequence of touch events
2363 * @tc.expected: All touch events should be handled properly
2364 */
2365 std::vector<TouchType> touchTypes = { TouchType::DOWN, TouchType::MOVE, TouchType::UP, TouchType::CANCEL };
2366
2367 for (auto touchType : touchTypes) {
2368 TouchEventInfo touchInfo("test");
2369 TouchLocationInfo touchLocationInfo(0);
2370 touchLocationInfo.SetTouchType(touchType);
2371 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2372
2373 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2374 }
2375 ViewStackProcessor::GetInstance()->ClearStack();
2376 }
2377
2378 /**
2379 * @tc.name: BindMenuTouch009
2380 * @tc.desc: Test BindMenuTouch touch callback with TouchType::MOVE
2381 * @tc.type: FUNC
2382 */
2383 HWTEST_F(SelectPatternTestNg, BindMenuTouch009, TestSize.Level1)
2384 {
2385 /**
2386 * @tc.steps: step1. Create select and setup
2387 */
2388 auto select = CreateSelect(CREATE_VALUE);
2389 ASSERT_NE(select, nullptr);
2390 auto selectPattern = select->GetPattern<SelectPattern>();
2391 ASSERT_NE(selectPattern, nullptr);
2392 auto gestureHub = select->GetOrCreateGestureEventHub();
2393 ASSERT_NE(gestureHub, nullptr);
2394
2395 /**
2396 * @tc.steps: step2. Call BindMenuTouch and get the callback
2397 */
2398 selectPattern->BindMenuTouch(select, gestureHub);
2399 auto touchEventActuator = gestureHub->touchEventActuator_;
2400 ASSERT_NE(touchEventActuator, nullptr);
2401 auto touchEvents = touchEventActuator->touchEvents_;
2402 ASSERT_FALSE(touchEvents.empty());
2403
2404 /**
2405 * @tc.steps: step3. Trigger MOVE event
2406 * @tc.expected: Callback should be executed without special handling
2407 */
2408 TouchEventInfo touchInfo("test");
2409 TouchLocationInfo touchLocationInfo(0);
2410 touchLocationInfo.SetTouchType(TouchType::MOVE);
2411 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2412
2413 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2414 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2415 ViewStackProcessor::GetInstance()->ClearStack();
2416 }
2417
2418 /**
2419 * @tc.name: BindMenuTouch010
2420 * @tc.desc: Test BindMenuTouch touch callback with multiple touches
2421 * @tc.type: FUNC
2422 */
2423 HWTEST_F(SelectPatternTestNg, BindMenuTouch010, TestSize.Level1)
2424 {
2425 /**
2426 * @tc.steps: step1. Create select and setup
2427 */
2428 auto select = CreateSelect(CREATE_VALUE);
2429 ASSERT_NE(select, nullptr);
2430 auto selectPattern = select->GetPattern<SelectPattern>();
2431 ASSERT_NE(selectPattern, nullptr);
2432 auto gestureHub = select->GetOrCreateGestureEventHub();
2433 ASSERT_NE(gestureHub, nullptr);
2434
2435 /**
2436 * @tc.steps: step2. Call BindMenuTouch and get the callback
2437 */
2438 selectPattern->BindMenuTouch(select, gestureHub);
2439 auto touchEventActuator = gestureHub->touchEventActuator_;
2440 ASSERT_NE(touchEventActuator, nullptr);
2441 auto touchEvents = touchEventActuator->touchEvents_;
2442 ASSERT_FALSE(touchEvents.empty());
2443
2444 /**
2445 * @tc.steps: step3. Trigger event with multiple touches
2446 * @tc.expected: Callback should use the first touch for processing
2447 */
2448 TouchEventInfo touchInfo("test");
2449 TouchLocationInfo touchLocationInfo1(0);
2450 TouchLocationInfo touchLocationInfo2(1);
2451 touchLocationInfo1.SetTouchType(TouchType::DOWN);
2452 touchLocationInfo2.SetTouchType(TouchType::DOWN);
2453 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo1));
2454 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo2));
2455
2456 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2457 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2458 ViewStackProcessor::GetInstance()->ClearStack();
2459 }
2460
2461 /**
2462 * @tc.name: BindMenuTouch011
2463 * @tc.desc: Test BindMenuTouch touch callback with weakTarget upgrade failure simulation
2464 * @tc.type: FUNC
2465 */
2466 HWTEST_F(SelectPatternTestNg, BindMenuTouch011, TestSize.Level1)
2467 {
2468 /**
2469 * @tc.steps: step1. Create select and setup
2470 */
2471 auto select = CreateSelect(CREATE_VALUE);
2472 ASSERT_NE(select, nullptr);
2473 auto selectPattern = select->GetPattern<SelectPattern>();
2474 ASSERT_NE(selectPattern, nullptr);
2475 auto gestureHub = select->GetOrCreateGestureEventHub();
2476 ASSERT_NE(gestureHub, nullptr);
2477
2478 /**
2479 * @tc.steps: step2. Call BindMenuTouch
2480 */
2481 selectPattern->BindMenuTouch(select, gestureHub);
2482 auto touchEventActuator = gestureHub->touchEventActuator_;
2483 ASSERT_NE(touchEventActuator, nullptr);
2484 auto touchEvents = touchEventActuator->touchEvents_;
2485 ASSERT_FALSE(touchEvents.empty());
2486
2487 /**
2488 * @tc.steps: step3. Test with valid touches
2489 */
2490 TouchEventInfo touchInfo("test");
2491 TouchLocationInfo touchLocationInfo(0);
2492 touchLocationInfo.SetTouchType(TouchType::DOWN);
2493 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2494
2495 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2496 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2497 ViewStackProcessor::GetInstance()->ClearStack();
2498 }
2499
2500 /**
2501 * @tc.name: BindMenuTouch012
2502 * @tc.desc: Test BindMenuTouch edge case coverage for container null checks
2503 * @tc.type: FUNC
2504 */
2505 HWTEST_F(SelectPatternTestNg, BindMenuTouch012, TestSize.Level1)
2506 {
2507 /**
2508 * @tc.steps: step1. Create select and setup
2509 */
2510 auto select = CreateSelect(CREATE_VALUE);
2511 ASSERT_NE(select, nullptr);
2512 auto selectPattern = select->GetPattern<SelectPattern>();
2513 ASSERT_NE(selectPattern, nullptr);
2514 auto gestureHub = select->GetOrCreateGestureEventHub();
2515 ASSERT_NE(gestureHub, nullptr);
2516
2517 /**
2518 * @tc.steps: step2. Call BindMenuTouch
2519 */
2520 selectPattern->BindMenuTouch(select, gestureHub);
2521 auto touchEventActuator = gestureHub->touchEventActuator_;
2522 ASSERT_NE(touchEventActuator, nullptr);
2523 auto touchEvents = touchEventActuator->touchEvents_;
2524 ASSERT_FALSE(touchEvents.empty());
2525
2526 /**
2527 * @tc.steps: step3. Test various touch types to ensure all branches are covered
2528 * @tc.expected: All touch events should be handled without crashing
2529 */
2530 std::vector<TouchType> touchTypes = { TouchType::DOWN, TouchType::MOVE, TouchType::UP, TouchType::CANCEL,
2531 TouchType::UNKNOWN };
2532
2533 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2534
2535 for (auto touchType : touchTypes) {
2536 TouchEventInfo touchInfo("test");
2537 TouchLocationInfo touchLocationInfo(0);
2538 touchLocationInfo.SetTouchType(touchType);
2539 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2540
2541 // Each touch type should be handled gracefully
2542 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2543 }
2544 ViewStackProcessor::GetInstance()->ClearStack();
2545 }
2546
2547 /**
2548 * @tc.name: BindMenuTouch013
2549 * @tc.desc: Test BindMenuTouch behavior when subwindow components are null
2550 * @tc.type: FUNC
2551 */
2552 HWTEST_F(SelectPatternTestNg, BindMenuTouch013, TestSize.Level1)
2553 {
2554 /**
2555 * @tc.steps: step1. Create select and setup
2556 */
2557 auto select = CreateSelect(CREATE_VALUE);
2558 ASSERT_NE(select, nullptr);
2559 auto selectPattern = select->GetPattern<SelectPattern>();
2560 ASSERT_NE(selectPattern, nullptr);
2561 auto gestureHub = select->GetOrCreateGestureEventHub();
2562 ASSERT_NE(gestureHub, nullptr);
2563
2564 /**
2565 * @tc.steps: step2. Call BindMenuTouch
2566 */
2567 selectPattern->BindMenuTouch(select, gestureHub);
2568 auto touchEventActuator = gestureHub->touchEventActuator_;
2569 ASSERT_NE(touchEventActuator, nullptr);
2570 auto touchEvents = touchEventActuator->touchEvents_;
2571 ASSERT_FALSE(touchEvents.empty());
2572
2573 /**
2574 * @tc.steps: step3. Test touch callback when subwindow may not exist
2575 * @tc.expected: Should handle null subwindow gracefully
2576 */
2577 TouchEventInfo touchInfo("test");
2578 TouchLocationInfo touchLocationInfo(0);
2579 touchLocationInfo.SetTouchType(TouchType::DOWN);
2580 touchInfo.AddTouchLocationInfo(std::move(touchLocationInfo));
2581
2582 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2583 // This should not crash even if subwindow doesn't exist in test environment
2584 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfo));
2585 ViewStackProcessor::GetInstance()->ClearStack();
2586 }
2587
2588 /**
2589 * @tc.name: BindMenuTouch014
2590 * @tc.desc: Test BindMenuTouch with all touch types for comprehensive coverage
2591 * @tc.type: FUNC
2592 */
2593 HWTEST_F(SelectPatternTestNg, BindMenuTouch014, TestSize.Level1)
2594 {
2595 /**
2596 * @tc.steps: step1. Create select and setup
2597 */
2598 auto select = CreateSelect(CREATE_VALUE);
2599 ASSERT_NE(select, nullptr);
2600 auto selectPattern = select->GetPattern<SelectPattern>();
2601 ASSERT_NE(selectPattern, nullptr);
2602 auto gestureHub = select->GetOrCreateGestureEventHub();
2603 ASSERT_NE(gestureHub, nullptr);
2604
2605 /**
2606 * @tc.steps: step2. Call BindMenuTouch
2607 */
2608 selectPattern->BindMenuTouch(select, gestureHub);
2609 auto touchEventActuator = gestureHub->touchEventActuator_;
2610 ASSERT_NE(touchEventActuator, nullptr);
2611 auto touchEvents = touchEventActuator->touchEvents_;
2612 ASSERT_FALSE(touchEvents.empty());
2613
2614 auto touchCallback = touchEvents.front()->GetTouchEventCallback();
2615
2616 /**
2617 * @tc.steps: step3. Test all possible TouchType values systematically
2618 * @tc.expected: All touch types should be handled without exceptions
2619 */
2620
2621 TouchEventInfo touchInfoDown("test_down");
2622 TouchLocationInfo touchLocationInfo(0);
2623 touchLocationInfo.SetTouchType(TouchType::DOWN);
2624 touchInfoDown.AddTouchLocationInfo(std::move(touchLocationInfo));
2625 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfoDown));
2626
2627 TouchEventInfo touchInfoUp("test_up");
2628 touchLocationInfo.SetTouchType(TouchType::UP);
2629 touchInfoUp.AddTouchLocationInfo(std::move(touchLocationInfo));
2630 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfoUp));
2631
2632 TouchEventInfo touchInfoCancel("test_cancel");
2633 touchLocationInfo.SetTouchType(TouchType::CANCEL);
2634 touchInfoCancel.AddTouchLocationInfo(std::move(touchLocationInfo));
2635 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfoCancel));
2636
2637 TouchEventInfo touchInfoMove("test_move");
2638 touchLocationInfo.SetTouchType(TouchType::MOVE);
2639 touchInfoMove.AddTouchLocationInfo(std::move(touchLocationInfo));
2640 EXPECT_NO_FATAL_FAILURE(touchCallback(touchInfoMove));
2641 ViewStackProcessor::GetInstance()->ClearStack();
2642 }
2643
2644 /**
2645 * @tc.name: SetOptionTextModifierByUser
2646 * @tc.desc: Test SelectPattern SetOptionTextModifierByUser.
2647 * @tc.type: FUNC
2648 */
2649 HWTEST_F(SelectPatternTestNg, SetOptionTextModifierByUser, TestSize.Level1)
2650 {
2651 /**
2652 * @tc.steps: step1. Create select model, initialize frame node.
2653 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
2654 */
2655 SelectModelNG selectModelInstance;
2656 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
2657 selectModelInstance.Create(params);
2658
2659 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2660 ASSERT_NE(select, nullptr);
2661 auto selectPattern = select->GetPattern<SelectPattern>();
2662 ASSERT_NE(selectPattern, nullptr);
2663 auto props = select->GetPaintProperty<SelectPaintProperty>();
2664 ASSERT_NE(props, nullptr);
2665 auto pipeline = select->GetContextWithCheck();
2666 ASSERT_NE(pipeline, nullptr);
2667 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
2668 ASSERT_NE(selectTheme, nullptr);
2669 selectTheme->fontColor_ = Color::GREEN;
2670 /**
2671 * @tc.steps: step2. Enable user-defined font color flag, call SetOptionTextModifierByUser.
2672 * @tc.expected: step2. Option font color in selectPattern is not set.
2673 */
2674 EXPECT_FALSE(selectPattern->optionFont_.FontColor.has_value());
2675 selectModelInstance.SetOptionFontColorByUser(true);
2676 EXPECT_TRUE(props->GetOptionFontColorSetByUserValue(false));
2677 selectPattern->SetOptionTextModifierByUser(selectTheme, props);
2678 EXPECT_FALSE(selectPattern->optionFont_.FontColor.has_value());
2679
2680 /**
2681 * @tc.steps: step3. Disable user-defined font color flag, call SetOptionTextModifierByUser.
2682 * @tc.expected: step3. Option font color in selectPattern is set to theme green.
2683 */
2684 selectModelInstance.SetOptionFontColorByUser(false);
2685 EXPECT_FALSE(props->GetOptionFontColorSetByUserValue(false));
2686 selectPattern->SetOptionTextModifierByUser(selectTheme, props);
2687 EXPECT_TRUE(selectPattern->optionFont_.FontColor.has_value());
2688 EXPECT_EQ(selectPattern->optionFont_.FontColor, Color::GREEN);
2689 }
2690
2691 /**
2692 * @tc.name: SetSelectedOptionTextModifierByUser
2693 * @tc.desc: Test SelectPattern SetSelectedOptionTextModifierByUser.
2694 * @tc.type: FUNC
2695 */
2696 HWTEST_F(SelectPatternTestNg, SetSelectedOptionTextModifierByUser, TestSize.Level1)
2697 {
2698 /**
2699 * @tc.steps: step1. Create select model, initialize frame node.
2700 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
2701 */
2702 SelectModelNG selectModelInstance;
2703 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
2704 selectModelInstance.Create(params);
2705
2706 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2707 ASSERT_NE(select, nullptr);
2708 auto selectPattern = select->GetPattern<SelectPattern>();
2709 ASSERT_NE(selectPattern, nullptr);
2710 auto props = select->GetPaintProperty<SelectPaintProperty>();
2711 ASSERT_NE(props, nullptr);
2712 auto pipeline = select->GetContextWithCheck();
2713 ASSERT_NE(pipeline, nullptr);
2714 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
2715 ASSERT_NE(selectTheme, nullptr);
__anonbe0efc1c0302(WeakPtr<FrameNode> weakNode) 2716 auto applySelectedFunc = [](WeakPtr<FrameNode> weakNode) {
2717 auto textNode = weakNode.Upgrade();
2718 ASSERT_NE(textNode, nullptr);
2719 auto property = textNode->GetLayoutProperty<TextLayoutProperty>();
2720 ASSERT_NE(property, nullptr);
2721 property->UpdateTextColor(Color::BLUE);
2722 };
2723 selectTheme->selectedColorText_ = Color::GREEN;
2724 selectPattern->textSelectOptionApply_ = applySelectedFunc;
2725 auto optionSelected = selectPattern->options_[0];
2726 ASSERT_NE(optionSelected, nullptr);
2727 auto menuItemSelectedPattern = optionSelected->GetPattern<MenuItemPattern>();
2728 ASSERT_NE(menuItemSelectedPattern, nullptr);
2729 auto textSelected = menuItemSelectedPattern->text_;
2730 ASSERT_NE(textSelected, nullptr);
2731 /**
2732 * @tc.steps: step2. Enable user-defined selected font color flag, disable text modifier flag.
2733 * @tc.expected: step2. Selected font color in selectPattern is not set, text node color is not blue.
2734 */
2735 selectModelInstance.SetSelectedOptionFontColorByUser(true);
2736 EXPECT_TRUE(props->GetSelectedOptionFontColorSetByUserValue(false));
2737 props->UpdateSelectedOptionTextModifierSetByUser(false);
2738 EXPECT_FALSE(props->GetSelectedOptionTextModifierSetByUserValue(false));
2739 selectPattern->SetSelectedOptionTextModifierByUser(selectTheme, props);
2740 EXPECT_FALSE(selectPattern->selectedFont_.FontColor.has_value());
2741 auto propertySelected = textSelected->GetLayoutProperty<TextLayoutProperty>();
2742 ASSERT_NE(propertySelected, nullptr);
2743 ASSERT_NE(propertySelected->GetTextColor(), Color::BLUE);
2744
2745 /**
2746 * @tc.steps: step3. Enable both user-defined selected font color flag and text modifier flag.
2747 * @tc.expected: step3. Selected font color in selectPattern is still not set.
2748 */
2749 props->UpdateSelectedOptionTextModifierSetByUser(true);
2750 EXPECT_TRUE(props->GetSelectedOptionTextModifierSetByUserValue(false));
2751 selectPattern->SetSelectedOptionTextModifierByUser(selectTheme, props);
2752 EXPECT_FALSE(selectPattern->selectedFont_.FontColor.has_value());
2753
2754 /**
2755 * @tc.steps: step4. Disable user-defined selected font color flag, call SetSelectedOptionTextModifierByUser.
2756 * @tc.expected: step4. Selected font color in selectPattern is set to theme green.
2757 */
2758 selectModelInstance.SetSelectedOptionFontColorByUser(false);
2759 EXPECT_FALSE(props->GetSelectedOptionFontColorSetByUserValue(false));
2760 selectPattern->SetSelectedOptionTextModifierByUser(selectTheme, props);
2761 EXPECT_TRUE(selectPattern->selectedFont_.FontColor.has_value());
2762 EXPECT_EQ(selectPattern->selectedFont_.FontColor, Color::GREEN);
2763 }
2764
2765 /**
2766 * @tc.name: SetArrowModifierByUser
2767 * @tc.desc: Test SelectPattern SetArrowModifierByUser.
2768 * @tc.type: FUNC
2769 */
2770 HWTEST_F(SelectPatternTestNg, SetArrowModifierByUser, TestSize.Level1)
2771 {
2772 /**
2773 * @tc.steps: step1. Create select model, initialize frame node.
2774 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
2775 */
2776 AceApplicationInfo::GetInstance().apiVersion_ = static_cast<int32_t>(PlatformVersion::VERSION_SIXTEEN);
2777 EXPECT_TRUE(AceApplicationInfo::GetInstance().GreatOrEqualTargetAPIVersion(PlatformVersion::VERSION_SIXTEEN));
2778 SelectModelNG selectModelInstance;
2779 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
2780 selectModelInstance.Create(params);
2781
2782 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2783 ASSERT_NE(select, nullptr);
2784 auto selectPattern = select->GetPattern<SelectPattern>();
2785 ASSERT_NE(selectPattern, nullptr);
2786 auto props = select->GetPaintProperty<SelectPaintProperty>();
2787 ASSERT_NE(props, nullptr);
2788 auto pipeline = select->GetContextWithCheck();
2789 ASSERT_NE(pipeline, nullptr);
2790 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
2791 ASSERT_NE(selectTheme, nullptr);
2792
__anonbe0efc1c0402(WeakPtr<FrameNode> weakNode) 2793 auto applyFunc = [](WeakPtr<FrameNode> weakNode) {
2794 auto symbolNode = weakNode.Upgrade();
2795 ASSERT_NE(symbolNode, nullptr);
2796 auto property = symbolNode->GetLayoutProperty<TextLayoutProperty>();
2797 ASSERT_NE(property, nullptr);
2798 property->UpdateFontSize(Dimension(80));
2799 };
2800 selectPattern->arrowApply_ = applyFunc;
2801
2802 /**
2803 * @tc.steps: step2. Disable arrow modifier flag, call SetArrowModifierByUser.
2804 * @tc.expected: step2. Arrow font size is not updated to 80.
2805 */
2806 props->UpdateArrowModifierSetByUser(false);
2807 EXPECT_FALSE(props->GetArrowModifierSetByUserValue(false));
2808 selectPattern->SetArrowModifierByUser(selectTheme, props);
2809 auto frameNode = selectPattern->spinner_;
2810 ASSERT_NE(frameNode, nullptr);
2811 EXPECT_EQ(frameNode->GetTag(), V2::SYMBOL_ETS_TAG);
2812 auto property = frameNode->GetLayoutProperty<TextLayoutProperty>();
2813 ASSERT_NE(property, nullptr);
2814 ASSERT_NE(property->GetFontSize(), Dimension(80));
2815
2816 /**
2817 * @tc.steps: step3. Enable arrow modifier flag, call SetArrowModifierByUser.
2818 * @tc.expected: step3. Arrow font size is updated to 80.
2819 */
2820 props->UpdateArrowModifierSetByUser(true);
2821 EXPECT_TRUE(props->GetArrowModifierSetByUserValue(false));
2822 selectPattern->SetArrowModifierByUser(selectTheme, props);
2823 EXPECT_EQ(property->GetFontSize(), Dimension(80));
2824 }
2825
2826 /**
2827 * @tc.name: SetModifierByUser001
2828 * @tc.desc: Test SelectPattern SetModifierByUser.
2829 * @tc.type: FUNC
2830 */
2831 HWTEST_F(SelectPatternTestNg, SetModifierByUser001, TestSize.Level1)
2832 {
2833 /**
2834 * @tc.steps: step1. Create select model, initialize frame node, obtain related objects.
2835 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
2836 */
2837 SelectModelNG selectModelInstance;
2838 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
2839 selectModelInstance.Create(params);
2840
2841 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2842 ASSERT_NE(select, nullptr);
2843 auto selectPattern = select->GetPattern<SelectPattern>();
2844 ASSERT_NE(selectPattern, nullptr);
2845 auto props = select->GetPaintProperty<SelectPaintProperty>();
2846 ASSERT_NE(props, nullptr);
2847 auto layoutProps = select->GetLayoutProperty<SelectLayoutProperty>();
2848 ASSERT_NE(layoutProps, nullptr);
2849 auto pipeline = select->GetContextWithCheck();
2850 ASSERT_NE(pipeline, nullptr);
2851 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
2852 ASSERT_NE(selectTheme, nullptr);
2853 selectTheme->selectedColor_ = Color::GREEN;
2854 /**
2855 * @tc.steps: step2. Show default selected icon, enable user-defined selected background color flag.
2856 * @tc.expected: step2. Selected background color in selectPattern is not set.
2857 */
2858 selectModelInstance.SetShowDefaultSelectedIcon(true);
2859 EXPECT_TRUE(layoutProps->GetShowDefaultSelectedIconValue(false));
2860 selectModelInstance.SetSelectedOptionBgColorByUser(true);
2861 EXPECT_TRUE(props->GetSelectedOptionBgColorSetByUserValue(false));
2862 selectPattern->SetSelectedOptionBgColorByUser(selectTheme, props, layoutProps);
2863 selectPattern->SetModifierByUser(selectTheme, props);
2864 EXPECT_FALSE(selectPattern->selectedBgColor_.has_value());
2865
2866 /**
2867 * @tc.steps: step3. Hide default selected icon, enable user-defined selected background color flag.
2868 * @tc.expected: step3. Selected background color in selectPattern is not set.
2869 */
2870 selectModelInstance.SetShowDefaultSelectedIcon(false);
2871 EXPECT_FALSE(layoutProps->GetShowDefaultSelectedIconValue(false));
2872 selectModelInstance.SetSelectedOptionBgColorByUser(true);
2873 EXPECT_TRUE(props->GetSelectedOptionBgColorSetByUserValue(false));
2874 selectPattern->SetSelectedOptionBgColorByUser(selectTheme, props, layoutProps);
2875 selectPattern->SetModifierByUser(selectTheme, props);
2876 EXPECT_FALSE(selectPattern->selectedBgColor_.has_value());
2877
2878 /**
2879 * @tc.steps: step4. Show default selected icon, disable user-defined selected background color flag.
2880 * @tc.expected: step4. Selected background color in selectPattern is not set.
2881 */
2882 selectModelInstance.SetShowDefaultSelectedIcon(true);
2883 EXPECT_TRUE(layoutProps->GetShowDefaultSelectedIconValue(false));
2884 selectModelInstance.SetSelectedOptionBgColorByUser(false);
2885 EXPECT_FALSE(props->GetSelectedOptionBgColorSetByUserValue(false));
2886 selectPattern->SetSelectedOptionBgColorByUser(selectTheme, props, layoutProps);
2887 selectPattern->SetModifierByUser(selectTheme, props);
2888 EXPECT_FALSE(selectPattern->selectedBgColor_.has_value());
2889
2890 /**
2891 * @tc.steps: step5. Hide default selected icon, disable user-defined selected background color flag.
2892 * @tc.expected: step5. Selected background color in selectPattern is set to theme green.
2893 */
2894 selectModelInstance.SetShowDefaultSelectedIcon(false);
2895 EXPECT_FALSE(layoutProps->GetShowDefaultSelectedIconValue(false));
2896 selectModelInstance.SetSelectedOptionBgColorByUser(false);
2897 EXPECT_FALSE(props->GetSelectedOptionBgColorSetByUserValue(false));
2898 selectPattern->SetSelectedOptionBgColorByUser(selectTheme, props, layoutProps);
2899 selectPattern->SetModifierByUser(selectTheme, props);
2900 EXPECT_TRUE(selectPattern->selectedBgColor_.has_value());
2901 EXPECT_EQ(selectPattern->selectedBgColor_, Color::GREEN);
2902 }
2903
2904 /**
2905 * @tc.name: SetModifierByUser002
2906 * @tc.desc: Test SelectPattern SetModifierByUser.
2907 * @tc.type: FUNC
2908 */
2909 HWTEST_F(SelectPatternTestNg, SetModifierByUser002, TestSize.Level1)
2910 {
2911 /**
2912 * @tc.steps: step1. Create select model, initialize frame node, obtain related objects.
2913 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
2914 */
2915 SelectModelNG selectModelInstance;
2916 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
2917 selectModelInstance.Create(params);
2918
2919 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
2920 ASSERT_NE(select, nullptr);
2921 auto selectPattern = select->GetPattern<SelectPattern>();
2922 ASSERT_NE(selectPattern, nullptr);
2923 auto props = select->GetPaintProperty<SelectPaintProperty>();
2924 ASSERT_NE(props, nullptr);
2925 auto layoutProps = select->GetLayoutProperty<SelectLayoutProperty>();
2926 ASSERT_NE(layoutProps, nullptr);
2927 auto pipeline = select->GetContextWithCheck();
2928 ASSERT_NE(pipeline, nullptr);
2929 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
2930 ASSERT_NE(selectTheme, nullptr);
2931
2932 auto frameNode = selectPattern->text_;
2933 ASSERT_NE(frameNode, nullptr);
2934 auto property = frameNode->GetLayoutProperty<TextLayoutProperty>();
2935 ASSERT_NE(property, nullptr);
2936 EXPECT_EQ(property->GetMaxLines(), 1);
2937
__anonbe0efc1c0502(WeakPtr<FrameNode> weakNode) 2938 auto applyFunc = [](WeakPtr<FrameNode> weakNode) {
2939 auto textNode = weakNode.Upgrade();
2940 ASSERT_NE(textNode, nullptr);
2941 auto property = textNode->GetLayoutProperty<TextLayoutProperty>();
2942 ASSERT_NE(property, nullptr);
2943 property->UpdateMaxLines(2);
2944 property->UpdateFontSize(Dimension(80));
2945 };
2946 selectPattern->fontColor_ = Color::GREEN;
2947 selectPattern->textApply_ = applyFunc;
2948 /**
2949 * @tc.steps: step2. Enable user-defined font color flag, disable text modifier flag, call SetModifierByUser.
2950 * @tc.expected: step2. Font color remains green, max lines remains 1.
2951 */
2952 selectModelInstance.SetFontColorByUser(true);
2953 EXPECT_TRUE(props->GetFontColorSetByUserValue(false));
2954 props->UpdateTextModifierSetByUser(false);
2955 EXPECT_FALSE(props->GetTextModifierSetByUserValue(false));
2956 selectPattern->SetModifierByUser(selectTheme, props);
2957 EXPECT_EQ(selectPattern->fontColor_, Color::GREEN);
2958 EXPECT_EQ(property->GetMaxLines(), 1);
2959
2960 /**
2961 * @tc.steps: step3. Enable both user-defined font color flag and text modifier flag, call SetModifierByUser.
2962 * @tc.expected: step3. Font color remains green, max lines is updated to 2.
2963 */
2964 selectModelInstance.SetFontColorByUser(true);
2965 EXPECT_TRUE(props->GetFontColorSetByUserValue(false));
2966 props->UpdateTextModifierSetByUser(true);
2967 EXPECT_TRUE(props->GetTextModifierSetByUserValue(false));
2968 selectPattern->SetModifierByUser(selectTheme, props);
2969 EXPECT_EQ(selectPattern->fontColor_, Color::GREEN);
2970 EXPECT_EQ(property->GetMaxLines(), 2);
2971
2972 /**
2973 * @tc.steps: step4. Disable user-defined font color flag, call SetModifierByUser.
2974 * @tc.expected: step4. Font color is no longer green.
2975 */
2976 selectModelInstance.SetFontColorByUser(false);
2977 EXPECT_FALSE(props->GetFontColorSetByUserValue(false));
2978 selectPattern->SetModifierByUser(selectTheme, props);
2979 ASSERT_NE(selectPattern->fontColor_, Color::GREEN);
2980 }
2981
2982 /**
2983 * @tc.name: SetOptionBgColorByUser001
2984 * @tc.desc: Test SetOptionBgColorByUser func
2985 * @tc.type: FUNC
2986 */
2987 HWTEST_F(SelectPatternTestNg, SetOptionBgColorByUser001, TestSize.Level1)
2988 {
2989 /**
2990 * @tc.steps: step1. Create select pattern and gesture hub
2991 */
2992 auto select = CreateSelect(CREATE_VALUE);
2993 ASSERT_NE(select, nullptr);
2994 auto selectPattern = select->GetPattern<SelectPattern>();
2995 ASSERT_NE(selectPattern, nullptr);
2996 auto option = FrameNode::GetOrCreateFrameNode(V2::OPTION_ETS_TAG, ElementRegister::GetInstance()->MakeUniqueId(),
__anonbe0efc1c0602() 2997 []() { return AceType::MakeRefPtr<MenuItemPattern>(true, 0); });
2998 ASSERT_NE(option, nullptr);
2999 selectPattern->options_.push_back(option);
3000 auto optionCount = selectPattern->options_.size();
3001 ASSERT_NE(optionCount, 0);
3002 auto paintProperty = select->GetPaintProperty<SelectPaintProperty>();
3003 ASSERT_NE(paintProperty, nullptr);
3004 paintProperty->UpdateOptionBgColorSetByUser(true);
3005 selectPattern->SetOptionBgColorByUser(Color::BLACK, paintProperty);
3006 ASSERT_NE(selectPattern->options_[0], nullptr);
3007 auto itemPaintProperty = selectPattern->options_[0]->GetPaintProperty<MenuItemPaintProperty>();
3008 ASSERT_NE(itemPaintProperty, nullptr);
3009 ASSERT_EQ(itemPaintProperty->GetOptionBgColor().has_value(), false);
3010 }
3011
3012 /**
3013 * @tc.name: SetOptionBgColorByUser
3014 * @tc.desc: Test SelectPattern SetOptionBgColorByUser.
3015 * @tc.type: FUNC
3016 */
3017 HWTEST_F(SelectPatternTestNg, SetOptionBgColorByUser, TestSize.Level1)
3018 {
3019 /**
3020 * @tc.steps: step1. Create select model, initialize frame node and set size.
3021 * @tc.expected: step1. Select model and frame node are created, size is set correctly.
3022 */
3023 SelectModelNG selectModelInstance;
3024 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
3025 selectModelInstance.Create(params);
3026
3027 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3028 ASSERT_NE(select, nullptr);
3029 auto selectPattern = select->GetPattern<SelectPattern>();
3030 ASSERT_NE(selectPattern, nullptr);
3031 selectPattern->SetSelectSize(SizeF(SELECT_WIDTH, SELECT_HEIGHT));
3032 selectPattern->UpdateTargetSize();
3033 auto menu = selectPattern->GetMenuNode();
3034 ASSERT_NE(menu, nullptr);
3035 auto menuLayoutProps = menu->GetLayoutProperty<MenuLayoutProperty>();
3036 ASSERT_NE(menuLayoutProps, nullptr);
3037 auto targetSize = menuLayoutProps->GetTargetSizeValue(SizeF());
3038 EXPECT_EQ(targetSize, SizeF(SELECT_WIDTH, SELECT_HEIGHT));
3039 auto optionCount = selectPattern->options_.size();
3040 ASSERT_NE(optionCount, 0);
3041 auto option = selectPattern->options_[0];
3042 auto optionPaintProperty = option->GetPaintProperty<MenuItemPaintProperty>();
3043 ASSERT_NE(optionPaintProperty, nullptr);
3044 auto props = select->GetPaintProperty<SelectPaintProperty>();
3045 ASSERT_NE(props, nullptr);
3046
3047 /**
3048 * @tc.steps: step2. Test option background color update with user-defined flag.
3049 * @tc.expected: step2. Option background color is updated based on user-defined flag.
3050 */
3051 std::vector<bool> vec { true, false };
3052 for (auto flag : vec) {
3053 props->UpdateSelectedOptionBgColorSetByUser(flag);
3054 selectPattern->optionBgColor_.reset();
3055 selectPattern->SetOptionBgColor(Color::GREEN);
3056 EXPECT_EQ(optionPaintProperty->GetOptionBgColorValue(), Color::GREEN);
3057 }
3058 }
3059
3060 /**
3061 * @tc.name: SetColorByUser
3062 * @tc.desc: Test SelectPattern SetColorByUser.
3063 * @tc.type: FUNC
3064 */
3065 HWTEST_F(SelectPatternTestNg, SetColorByUser, TestSize.Level1)
3066 {
3067 /**
3068 * @tc.steps: step1. Create select model and initialize components.
3069 * @tc.expected: step1. Select model and related components are created successfully.
3070 */
3071 SelectModelNG selectModelInstance;
3072 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
3073 selectModelInstance.Create(params);
3074
3075 auto select = AceType::WeakClaim(ViewStackProcessor::GetInstance()->GetMainFrameNode()).Upgrade();
3076 ASSERT_NE(select, nullptr);
3077 auto selectPattern = select->GetPattern<SelectPattern>();
3078 ASSERT_NE(selectPattern, nullptr);
3079 auto pipeline = select->GetContextWithCheck();
3080 ASSERT_NE(pipeline, nullptr);
3081 auto theme = pipeline->GetTheme<SelectTheme>();
3082 ASSERT_NE(theme, nullptr);
3083 auto props = select->GetPaintProperty<SelectPaintProperty>();
3084 ASSERT_NE(props, nullptr);
3085
3086 /**
3087 * @tc.steps: step2. Test SetColorByUser with different user-defined flags.
3088 * @tc.expected: step2. Color properties are updated based on user-defined flags and theme.
3089 */
3090 g_isConfigChangePerform = false;
3091 selectPattern->SetColorByUser(select, theme);
3092 g_isConfigChangePerform = true;
3093 props->UpdateFontColorSetByUser(true);
3094 props->UpdateOptionFontColorSetByUser(true);
3095 props->UpdateSelectedOptionBgColorSetByUser(true);
3096 props->UpdateSelectedOptionFontColorSetByUser(true);
3097 selectPattern->SetColorByUser(select, theme);
3098
3099 selectPattern->fontColor_ = Color::RED;
3100 props->UpdateFontColorSetByUser(false);
3101 selectPattern->SetColorByUser(select, theme);
3102 EXPECT_FALSE(selectPattern->fontColor_.has_value());
3103
3104 props->UpdateSelectedOptionBgColorSetByUser(false);
3105 selectPattern->SetColorByUser(select, theme);
3106 EXPECT_EQ(theme->GetSelectedColor(), selectPattern->selectedBgColor_);
3107
3108 props->UpdateSelectedOptionFontColorSetByUser(false);
3109 selectPattern->SetColorByUser(select, theme);
3110 EXPECT_EQ(theme->GetSelectedColorText(), selectPattern->selectedFont_.FontColor);
3111 g_isConfigChangePerform = false;
3112 }
3113
3114 /**
3115 * @tc.name: FontColorByUser001
3116 * @tc.desc: Test FontColorByUser func.
3117 * @tc.type: FUNC
3118 */
3119 HWTEST_F(SelectPatternTestNg, FontColorByUser001, TestSize.Level1)
3120 {
3121 /**
3122 * @tc.steps: step1. Create select model, initialize frame node, obtain related objects.
3123 * @tc.expected: step1. Select model and frame node are created successfully, related objects are obtained.
3124 */
3125 SelectModelNG selectModelInstance;
3126 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
3127 selectModelInstance.Create(params);
3128 selectModelInstance.SetFontColorByUser(true);
3129 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3130 ASSERT_NE(select, nullptr);
3131 auto props = select->GetPaintProperty<SelectPaintProperty>();
3132 ASSERT_NE(props, nullptr);
3133 EXPECT_TRUE(props->GetFontColorSetByUserValue(false));
3134
3135 /**
3136 * @tc.steps: step2. call ResetFontColor.
3137 * @tc.expected: step2. Font color is reset, FontColorSetByUser flag is updated.
3138 */
3139 selectModelInstance.ResetFontColor();
3140 EXPECT_FALSE(props->GetFontColorSetByUserValue(false));
3141
3142 auto pipeline = select->GetContextWithCheck();
3143 ASSERT_NE(pipeline, nullptr);
3144 auto selectTheme = pipeline->GetTheme<SelectTheme>(select->GetThemeScopeId());
3145 ASSERT_NE(selectTheme, nullptr);
3146 auto selectPattern = select->GetPattern<SelectPattern>();
3147 ASSERT_NE(selectPattern, nullptr);
3148
3149 /**
3150 * @tc.steps: step3. Test UpdateComponentColor with BACKGROUND_COLOR.
3151 * @tc.expected: The color is updated correctly.
3152 */
3153 selectPattern->SetModifierByUser(selectTheme, props);
3154 ASSERT_NE(selectPattern->text_, nullptr);
3155 auto textProps = selectPattern->text_->GetLayoutProperty<TextLayoutProperty>();
3156 ASSERT_NE(textProps, nullptr);
3157 ASSERT_EQ(textProps->GetTextColor(), selectTheme->GetFontColor());
3158 auto context = selectPattern->text_->GetRenderContext();
3159 ASSERT_NE(context, nullptr);
3160 ASSERT_EQ(context->GetForegroundColor(), selectTheme->GetFontColor());
3161 }
3162
3163 /**
3164 * @tc.name: UpdateComponentColor001
3165 * @tc.desc: Test UpdateComponentColor.
3166 * @tc.type: FUNC
3167 */
3168 HWTEST_F(SelectPatternTestNg, UpdateComponentColor001, TestSize.Level1)
3169 {
3170 /**
3171 * @tc.steps: step1. Create select model and initialize frame node.
3172 * @tc.expected: step1. Select model and frame node are created successfully.
3173 */
3174 SelectModelNG selectModelNG;
3175 std::vector<SelectParam> params = { { OPTION_TEXT_3, INTERNAL_SOURCE } };
3176 selectModelNG.Create(params);
3177 auto frameNode = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3178 ASSERT_NE(frameNode, nullptr);
3179 auto pipelineContext = PipelineBase::GetCurrentContextSafely();
3180 ASSERT_NE(pipelineContext, nullptr);
3181 auto renderContext = frameNode->GetRenderContext();
3182 ASSERT_NE(renderContext, nullptr);
3183 auto pattern = frameNode->GetPattern<SelectPattern>();
3184 ASSERT_NE(pattern, nullptr);
3185
3186 /**
3187 * @tc.steps: step2. Test UpdateComponentColor under different system color change and rerenderable states.
3188 * @tc.expected: step2. Component colors are updated correctly when system color changes and node is rerenderable.
3189 */
3190 std::vector<std::pair<bool, bool>> vec { { true, true }, { true, false }, { false, true }, { false, false } };
3191 for (const auto& pair : vec) {
3192 pipelineContext->SetIsSystemColorChange(pair.first);
3193 frameNode->SetRerenderable(pair.second);
3194 pattern->UpdateComponentColor(Color::RED, static_cast<SelectColorType>(7));
3195 if (pipelineContext->IsSystmColorChange() && pair.second) {
3196 pattern->UpdateComponentColor(Color::RED, SelectColorType::FONT_COLOR);
3197 EXPECT_EQ(pattern->fontColor_, Color::RED);
3198 pattern->UpdateComponentColor(Color::RED, SelectColorType::BACKGROUND_COLOR);
3199 auto ret = renderContext->GetBackgroundColor();
3200 EXPECT_EQ(ret, Color::RED);
3201 pattern->UpdateComponentColor(Color::RED, SelectColorType::SELECTED_OPTION_BG_COLOR);
3202 EXPECT_EQ(pattern->selectedBgColor_, Color::RED);
3203 pattern->UpdateComponentColor(Color::RED, SelectColorType::SELECTED_OPTION_FONT_COLOR);
3204 EXPECT_EQ(pattern->selectedFont_.FontColor, Color::RED);
3205 pattern->UpdateComponentColor(Color::RED, SelectColorType::OPTION_BG_COLOR);
3206 EXPECT_EQ(pattern->optionBgColor_, Color::RED);
3207 pattern->UpdateComponentColor(Color::RED, SelectColorType::OPTION_FONT_COLOR);
3208 EXPECT_EQ(pattern->optionBgColor_, Color::RED);
3209 pattern->UpdateComponentColor(Color::RED, SelectColorType::MENU_BACKGROUND_COLOR);
3210 }
3211 }
3212 }
3213
3214 /**
3215 * @tc.name: UpdateMenuOption
3216 * @tc.desc: Test UpdateMenuOption.
3217 * @tc.type: FUNC
3218 */
3219 HWTEST_F(SelectPatternTestNg, UpdateMenuOption, TestSize.Level1)
3220 {
3221 SelectModelNG selectModelInstance;
3222 std::vector<SelectParam> params = { { OPTION_TEXT, FILE_SOURCE } };
3223 selectModelInstance.Create(params);
3224
3225 auto select = ViewStackProcessor::GetInstance()->GetMainFrameNode();
3226 ASSERT_NE(select, nullptr);
3227 auto selectPattern = select->GetPattern<SelectPattern>();
3228 ASSERT_NE(selectPattern, nullptr);
3229 auto menuNode = selectPattern->GetMenuNode();
3230 ASSERT_NE(menuNode, nullptr);
3231 auto menuPattern = menuNode->GetPattern<MenuPattern>();
3232 ASSERT_NE(menuPattern, nullptr);
3233
3234 // Ensure there is at least one option
3235 ASSERT_FALSE(menuPattern->GetOptions().empty());
3236 auto menuItemNode = AceType::DynamicCast<FrameNode>(menuPattern->GetOptions().at(0));
3237 ASSERT_NE(menuItemNode, nullptr);
3238 auto menuItemPattern = menuItemNode->GetPattern<MenuItemPattern>();
3239 ASSERT_NE(menuItemPattern, nullptr);
3240
3241 // Test text update
3242 const std::string newText = "UpdatedText";
3243 selectPattern->UpdateMenuOption(0, newText, SelectOptionType::TEXT);
3244 EXPECT_EQ(menuItemPattern->GetText(), newText);
3245
3246 // Test invalid update
3247 selectPattern->UpdateMenuOption(0, "UnusedValue", static_cast<SelectOptionType>(999));
3248
3249 // Test icon update
3250 const std::string newIcon = "/path/to/icon.png";
3251 selectPattern->UpdateMenuOption(0, newIcon, SelectOptionType::ICON);
3252 auto iconNode = menuItemPattern->icon_;
3253 ASSERT_NE(iconNode, nullptr);
3254 ASSERT_EQ(iconNode->GetTag(), V2::IMAGE_ETS_TAG);
3255 auto props = iconNode->GetLayoutProperty<ImageLayoutProperty>();
3256 ASSERT_NE(props, nullptr);
3257 auto imageSrcInfo = props->GetImageSourceInfo();
3258 EXPECT_EQ(imageSrcInfo->GetSrc(), newIcon);
3259 }
3260 } // namespace OHOS::Ace::NG
3261