mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-17 22:08:39 +00:00
Fix ElementHandle::find_by_element_id docs
Describe what an id is and provide an example.
This commit is contained in:
parent
7af0e7ae7c
commit
622991a627
6 changed files with 327 additions and 116 deletions
70
api/cpp/tests/testing.cpp
Normal file
70
api/cpp/tests/testing.cpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
// Copyright © SixtyFPS GmbH <info@slint.dev>
|
||||
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
#include <slint.h>
|
||||
#include <slint-interpreter.h>
|
||||
#include <slint-testing.h>
|
||||
|
||||
SCENARIO("ElementHandle")
|
||||
{
|
||||
using namespace slint::interpreter;
|
||||
using namespace slint;
|
||||
|
||||
ComponentCompiler compiler;
|
||||
|
||||
auto result = compiler.build_from_source(
|
||||
R"(
|
||||
component ButtonBase {
|
||||
@children
|
||||
}
|
||||
component PushButton inherits ButtonBase {
|
||||
in property <string> text <=> label.text;
|
||||
label := Text {}
|
||||
}
|
||||
export component App {
|
||||
VerticalLayout {
|
||||
PushButton { text: "first"; }
|
||||
second := PushButton { text: "second"; }
|
||||
}
|
||||
}
|
||||
)",
|
||||
"");
|
||||
for (auto &&x : compiler.diagnostics())
|
||||
std::cerr << x.message << std::endl;
|
||||
REQUIRE(result.has_value());
|
||||
auto component_definition = *result;
|
||||
|
||||
auto instance = component_definition.create();
|
||||
|
||||
SECTION("Find by accessible label")
|
||||
{
|
||||
auto elements = slint::testing::ElementHandle::find_by_accessible_label(instance, "first");
|
||||
REQUIRE(elements.size() == 1);
|
||||
REQUIRE(*elements[0].accessible_label() == "first");
|
||||
REQUIRE(*elements[0].id() == "PushButton::label");
|
||||
REQUIRE(*elements[0].type_name() == "Text");
|
||||
REQUIRE((*elements[0].bases()).size() == 0);
|
||||
}
|
||||
|
||||
SECTION("Find by id")
|
||||
{
|
||||
auto elements = slint::testing::ElementHandle::find_by_element_id(instance, "App::second");
|
||||
REQUIRE(elements.size() == 1);
|
||||
REQUIRE(*elements[0].id() == "App::second");
|
||||
REQUIRE(*elements[0].type_name() == "PushButton");
|
||||
REQUIRE((*elements[0].bases()).size() == 1);
|
||||
REQUIRE((*elements[0].bases())[0] == "ButtonBase");
|
||||
}
|
||||
|
||||
SECTION("Find by type name")
|
||||
{
|
||||
auto elements =
|
||||
slint::testing::ElementHandle::find_by_element_type_name(instance, "PushButton");
|
||||
REQUIRE(elements.size() == 2);
|
||||
REQUIRE(*elements[0].id() == "");
|
||||
REQUIRE(*elements[1].id() == "App::second");
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue