| 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 | TestCase := Rectangle { |
| 5 | width: 400phx; |
| 6 | height: 600phx; |
| 7 | |
| 8 | input1 := TextInput { |
| 9 | width: parent.width; |
| 10 | height: 200phx; |
| 11 | } |
| 12 | |
| 13 | input2 := TextInput { |
| 14 | y: 200phx; |
| 15 | width: parent.width; |
| 16 | height: 200phx; |
| 17 | } |
| 18 | |
| 19 | input3 := TextInput { |
| 20 | y: 400phx; |
| 21 | width: parent.width; |
| 22 | height: 200phx; |
| 23 | read-only: true; |
| 24 | } |
| 25 | |
| 26 | property<bool> input1_focused: input1.has_focus; |
| 27 | property<string> input1_text: input1.text; |
| 28 | property<bool> input2_focused: input2.has_focus; |
| 29 | property<string> input2_text: input2.text; |
| 30 | property<bool> input3_focused: input3.has_focus; |
| 31 | } |
| 32 | |
| 33 | /* |
| 34 | ```rust |
| 35 | use slint::private_unstable_api::re_exports::{InputMethodRequest, InputType, MouseCursor}; |
| 36 | |
| 37 | let instance = TestCase::new().unwrap(); |
| 38 | assert!(!instance.get_input1_focused()); |
| 39 | assert!(!instance.get_input2_focused()); |
| 40 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).len(), 0); |
| 41 | |
| 42 | slint_testing::send_mouse_click(&instance, 150., 100.); |
| 43 | assert!(instance.get_input1_focused()); |
| 44 | assert!(!instance.get_input2_focused()); |
| 45 | let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter(); |
| 46 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Enable(props)) if props.input_type == InputType::Text)); |
| 47 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Update(..)))); |
| 48 | assert!(ime_requests.next().is_none()); |
| 49 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text); |
| 50 | |
| 51 | slint_testing::send_keyboard_string_sequence(&instance, "Only for field 1"); |
| 52 | assert_eq!(instance.get_input1_text(), "Only for field 1"); |
| 53 | assert_eq!(instance.get_input2_text(), ""); |
| 54 | |
| 55 | slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()); |
| 56 | slint_testing::send_mouse_click(&instance, 150., 300.); |
| 57 | assert!(!instance.get_input1_focused()); |
| 58 | assert!(instance.get_input2_focused()); |
| 59 | let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter(); |
| 60 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Disable))); |
| 61 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Enable(props)) if props.input_type == InputType::Text)); |
| 62 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Update(..)))); |
| 63 | assert!(ime_requests.next().is_none()); |
| 64 | |
| 65 | |
| 66 | slint_testing::send_keyboard_string_sequence(&instance, "Only for field 2"); |
| 67 | assert_eq!(instance.get_input1_text(), "Only for field 1"); |
| 68 | assert_eq!(instance.get_input2_text(), "Only for field 2"); |
| 69 | |
| 70 | slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()); |
| 71 | slint_testing::send_mouse_click(&instance, 150., 500.); |
| 72 | assert!(!instance.get_input1_focused()); |
| 73 | assert!(!instance.get_input2_focused()); |
| 74 | assert!(instance.get_input3_focused()); |
| 75 | let mut ime_requests = slint_testing::access_testing_window(instance.window(), |window| window.ime_requests.take()).into_iter(); |
| 76 | assert!(matches!(ime_requests.next(), Some(InputMethodRequest::Disable))); |
| 77 | assert!(ime_requests.next().is_none()); |
| 78 | assert_eq!(slint_testing::access_testing_window(instance.window(), |window| window.mouse_cursor.get()), MouseCursor::Text); |
| 79 | |
| 80 | ``` |
| 81 | |
| 82 | ```cpp |
| 83 | auto handle = TestCase::create(); |
| 84 | const TestCase &instance = *handle; |
| 85 | assert(!instance.get_input1_focused()); |
| 86 | assert(!instance.get_input2_focused()); |
| 87 | |
| 88 | slint_testing::send_mouse_click(&instance, 150., 100.); |
| 89 | assert(instance.get_input1_focused()); |
| 90 | assert(!instance.get_input2_focused()); |
| 91 | |
| 92 | slint_testing::send_keyboard_string_sequence(&instance, "Only for field 1"); |
| 93 | assert_eq(instance.get_input1_text(), "Only for field 1"); |
| 94 | assert_eq(instance.get_input2_text(), ""); |
| 95 | |
| 96 | slint_testing::send_mouse_click(&instance, 150., 300.); |
| 97 | assert(!instance.get_input1_focused()); |
| 98 | assert(instance.get_input2_focused()); |
| 99 | |
| 100 | slint_testing::send_keyboard_string_sequence(&instance, "Only for field 2"); |
| 101 | assert_eq(instance.get_input1_text(), "Only for field 1"); |
| 102 | assert_eq(instance.get_input2_text(), "Only for field 2"); |
| 103 | ``` |
| 104 | |
| 105 | ```js |
| 106 | var instance = new slint.TestCase(); |
| 107 | assert(!instance.input1_focused); |
| 108 | assert(!instance.input2_focused); |
| 109 | |
| 110 | slintlib.private_api.send_mouse_click(instance, 150., 100.); |
| 111 | assert(instance.input1_focused); |
| 112 | assert(!instance.input2_focused); |
| 113 | |
| 114 | slintlib.private_api.send_keyboard_string_sequence(instance, "Only for field 1"); |
| 115 | assert.equal(instance.input1_text, "Only for field 1"); |
| 116 | assert.equal(instance.input2_text, ""); |
| 117 | |
| 118 | slintlib.private_api.send_mouse_click(instance, 150., 300.); |
| 119 | assert(!instance.input1_focused); |
| 120 | assert(instance.input2_focused); |
| 121 | |
| 122 | slintlib.private_api.send_keyboard_string_sequence(instance, "Only for field 2"); |
| 123 | assert.equal(instance.input1_text, "Only for field 1"); |
| 124 | assert.equal(instance.input2_text, "Only for field 2"); |
| 125 | ``` |
| 126 | */ |
| 127 | |