| 1 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
| 2 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0 |
| 3 | |
| 4 | use i_slint_backend_testing::ElementHandle; |
| 5 | use slint::platform::PointerEventButton; |
| 6 | |
| 7 | #[test ] |
| 8 | fn test_click() { |
| 9 | i_slint_backend_testing::init_integration_test_with_system_time(); |
| 10 | |
| 11 | slint::spawn_local(async move { |
| 12 | slint::slint! { |
| 13 | export component App inherits Window { |
| 14 | out property <int> click-count: 0; |
| 15 | out property <int> double-click-count: 0; |
| 16 | ta := TouchArea { |
| 17 | clicked => { root.click-count += 1; } |
| 18 | double-clicked => { root.double-click-count += 1; } |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | let app = App::new().unwrap(); |
| 24 | |
| 25 | let mut it = ElementHandle::find_by_element_id(&app, "App::ta" ); |
| 26 | let elem = it.next().unwrap(); |
| 27 | assert!(it.next().is_none()); |
| 28 | |
| 29 | assert_eq!(app.get_click_count(), 0); |
| 30 | assert_eq!(app.get_double_click_count(), 0); |
| 31 | elem.single_click(PointerEventButton::Left).await; |
| 32 | assert_eq!(app.get_click_count(), 1); |
| 33 | assert_eq!(app.get_double_click_count(), 0); |
| 34 | |
| 35 | elem.double_click(PointerEventButton::Left).await; |
| 36 | assert_eq!(app.get_click_count(), 3); |
| 37 | assert_eq!(app.get_double_click_count(), 1); |
| 38 | |
| 39 | slint::quit_event_loop().unwrap(); |
| 40 | }) |
| 41 | .unwrap(); |
| 42 | slint::run_event_loop().unwrap(); |
| 43 | } |
| 44 | |