| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: MIT |
| 3 | |
| 4 | #include <slint-testing.h> |
| 5 | #include "../app.h" |
| 6 | |
| 7 | #define CATCH_CONFIG_MAIN |
| 8 | #include "catch2/catch.hpp" |
| 9 | |
| 10 | SCENARIO("Basic TEST" ) |
| 11 | { |
| 12 | slint::testing::init(); |
| 13 | auto state = create_ui(); |
| 14 | using todo_ui::TodoItem; |
| 15 | state.todo_model->set_vector({ TodoItem { "first" , true } }); |
| 16 | |
| 17 | auto line_edit = slint::testing::ElementHandle::visit_elements( |
| 18 | state.mainWindow, |
| 19 | [](slint::testing::ElementHandle element) |
| 20 | -> std::optional<slint::testing::ElementHandle> { |
| 21 | if (element.accessible_placeholder_text() == "What needs to be done?" ) { |
| 22 | return element; |
| 23 | } else { |
| 24 | return {}; |
| 25 | } |
| 26 | }); |
| 27 | |
| 28 | REQUIRE(line_edit); |
| 29 | line_edit->set_accessible_value("second" ); |
| 30 | |
| 31 | auto results = slint::testing::ElementHandle::find_by_accessible_label(state.mainWindow, |
| 32 | "Add New Entry" ); |
| 33 | REQUIRE(results.size() == 1); |
| 34 | auto button = results[0]; |
| 35 | button.invoke_accessible_default_action(); |
| 36 | |
| 37 | REQUIRE(state.todo_model->row_count() == 2); |
| 38 | REQUIRE(state.todo_model->row_data(0).value() == TodoItem { "first" , true }); |
| 39 | REQUIRE(state.todo_model->row_data(1).value() == TodoItem { "second" , false }); |
| 40 | |
| 41 | REQUIRE(line_edit->accessible_value() == "" ); |
| 42 | } |
| 43 | |