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 | ti := TextInput { |
9 | input-type: number; |
10 | } |
11 | |
12 | property <bool> input_focused: ti.has_focus; |
13 | property <string> text <=> ti.text; |
14 | } |
15 | |
16 | /* |
17 | ```rust |
18 | use slint::platform::Key; |
19 | |
20 | let instance = TestCase::new().unwrap(); |
21 | slint_testing::send_mouse_click(&instance, 5., 5.); |
22 | assert!(instance.get_input_focused()); |
23 | assert!(instance.get_text().is_empty()); |
24 | |
25 | // accept number characters only |
26 | slint_testing::send_keyboard_char(&instance, 'a', true); |
27 | assert!(instance.get_text().is_empty()); |
28 | slint_testing::send_keyboard_char(&instance, Key::Shift.into(), true); |
29 | assert!(instance.get_text().is_empty()); |
30 | slint_testing::send_keyboard_char(&instance, '1', true); |
31 | assert_eq!(instance.get_text(), "1"); |
32 | ``` |
33 | */ |
34 | } |
35 | |
36 | #[test ] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> { |
37 | use i_slint_backend_testing as slint_testing; |
38 | slint_testing::init(); |
39 | use slint::platform::Key; |
40 | |
41 | let instance = TestCase::new().unwrap(); |
42 | slint_testing::send_mouse_click(&instance, x:5., y:5.); |
43 | assert!(instance.get_input_focused()); |
44 | assert!(instance.get_text().is_empty()); |
45 | |
46 | // accept number characters only |
47 | slint_testing::send_keyboard_char(&instance, string:'a' , pressed:true); |
48 | assert!(instance.get_text().is_empty()); |
49 | slint_testing::send_keyboard_char(&instance, string:Key::Shift.into(), pressed:true); |
50 | assert!(instance.get_text().is_empty()); |
51 | slint_testing::send_keyboard_char(&instance, string:'1' , pressed:true); |
52 | assert_eq!(instance.get_text(), "1" ); |
53 | Ok(()) |
54 | } |