• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 "gtest/gtest.h"
17 
18 #include "core/components/common/layout/constants.h"
19 #include "frameworks/bridge/common/dom/dom_document.h"
20 #include "frameworks/bridge/common/dom/dom_tab_bar.h"
21 #include "frameworks/bridge/common/dom/dom_tab_content.h"
22 #include "frameworks/bridge/common/dom/dom_tabs.h"
23 #include "frameworks/bridge/test/unittest/jsfrontend/dom_node_factory.h"
24 
25 using namespace testing;
26 using namespace testing::ext;
27 
28 namespace OHOS::Ace::Framework {
29 namespace {
30 
31 const std::string TABS_TEST_001 = ""
32                                   "{                                                          "
33                                   "  \"tag\": \"tabs\"                                        "
34                                   "}";
35 
36 const std::string TABS_TEST_002 = ""
37                                   "{                                                          "
38                                   "  \"tag\": \"tabs\",                                       "
39                                   "  \"attr\": [{                                             "
40                                   "                \"index\" : \"2\"                          "
41                                   "             }]                                            "
42                                   "}";
43 
44 const std::string TABS_TEST_003 = ""
45                                   "{                                                          "
46                                   "  \"tag\": \"tabs\",                                       "
47                                   "  \"attr\": [{                                             "
48                                   "                \"vertical\" : \"true\"                    "
49                                   "             }]                                            "
50                                   "}";
51 
52 const std::string TABS_TEST_004 = ""
53                                   "{                                                          "
54                                   "  \"tag\": \"tabs\",                                       "
55                                   "  \"attr\": [{                                             "
56                                   "                \"vertical\" : \"false\"                   "
57                                   "             }]                                            "
58                                   "}";
59 
60 const std::string TABS_TEST_005 = ""
61                                   "{                                                          "
62                                   "  \"tag\": \"tabs\",                                       "
63                                   "  \"attr\": [{                                             "
64                                   "                \"index\" : \"2\"                          "
65                                   "             }]                                            "
66                                   "}";
67 
68 const std::string TABBAR_TEST_001 = ""
69                                     "{                                                        "
70                                     "  \"tag\": \"tab-bar\"                                   "
71                                     "}";
72 
73 const std::string TABBAR_TEST_002 = ""
74                                     "{                                                        "
75                                     "  \"tag\": \"tab-bar\" ,                                 "
76                                     "  \"attr\": [{                                           "
77                                     "                \"mode\" : \"fixed\"                     "
78                                     "             }]                                          "
79                                     "}";
80 
81 const std::string TABCONTENT_TEST_001 = ""
82                                         "{                                                    "
83                                         "  \"tag\": \"tab-content\"                           "
84                                         "}";
85 
86 const std::string TABCONTENT_TEST_002 = ""
87                                         "{                                                    "
88                                         "  \"tag\": \"tab-content\" ,                         "
89                                         "  \"attr\": [{                                       "
90                                         "                \"scrollable\" : \"false\"           "
91                                         "             }]                                      "
92                                         "}";
93 
94 const std::string TABCONTENT_TEST_003 = "                                                     "
95                                         "{                                                    "
96                                         "  \"tag\": \"tab-content\" ,                         "
97                                         "    \"commonStyle\": [{                              "
98                                         "        \"height\": \"1000px\"                       "
99                                         "    }],                                              "
100                                         "  \"attr\": [{                                       "
101                                         "                \"scrollable\" : \"false\"           "
102                                         "             }],                                     "
103                                         "   \"child\":                                        "
104                                         "{                                                    "
105                                         "    \"tag\":\"div\",                                 "
106                                         "    \"attr\": {},                                    "
107                                         "    \"commonStyle\": [{                              "
108                                         "        \"height\": \"2000px\"                       "
109                                         "    }]                                               "
110                                         "}                                                    "
111                                         "}";
112 
113 } // namespace
114 
115 class DomTabTest : public testing::Test {
116 public:
117     static void SetUpTestCase();
118     static void TearDownTestCase();
119     void SetUp();
120     void TearDown();
121 };
122 
SetUpTestCase()123 void DomTabTest::SetUpTestCase() {}
TearDownTestCase()124 void DomTabTest::TearDownTestCase() {}
SetUp()125 void DomTabTest::SetUp() {}
TearDown()126 void DomTabTest::TearDown() {}
127 
128 /**
129  * @tc.name: DomTabsCreatorTest001
130  * @tc.desc: Test tabs node are created as expected.
131  * @tc.type: FUNC
132  */
133 HWTEST_F(DomTabTest, DomTabsCreatorTest001, TestSize.Level1)
134 {
135     /**
136      * @tc.steps: step1. Construct string with right fields, then create tabs node with it.
137      * @tc.expected: step1. tabs node are created successfully.
138      */
139     auto tabs = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABS_TEST_001);
140     ASSERT_TRUE(tabs != nullptr);
141 
142     /**
143      * @tc.steps: step2. Check styles and attributes of created tabs node.
144      * @tc.expected: step2. The styles and attributes are as expected.
145      */
146     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->GetTabIndex(), 0U);
147     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->GetTabControllerId(), 1U);
148 }
149 
150 /**
151  * @tc.name: DomTabsCreatorTest002
152  * @tc.desc: Test tabs node are created as expected.
153  * @tc.type: FUNC
154  */
155 HWTEST_F(DomTabTest, DomTabsCreatorTest002, TestSize.Level1)
156 {
157     /**
158      * @tc.steps: step1. Construct string with right fields, then create tabs node with it.
159      * @tc.expected: step1. tabs node are created successfully.
160      */
161     auto tabs = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABS_TEST_002);
162     ASSERT_TRUE(tabs != nullptr);
163 
164     /**
165      * @tc.steps: step2. Check styles and attributes of created tabs node.
166      * @tc.expected: step2. The styles and attributes are as expected.
167      */
168     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->GetTabIndex(), 2U);
169     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->GetTabControllerId(), 2U);
170 }
171 
172 /**
173  * @tc.name: DomTabsCreatorTest003
174  * @tc.desc: Test tabs node are created as expected.
175  * @tc.type: FUNC
176  */
177 HWTEST_F(DomTabTest, DomTabsCreatorTest003, TestSize.Level1)
178 {
179     /**
180      * @tc.steps: step1. Construct string with right fields, then create tabs node with it.
181      * @tc.expected: step1. tabs node are created successfully.
182      */
183     auto tabs = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABS_TEST_003);
184     ASSERT_TRUE(tabs != nullptr);
185 
186     /**
187      * @tc.steps: step2. Check styles and attributes of created tabs node.
188      * @tc.expected: step2. The styles and attributes are as expected.
189      */
190     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->IsVertical(), true);
191 }
192 
193 /**
194  * @tc.name: DomTabsCreatorTest004
195  * @tc.desc: Test tabs node are created as expected.
196  * @tc.type: FUNC
197  */
198 HWTEST_F(DomTabTest, DomTabsCreatorTest004, TestSize.Level1)
199 {
200     /**
201      * @tc.steps: step1. Construct string with right fields, then create tabs node with it.
202      * @tc.expected: step1. tabs node are created successfully.
203      */
204     auto tabs = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABS_TEST_004);
205     ASSERT_TRUE(tabs != nullptr);
206 
207     /**
208      * @tc.steps: step2. Check styles and attributes of created tabs node.
209      * @tc.expected: step2. The styles and attributes are as expected.
210      */
211     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->IsVertical(), false);
212 }
213 
214 /**
215  * @tc.name: DomTabsCreatorTest005
216  * @tc.desc: Test tabs node are created as expected.
217  * @tc.type: FUNC
218  */
219 HWTEST_F(DomTabTest, DomTabsCreatorTest005, TestSize.Level1)
220 {
221     /**
222      * @tc.steps: step1. Construct string with right fields, then create tabs node with it.
223      * @tc.expected: step1. tabs node are created successfully.
224      */
225     auto tabs = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABS_TEST_005);
226     ASSERT_TRUE(tabs != nullptr);
227 
228     /**
229      * @tc.steps: step2. Check styles and attributes of created tabs node.
230      * @tc.expected: step2. The styles and attributes are as expected.
231      */
232     EXPECT_EQ(AceType::DynamicCast<DOMTabs>(tabs)->IsVertical(), false);
233 }
234 
235 /**
236  * @tc.name: DomTabBarCreatorTest001
237  * @tc.desc: Test tab-bar node are created as expected.
238  * @tc.type: FUNC
239  */
240 HWTEST_F(DomTabTest, DomTabBarCreatorTest001, TestSize.Level1)
241 {
242     /**
243      * @tc.steps: step1. Construct string with right fields, then create tab-bar node with it.
244      * @tc.expected: step1. tab-bar node and its component are created successfully.
245      */
246     auto tabBarNode = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABBAR_TEST_001);
247     auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(tabBarNode);
248     RefPtr<TabBarComponent> tabBarComponent = AceType::DynamicCast<TabBarComponent>(boxChild->GetChild());
249 
250     ASSERT_TRUE(tabBarComponent != nullptr);
251 
252     /**
253      * @tc.steps: step2. Check styles and attributes of created tab-bar node.
254      * @tc.expected: step2. The styles and attributes are as expected.
255      */
256     EXPECT_EQ(tabBarComponent->GetMode(), TabBarMode::SCROLLABLE);
257 }
258 
259 /**
260  * @tc.name: DomTabBarCreatorTest002
261  * @tc.desc: Test tab-bar node are created as expected.
262  * @tc.type: FUNC
263  */
264 HWTEST_F(DomTabTest, DomTabBarCreatorTest002, TestSize.Level1)
265 {
266     /**
267      * @tc.steps: step1. Construct string with right fields, then create tab-bar node with it.
268      * @tc.expected: step1. tab-bar node and its component are created successfully.
269      */
270     auto tabBarNode = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABBAR_TEST_002);
271     auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(tabBarNode);
272     RefPtr<TabBarComponent> tabBarComponent = AceType::DynamicCast<TabBarComponent>(boxChild->GetChild());
273 
274     ASSERT_TRUE(tabBarComponent != nullptr);
275 
276     /**
277      * @tc.steps: step2. Check styles and attributes of created tab-bar node.
278      * @tc.expected: step2. The styles and attributes are as expected.
279      */
280     EXPECT_EQ(tabBarComponent->GetMode(), TabBarMode::FIXED);
281 }
282 
283 /**
284  * @tc.name: DomTabContentCreatorTest001
285  * @tc.desc: Test tab-content node are created as expected.
286  * @tc.type: FUNC
287  */
288 HWTEST_F(DomTabTest, DomTabContentCreatorTest001, TestSize.Level1)
289 {
290     /**
291      * @tc.steps: step1. Construct string with right fields, then create tab-content node with it.
292      * @tc.expected: step1. tab-content node and its component are created successfully.
293      */
294     auto tabContentNode = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABCONTENT_TEST_001);
295     auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(tabContentNode);
296     RefPtr<TabContentComponent> tabContentComponent = AceType::DynamicCast<TabContentComponent>(boxChild->GetChild());
297 
298     ASSERT_TRUE(tabContentComponent != nullptr);
299 
300     /**
301      * @tc.steps: step2. Check styles and attributes of created tab-content node.
302      * @tc.expected: step2. The styles and attributes are as expected.
303      */
304     EXPECT_EQ(tabContentComponent->IsScrollable(), true);
305 }
306 
307 /**
308  * @tc.name: DomTabContentCreatorTest002
309  * @tc.desc: Test tab-content node are created as expected.
310  * @tc.type: FUNC
311  */
312 HWTEST_F(DomTabTest, DomTabContentCreatorTest002, TestSize.Level1)
313 {
314     /**
315      * @tc.steps: step1. Construct string with right fields, then create tab-content node with it.
316      * @tc.expected: step1. tab-content node and its component are created successfully.
317      */
318     auto tabContentNode = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABCONTENT_TEST_002);
319     auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(tabContentNode);
320     RefPtr<TabContentComponent> tabContentComponent = AceType::DynamicCast<TabContentComponent>(boxChild->GetChild());
321 
322     ASSERT_TRUE(tabContentComponent != nullptr);
323 
324     /**
325      * @tc.steps: step2. Check styles and attributes of created tab-content node.
326      * @tc.expected: step2. The styles and attributes are as expected.
327      */
328     EXPECT_EQ(tabContentComponent->IsScrollable(), false);
329 }
330 
331 /**
332  * @tc.name: DomTabContentCreatorTest003
333  * @tc.desc: Test tab-content node are created as expected.
334  * @tc.type: FUNC
335  */
336 HWTEST_F(DomTabTest, DomTabContentCreatorTest003, TestSize.Level1)
337 {
338     /**
339      * @tc.steps: step1. Construct string with right fields, then create tab-content node with it.
340      * @tc.expected: step1. tab-content node and its component are created successfully.
341      */
342     auto tabContentNode = DOMNodeFactory::GetInstance().CreateDOMNodeFromDsl(TABCONTENT_TEST_003);
343     auto boxChild = DOMNodeFactory::GetInstance().GetBoxChildComponent(tabContentNode);
344     RefPtr<TabContentComponent> tabContentComponent = AceType::DynamicCast<TabContentComponent>(boxChild->GetChild());
345 
346     ASSERT_TRUE(tabContentComponent != nullptr);
347 }
348 
349 } // namespace OHOS::Ace::Framework
350