• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-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 #ifndef FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_TABS_TABS_TEST_NG_H
17 #define FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_TABS_TABS_TEST_NG_H
18 
19 #include "test/unittest/core/pattern/test_ng.h"
20 #define private public
21 #define protected public
22 #include "test/mock/core/animation/mock_animation_manager.h"
23 
24 #include "core/components_ng/pattern/divider/divider_render_property.h"
25 #include "core/components_ng/pattern/swiper/swiper_pattern.h"
26 #include "core/components_ng/pattern/tabs/tab_content_model_ng.h"
27 #include "core/components_ng/pattern/tabs/tabs_model_ng.h"
28 #include "core/components_ng/pattern/tabs/tabs_pattern.h"
29 #include "core/components_ng/pattern/tabs/tab_bar_item_pattern.h"
30 #include "core/common/container.h"
31 
32 namespace OHOS::Ace::NG {
33 constexpr float TABS_WIDTH = 720.f;
34 constexpr float TABS_HEIGHT = 400.f;
35 constexpr int32_t TABCONTENT_NUMBER = 4;
36 constexpr float FIRST_ITEM_WIDTH = 800.0f;
37 constexpr float FIRST_ITEM_HEIGHT = 800.0f;
38 const SizeF FIRST_ITEM_SIZE(FIRST_ITEM_WIDTH, FIRST_ITEM_HEIGHT);
39 constexpr float TABBAR_WIDTH = 50.0f;
40 constexpr float TABBAR_HEIGHT = 40.0f;
41 constexpr float SWIPER_WIDTH = 750.0f;
42 constexpr float SWIPER_HEIGHT = 500.0f;
43 constexpr float DIVIDER_STROKE_WIDTH = 10.0f;
44 constexpr float TABS_PADDING = 20.0f;
45 const int BEGIN_INDEX = 0;
46 const int CURRENT_INDEX = 1;
47 const OffsetF CURRENT_OFFSET(1.0f, 1.0f);
48 constexpr float TEST_MASK_A_RADIUS_RATIO = 0.0f;
49 constexpr float TEST_MASK_B_RADIUS_RATIO = 1.414f;
50 constexpr float TEST_MASK_MIDDLE_RADIUS_RATIO = (TEST_MASK_A_RADIUS_RATIO + TEST_MASK_B_RADIUS_RATIO) / 2.0f;
51 constexpr int32_t TEST_DIVIDER_INDEX = 1;
52 constexpr int32_t TEST_TAB_BAR_INDEX = 2;
53 constexpr int32_t TEST_SELECTED_MASK_COUNT = 2;
54 constexpr int32_t TEST_UNSELECTED_MASK_COUNT = 1;
55 constexpr int32_t LG_COLUMN_NUM = 12;
56 constexpr int32_t XS_COLUMN_NUM = 2;
57 constexpr int32_t TAB_BAR_SIZE = 56.0f;
58 constexpr float BAR_ITEM_SIZE = 10.0f;
59 constexpr float BIG_FONT_SIZE_SCALE = 1.75f;
60 constexpr float LARGE_FONT_SIZE_SCALE = 2.0f;
61 constexpr float MAX_FONT_SIZE_SCALE = 3.2f;
62 constexpr double BIG_DIALOG_WIDTH = 216.0;
63 constexpr double MAX_DIALOG_WIDTH = 256.0;
64 const std::string IMAGE_SRC_URL = "file://data/data/com.example.test/res/example.svg";
65 constexpr int8_t MASK_COUNT = 2;
66 constexpr float DRAG_DELTA = TABS_WIDTH;
67 
68 class TabsTestNg : public TestNG {
69 public:
70     static void SetUpTestSuite();
71     static void TearDownTestSuite();
72     void SetUp() override;
73     void TearDown() override;
74     void GetTabs();
75     TabsModelNG CreateTabs(BarPosition barPosition = BarPosition::START, int32_t index = 0);
76     TabContentModelNG CreateTabContent();
77     TabContentModelNG CreateTabContentWithDeepRender(std::function<void()>&& deepRenderFunc);
78     void CreateTabContents(int32_t itemNumber = TABCONTENT_NUMBER);
79     void CreateTabContentsWithBuilder(int32_t itemNumber = TABCONTENT_NUMBER);
80     void CreateTabsDone(TabsModelNG model);
81     TabBarBuilderFunc TabBarItemBuilder();
82     void CreateTabContentTabBarStyle(TabBarStyle tabBarStyle);
83     void CreateTabContentTabBarStyleWithBuilder(TabBarStyle tabBarStyle);
84     void ChangeIndex(int32_t index);
85     void HandleClick(int32_t index);
86     void HandleMouseEvent(MouseAction action, Offset location);
87     void HandleHoverEvent(bool isHover);
88     GestureEvent CreateDragInfo(bool moveDirection);
89     void MockPaintRect(const RefPtr<FrameNode>& frameNode);
90     void MockPaintRectSmallSize(const RefPtr<FrameNode>& frameNode);
91     RefPtr<TabBarModifier> OnDraw();
92     AssertionResult CurrentIndex(int32_t expectIndex);
93     AssertionResult VerifyBackgroundColor(int32_t itemIndex, Color expectColor);
94 
95     RefPtr<TabsNode> frameNode_;
96     RefPtr<TabsPattern> pattern_;
97     RefPtr<TabsLayoutProperty> layoutProperty_;
98 
99     RefPtr<FrameNode> swiperNode_;
100     RefPtr<SwiperPattern> swiperPattern_;
101     RefPtr<SwiperLayoutProperty> swiperLayoutProperty_;
102     RefPtr<SwiperPaintProperty> swiperPaintProperty_;
103     RefPtr<SwiperController> swiperController_;
104 
105     RefPtr<FrameNode> tabBarNode_;
106     RefPtr<TabBarPattern> tabBarPattern_;
107     RefPtr<TabBarLayoutProperty> tabBarLayoutProperty_;
108     RefPtr<TabBarPaintProperty> tabBarPaintProperty_;
109     RefPtr<TabBarAccessibilityProperty> tabBarAccessibilityProperty_;
110 
111     RefPtr<FrameNode> dividerNode_;
112     RefPtr<DividerRenderProperty> dividerRenderProperty_;
113 };
114 } // namespace OHOS::Ace::NG
115 #endif // FOUNDATION_ACE_TEST_UNITTEST_CORE_PATTERN_TABS_TABS_TEST_NG_H
116