1 /* 2 * Copyright (C) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OHOS_ACE_COMPONENT_TEST_MATCHER_IMPL_H 17 #define OHOS_ACE_COMPONENT_TEST_MATCHER_IMPL_H 18 19 #include "component_test/core/component_test_component_impl.h" 20 21 #include "base/memory/referenced.h" 22 #include "core/components_ng/base/ui_node.h" 23 24 namespace OHOS::Ace::ComponentTest { 25 enum class MatchType : uint8_t { 26 EQUALS, 27 CONTAINS, 28 STARTS_WITH, 29 ENDS_WITH, 30 }; 31 32 using MatchFunc = std::function<bool(ComponentTestComponentImpl&)>; 33 34 struct MatchText { MatchTextMatchText35 MatchText() : text_(""), matchType(MatchType::EQUALS), isCheck(false) {}; MatchTextMatchText36 explicit MatchText(const std::string& text) : text_(text), matchType(MatchType::EQUALS), isCheck(true) {}; MatchTextMatchText37 MatchText(const std::string& text, MatchType matchType) : text_(text), matchType(matchType), isCheck(true) {}; 38 std::string text_; 39 MatchType matchType; 40 bool isCheck; 41 }; 42 43 struct MatchString { MatchStringMatchString44 MatchString() : value(""), isCheck(false) {}; MatchStringMatchString45 explicit MatchString(const std::string& value) : value(value), isCheck(true) {}; 46 std::string value; 47 bool isCheck; 48 }; 49 50 struct MatchBool { MatchBoolMatchBool51 MatchBool() : value(false), isCheck(false) {}; MatchBoolMatchBool52 explicit MatchBool(bool value) : value(value), isCheck(true) {}; 53 bool value; 54 bool isCheck; 55 }; 56 57 class ACE_FORCE_EXPORT ComponentTestMatcherImpl final { 58 public: 59 ComponentTestMatcherImpl() = default; 60 ~ComponentTestMatcherImpl() = default; 61 62 bool Match(const RefPtr<NG::UINode>& uiNode) const; 63 void SetText(const std::string& text, MatchType matchType = MatchType::EQUALS); 64 void SetId(const std::string& id); 65 void SetType(const std::string& type); 66 void SetClickable(bool clickabled); 67 void SetLongPressable(bool longPressable); 68 void SetScrollable(bool scrollable); 69 void SetEnabled(bool enabled); 70 void SetFocused(bool focused); 71 void SetSelected(bool selected); 72 void SetChecked(bool checked); 73 void SetCheckable(bool checkable); 74 75 private: 76 std::vector<MatchFunc> matchFuncs; 77 }; 78 79 } // namespace OHOS::Ace::ComponentTest 80 81 #endif // OHOS_NAPI_ACE_COMPONENT_TEST_MATCHER_IMPL_H 82