mirror of
https://github.com/slint-ui/slint.git
synced 2025-11-01 12:24:16 +00:00
tests: Test deleting the parent for a focus scope from a key event
Attempt at reproducing #5698 although that doesn't panic but the test is still worth commiting
This commit is contained in:
parent
b6167bd96f
commit
f88e5c8ef7
1 changed files with 69 additions and 0 deletions
|
|
@ -14,6 +14,20 @@ export global Glob {
|
|||
component Button {
|
||||
callback clicked();
|
||||
in property <string> text;
|
||||
HorizontalLayout {
|
||||
FocusScope {
|
||||
width: 1px;
|
||||
height: 3%;
|
||||
key-pressed(k) => {
|
||||
if k.text == " " {
|
||||
clicked();
|
||||
return accept;
|
||||
}
|
||||
return reject;
|
||||
}
|
||||
}
|
||||
Rectangle {}
|
||||
}
|
||||
Rectangle {
|
||||
background: yellow;
|
||||
Text { text: text; }
|
||||
|
|
@ -58,6 +72,24 @@ slint_testing::send_mouse_click(&instance, 150., 150.);
|
|||
assert_eq!(instance.global::<Glob<'_>>().get_value(), "world");
|
||||
```
|
||||
|
||||
// same thing but with the keyboard
|
||||
```rust
|
||||
let instance = TestCase::new().unwrap();
|
||||
let model = std::rc::Rc::new(slint::VecModel::<slint::SharedString>::from(
|
||||
vec!["hello".into(), "world".into()]));
|
||||
instance.global::<Glob<'_>>().set_model(model.clone().into());
|
||||
instance.global::<Glob<'_>>().on_clicked(move |val|{
|
||||
assert_eq!(val, "world");
|
||||
model.remove(1);
|
||||
});
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, " ");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, " ");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
assert_eq!(instance.global::<Glob<'_>>().get_value(), "world");
|
||||
```
|
||||
|
||||
```cpp
|
||||
auto handle = TestCase::create();
|
||||
TestCase &instance = *handle;
|
||||
|
|
@ -75,6 +107,27 @@ slint_testing::send_mouse_click(&instance, 150., 150.);
|
|||
assert_eq(instance.global<Glob>().get_value(), "world");
|
||||
```
|
||||
|
||||
```cpp
|
||||
auto handle = TestCase::create();
|
||||
TestCase &instance = *handle;
|
||||
|
||||
std::vector<slint::SharedString> array;
|
||||
array.push_back("hello");
|
||||
array.push_back("world");
|
||||
auto model = std::make_shared<slint::VectorModel<slint::SharedString>>(std::move(array));
|
||||
instance.global<Glob>().set_model(model);
|
||||
instance.global<Glob>().on_clicked([=](slint::SharedString val){
|
||||
assert_eq(val, "world");
|
||||
model->erase(1);
|
||||
});
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, " ");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, " ");
|
||||
slint_testing::send_keyboard_string_sequence(&instance, "\t");
|
||||
assert_eq(instance.global<Glob>().get_value(), "world");
|
||||
```
|
||||
|
||||
|
||||
```js
|
||||
var instance = new slint.TestCase({});
|
||||
|
|
@ -88,5 +141,21 @@ slintlib.private_api.send_mouse_click(instance, 150., 150.);
|
|||
assert.equal(instance.Glob.value, "world");
|
||||
```
|
||||
|
||||
```js
|
||||
var instance = new slint.TestCase({});
|
||||
let model = new slintlib.ArrayModel(["hello", "world"]);
|
||||
instance.Glob.model = model;
|
||||
instance.Glob.clicked = (val) => {
|
||||
assert.equal(val, "world");
|
||||
model.remove(1, 1);
|
||||
};
|
||||
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
|
||||
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
|
||||
slintlib.private_api.send_keyboard_string_sequence(instance, " ");
|
||||
slintlib.private_api.send_keyboard_string_sequence(instance, " ");
|
||||
slintlib.private_api.send_keyboard_string_sequence(instance, "\t");
|
||||
assert.equal(instance.Glob.value, "world");
|
||||
```
|
||||
|
||||
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue