Skip to content

Commit

Permalink
test reordering of nodes in freya-core
Browse files Browse the repository at this point in the history
  • Loading branch information
marc2332 committed Dec 19, 2024
1 parent 0fe95a9 commit a14dee6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
41 changes: 41 additions & 0 deletions crates/core/tests/nodes_reorder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use freya::prelude::*;
use freya_testing::prelude::*;

#[tokio::test]
pub async fn nodes_reorder() {
fn nodes_reorder() -> Element {
let mut data = use_signal(|| vec![1, 2, 3]);

rsx!(
rect {
onclick: move |_| {
let item = data.write().remove(0);
data.write().push(item);
},
label {
"Move"
}
}
for d in data.read().iter() {
label {
key: "{d}",
height: "20",
"{d}"
}
}
)
}

let mut utils = launch_test(nodes_reorder);
utils.wait_for_update().await;

assert_eq!(utils.root().get(1).get(0).text(), Some("1"));
assert_eq!(utils.root().get(2).get(0).text(), Some("2"));
assert_eq!(utils.root().get(3).get(0).text(), Some("3"));

utils.click_cursor((5., 5.)).await;

assert_eq!(utils.root().get(1).get(0).text(), Some("2"));
assert_eq!(utils.root().get(2).get(0).text(), Some("3"));
assert_eq!(utils.root().get(3).get(0).text(), Some("1"));
}
2 changes: 1 addition & 1 deletion crates/native-core/src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ impl<'a> TreeMut for TreeMutView<'a> {

let mut node_state = &mut self.1;
let old_node = node_state.get(old_id).unwrap();
let parent_id = old_node.parent.expect("tried to insert before root");
let parent_id = old_node.parent.expect("tried to insert after root");
(&mut node_state).get(new_id).unwrap().parent = Some(parent_id);
let parent = (&mut node_state).get(parent_id).unwrap();
let index = parent
Expand Down

0 comments on commit a14dee6

Please sign in to comment.