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