Skip to content

Commit be4b93a

Browse files
committed
Add test case (non functional)
1 parent c812365 commit be4b93a

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

core/editor/src/communication/dispatcher.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ impl Dispatcher {
8282
#[cfg(test)]
8383
mod test {
8484
use crate::{
85+
communication::DocumentMessageHandler,
8586
message_prelude::{DocumentMessage, Message},
8687
misc::test_utils::EditorTestUtils,
8788
Editor,
@@ -302,4 +303,28 @@ mod test {
302303
assert_eq!(&layers_after_copy[4], rect_before_copy);
303304
assert_eq!(&layers_after_copy[5], ellipse_before_copy);
304305
}
306+
#[test]
307+
/// - create rect, shape and ellipse
308+
/// - select ellipse and rect
309+
/// - move them down and back up again
310+
fn move_seletion() {
311+
init_logger();
312+
let mut editor = create_editor_with_three_layers();
313+
314+
let verify_order = |handler: &mut DocumentMessageHandler| (handler.all_layers_sorted(), handler.non_selected_layers_sorted(), handler.selected_layers_sorted());
315+
316+
editor.handle_message(Message::Document(DocumentMessage::SelectLayers(vec![vec![0], vec![2]]))).unwrap();
317+
318+
editor.handle_message(Message::Document(DocumentMessage::ReorderSelectedLayers(1))).unwrap();
319+
let (all, non_selected, selected) = verify_order(&mut editor.dispatcher.document_message_handler);
320+
assert_eq!(all, non_selected.into_iter().chain(selected.into_iter()).collect::<Vec<_>>());
321+
322+
editor.handle_message(Message::Document(DocumentMessage::ReorderSelectedLayers(1))).unwrap();
323+
let (all, non_selected, selected) = verify_order(&mut editor.dispatcher.document_message_handler);
324+
assert_eq!(all, selected.into_iter().chain(non_selected.into_iter()).collect::<Vec<_>>());
325+
326+
editor.handle_message(Message::Document(DocumentMessage::ReorderSelectedLayers(i32::MIN))).unwrap();
327+
let (all, non_selected, selected) = verify_order(&mut editor.dispatcher.document_message_handler);
328+
assert_eq!(all, non_selected.into_iter().chain(selected.into_iter()).collect::<Vec<_>>());
329+
}
305330
}

core/editor/src/document/document_message_handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,17 +170,17 @@ impl DocumentMessageHandler {
170170
}
171171

172172
/// Returns the paths to all layers in order
173-
fn all_layers_sorted(&self) -> Vec<Vec<LayerId>> {
173+
pub fn all_layers_sorted(&self) -> Vec<Vec<LayerId>> {
174174
self.layers_sorted(None)
175175
}
176176

177177
/// Returns the paths to all selected layers in order
178-
fn selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
178+
pub fn selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
179179
self.layers_sorted(Some(true))
180180
}
181181

182182
/// Returns the paths to all selected layers in order
183-
fn non_selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
183+
pub fn non_selected_layers_sorted(&self) -> Vec<Vec<LayerId>> {
184184
self.layers_sorted(Some(false))
185185
}
186186
}

0 commit comments

Comments
 (0)