1 | #![allow (deprecated)]slint::slint!{#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/text"# ] |
2 | // Copyright © SixtyFPS GmbH <info@slint.dev> |
3 | // SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial |
4 | |
5 | TestCase := Window { |
6 | width: 100phx; |
7 | height: 100phx; |
8 | VerticalLayout { |
9 | padding: 0; |
10 | spacing: 0; |
11 | ti := TextInput { } |
12 | Rectangle { } |
13 | } |
14 | |
15 | property <string> text <=> ti.text; |
16 | property <bool> input_focused: ti.has_focus; |
17 | property<int> test_cursor_pos: ti.cursor_position_byte_offset; |
18 | } |
19 | |
20 | /* |
21 | ```rust |
22 | |
23 | const LEFT_CODE: char = '\u{F702}'; |
24 | |
25 | let instance = TestCase::new().unwrap(); |
26 | slint_testing::send_mouse_click(&instance, 5., 5.); |
27 | assert!(instance.get_input_focused()); |
28 | assert_eq!(instance.get_text(), ""); |
29 | slint_testing::send_keyboard_string_sequence(&instance, "Hallo"); |
30 | assert_eq!(instance.get_text(), "Hallo"); |
31 | instance.set_text("Yo".into()); |
32 | assert_eq!(instance.get_text(), "Yo"); |
33 | slint_testing::send_keyboard_string_sequence(&instance, "Hello Again"); |
34 | assert_eq!(instance.get_text(), "YoHello Again"); |
35 | instance.set_text("Yo".into()); |
36 | // Issue #331: assert_eq!(instance.get_test_cursor_pos(), 2); |
37 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
38 | assert_eq!(instance.get_test_cursor_pos(), 1); |
39 | ``` |
40 | */ |
41 | } |
42 | |
43 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
44 | use i_slint_backend_testing as slint_testing; |
45 | slint_testing::init(); |
46 | |
47 | const LEFT_CODE: char = ' \u{F702}' ; |
48 | |
49 | let instance = TestCase::new().unwrap(); |
50 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
51 | assert!(instance.get_input_focused()); |
52 | assert_eq!(instance.get_text(), "" ); |
53 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"Hallo" ); |
54 | assert_eq!(instance.get_text(), "Hallo" ); |
55 | instance.set_text("Yo" .into()); |
56 | assert_eq!(instance.get_text(), "Yo" ); |
57 | slint_testing::send_keyboard_string_sequence(&instance, sequence:"Hello Again" ); |
58 | assert_eq!(instance.get_text(), "YoHello Again" ); |
59 | instance.set_text("Yo" .into()); |
60 | // Issue #331: assert_eq!(instance.get_test_cursor_pos(), 2); |
61 | slint_testing::send_keyboard_string_sequence(&instance, &LEFT_CODE.to_string()); |
62 | assert_eq!(instance.get_test_cursor_pos(), 1); |
63 | Ok(()) |
64 | } |