1#![allow(deprecated)]slint::slint!{#[style="material"#]
2#[include_path=r#"/input/slint/tests/driver/driverlib/../../cases/widgets"#]
3// Copyright © SixtyFPS GmbH <info@slint.dev>
4// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-1.1 OR LicenseRef-Slint-commercial
5
6import { ComboBox } from "std-widgets.slint";
7export component TestCase inherits Window {
8 width: 200px;
9 height: 200px;
10
11 in-out property <string> output;
12 TouchArea {
13 clicked => { output += "clicked-under\n"; }
14 }
15
16 VerticalLayout {
17 alignment: center;
18 box := ComboBox {
19 model: ["Aaa", "Bbb", "Ccc"];
20 selected => {
21 output += "selected("+self.current-value+","+self.current-index+")\n";
22 }
23 }
24 }
25
26 in-out property current-index <=> box.current-index;
27 in-out property current-value <=> box.current-value;
28 out property has-focus <=> box.has-focus;
29}
30
31/*
32
33
34```rust
35use slint::platform::Key;
36use slint::SharedString;
37
38let instance = TestCase::new().unwrap();
39
40assert_eq!(instance.get_current_value(), "Aaa");
41assert_eq!(instance.get_current_index(), 0);
42assert_eq!(instance.get_has_focus(), false);
43
44// Change the index programmatically
45instance.set_current_index(1);
46assert_eq!(instance.get_current_value(), "Bbb");
47assert_eq!(instance.get_current_index(), 1);
48assert_eq!(instance.get_output(), "");
49instance.set_current_index(0);
50assert_eq!(instance.get_current_value(), "Aaa");
51assert_eq!(instance.get_current_index(), 0);
52assert_eq!(instance.get_output(), "");
53assert_eq!(instance.get_has_focus(), false);
54
55// Open the combobox
56slint_testing::send_mouse_click(&instance, 100., 100.);
57assert_eq!(instance.get_output(), "");
58assert_eq!(instance.get_has_focus(), true);
59
60// click outside of the combobox, this should close it
61slint_testing::send_mouse_click(&instance, 100., 10.);
62assert_eq!(instance.get_output(), "");
63assert_eq!(instance.get_current_value(), "Aaa");
64assert_eq!(instance.get_current_index(), 0);
65assert_eq!(instance.get_has_focus(), true);
66
67// click outside of the combobox again
68slint_testing::send_mouse_click(&instance, 100., 10.);
69assert_eq!(instance.get_output(), "clicked-under\n");
70instance.set_output(Default::default());
71assert_eq!(instance.get_current_value(), "Aaa");
72assert_eq!(instance.get_current_index(), 0);
73assert_eq!(instance.get_has_focus(), true);
74
75
76// The arrow change the values
77slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
78assert_eq!(instance.get_current_value(), "Bbb");
79assert_eq!(instance.get_current_index(), 1);
80assert_eq!(instance.get_output(), "selected(Bbb,1)\n");
81slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
82assert_eq!(instance.get_current_value(), "Ccc");
83assert_eq!(instance.get_current_index(), 2);
84assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\n");
85slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
86assert_eq!(instance.get_current_value(), "Bbb");
87assert_eq!(instance.get_current_index(), 1);
88assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\nselected(Bbb,1)\n");
89instance.set_output(Default::default());
90
91
92```
93
94*/
95}
96
97#[test] fn t_0() -> std::result::Result<(), std::boxed::Box<dyn std::error::Error>> {
98 use i_slint_backend_testing as slint_testing;
99 slint_testing::init();
100 use slint::platform::Key;
101 use slint::SharedString;
102
103 let instance = TestCase::new().unwrap();
104
105 assert_eq!(instance.get_current_value(), "Aaa");
106 assert_eq!(instance.get_current_index(), 0);
107 assert_eq!(instance.get_has_focus(), false);
108
109 // Change the index programmatically
110 instance.set_current_index(1);
111 assert_eq!(instance.get_current_value(), "Bbb");
112 assert_eq!(instance.get_current_index(), 1);
113 assert_eq!(instance.get_output(), "");
114 instance.set_current_index(0);
115 assert_eq!(instance.get_current_value(), "Aaa");
116 assert_eq!(instance.get_current_index(), 0);
117 assert_eq!(instance.get_output(), "");
118 assert_eq!(instance.get_has_focus(), false);
119
120 // Open the combobox
121 slint_testing::send_mouse_click(&instance, 100., 100.);
122 assert_eq!(instance.get_output(), "");
123 assert_eq!(instance.get_has_focus(), true);
124
125 // click outside of the combobox, this should close it
126 slint_testing::send_mouse_click(&instance, 100., 10.);
127 assert_eq!(instance.get_output(), "");
128 assert_eq!(instance.get_current_value(), "Aaa");
129 assert_eq!(instance.get_current_index(), 0);
130 assert_eq!(instance.get_has_focus(), true);
131
132 // click outside of the combobox again
133 slint_testing::send_mouse_click(&instance, 100., 10.);
134 assert_eq!(instance.get_output(), "clicked-under\n");
135 instance.set_output(Default::default());
136 assert_eq!(instance.get_current_value(), "Aaa");
137 assert_eq!(instance.get_current_index(), 0);
138 assert_eq!(instance.get_has_focus(), true);
139
140
141 // The arrow change the values
142 slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
143 assert_eq!(instance.get_current_value(), "Bbb");
144 assert_eq!(instance.get_current_index(), 1);
145 assert_eq!(instance.get_output(), "selected(Bbb,1)\n");
146 slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::DownArrow));
147 assert_eq!(instance.get_current_value(), "Ccc");
148 assert_eq!(instance.get_current_index(), 2);
149 assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\n");
150 slint_testing::send_keyboard_string_sequence(&instance, &SharedString::from(Key::UpArrow));
151 assert_eq!(instance.get_current_value(), "Bbb");
152 assert_eq!(instance.get_current_index(), 1);
153 assert_eq!(instance.get_output(), "selected(Bbb,1)\nselected(Ccc,2)\nselected(Bbb,1)\n");
154 instance.set_output(Default::default());
155
156
157 Ok(())
158}