File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
crates/bitwarden-vault/src Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -235,4 +235,41 @@ mod tests {
235235 panic ! ( "Node not found" ) ;
236236 }
237237 }
238+
239+ #[ test]
240+ fn given_collection_with_two_children_where_there_parent_node_does_not_exist_children_are_returned_correctly ( ) {
241+ let child_1_id = Uuid :: new_v4 ( ) ;
242+ let grandparent_id = Uuid :: new_v4 ( ) ;
243+ let mut items = vec ! [
244+ TestItem {
245+ id: child_1_id,
246+ name: "grandparent/parent/child1" . to_string( )
247+ } ,
248+ TestItem {
249+ id: Uuid :: new_v4( ) ,
250+ name: "grandparent/parent/child2" . to_string( )
251+ } ,
252+ TestItem {
253+ id: grandparent_id,
254+ name: "grandparent" . to_string( )
255+ } ,
256+ ] ;
257+
258+ let node_option = Tree :: from_items ( & mut items)
259+ . get_item_by_id ( child_1_id) ;
260+
261+ if let Some ( node) = node_option {
262+ let item = node. item ;
263+ let parent = node. parent ;
264+ let children = node. children ;
265+
266+ assert_eq ! ( children. len( ) , 0 ) ;
267+ assert_eq ! ( item. id( ) , Some ( child_1_id) ) ;
268+ assert_eq ! ( item. short_name( ) , "child1" ) ;
269+ assert_eq ! ( item. path( ) , [ "grandparent" , "parent" , "child1" ] ) ;
270+ assert ! ( parent. is_none( ) ) ;
271+ } else {
272+ panic ! ( "Node not found" ) ;
273+ }
274+ }
238275}
You can’t perform that action at this time.
0 commit comments