StratoSDK is a framework with a declarative approach similar to Flutter/React, written and designed entirely for Rust.
| 1 | use super::*; |
| 2 | use std::path::PathBuf; |
| 3 | use winit::window::WindowId as WinitWindowId; |
| 4 | |
| 5 | #[test] |
| 6 | fn test_drag_drop_debouncing_single_file() { |
| 7 | // Create a mock event loop structure |
| 8 | let window_id = WinitWindowId::from(1u64); |
| 9 | let mut state = State::default(); |
| 10 | state |
| 11 | .windows |
| 12 | .insert(window_id, WindowState::new(crate::WindowId::new())); |
| 13 | |
| 14 | // Simulate a single file drop |
| 15 | let path_buf = PathBuf::from("/path/to/file.txt"); |
| 16 | |
| 17 | // Process the event - this would normally be done by the event loop |
| 18 | if let Some(window_state) = state.windows.get_mut(&window_id) { |
| 19 | if let Some(path) = path_buf.as_os_str().to_str() { |
| 20 | window_state.pending_drag_drop_files.push(path.to_string()); |
| 21 | assert_eq!(window_state.pending_drag_drop_files.len(), 1); |
| 22 | assert_eq!(window_state.pending_drag_drop_files[0], "/path/to/file.txt"); |
| 23 | |
| 24 | // Verify timer flag is set correctly |
| 25 | window_state.has_pending_drag_drop_timer = true; |
| 26 | assert!(window_state.has_pending_drag_drop_timer); |
| 27 | } |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | #[test] |
| 32 | fn test_drag_drop_debouncing_multiple_files() { |
| 33 | let window_id = WinitWindowId::from(1u64); |
| 34 | let mut state = State::default(); |
| 35 | state |
| 36 | .windows |
| 37 | .insert(window_id, WindowState::new(crate::WindowId::new())); |
| 38 | |
| 39 | // Simulate multiple file drops |
| 40 | let files = vec![ |
| 41 | "/path/to/file w spaces.txt", |
| 42 | "/path/to/file2.txt", |
| 43 | "/path/to/file3.txt", |
| 44 | ]; |
| 45 | |
| 46 | if let Some(window_state) = state.windows.get_mut(&window_id) { |
| 47 | for file_path in files { |
| 48 | window_state |
| 49 | .pending_drag_drop_files |
| 50 | .push(file_path.to_string()); |
| 51 | } |
| 52 | |
| 53 | assert_eq!(window_state.pending_drag_drop_files.len(), 3); |
| 54 | assert_eq!( |
| 55 | window_state.pending_drag_drop_files[0], |
| 56 | "/path/to/file w spaces.txt" |
| 57 | ); |
| 58 | assert_eq!( |
| 59 | window_state.pending_drag_drop_files[1], |
| 60 | "/path/to/file2.txt" |
| 61 | ); |
| 62 | assert_eq!( |
| 63 | window_state.pending_drag_drop_files[2], |
| 64 | "/path/to/file3.txt" |
| 65 | ); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | #[test] |
| 70 | fn test_empty_drag_drop_handling() { |
| 71 | let window_id = WinitWindowId::from(1u64); |
| 72 | let mut state = State::default(); |
| 73 | state |
| 74 | .windows |
| 75 | .insert(window_id, WindowState::new(crate::WindowId::new())); |
| 76 | |
| 77 | if let Some(window_state) = state.windows.get_mut(&window_id) { |
| 78 | // Verify that empty file list is handled correctly |
| 79 | assert!(window_state.pending_drag_drop_files.is_empty()); |
| 80 | |
| 81 | // Simulate debounced event handling with empty list |
| 82 | window_state.has_pending_drag_drop_timer = false; |
| 83 | |
| 84 | if window_state.pending_drag_drop_files.is_empty() { |
| 85 | // Should return early without creating an event |
| 86 | assert!(window_state.pending_drag_drop_files.is_empty()); |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 |