| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  | use flowy_sync::client_folder::{FolderNodePad, WorkspaceNode};
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn client_folder_create_default_folder_test() {
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |     let folder_pad = FolderNodePad::new();
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     let json = folder_pad.to_json(false).unwrap();
 | 
					
						
							|  |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         json,
 | 
					
						
							|  |  |  |         r#"{"type":"folder","children":[{"type":"workspaces"},{"type":"trash"}]}"#
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn client_folder_create_default_folder_with_workspace_test() {
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |     let mut folder_pad = FolderNodePad::new();
 | 
					
						
							|  |  |  |     let workspace = WorkspaceNode::new(folder_pad.tree.clone(), "1".to_string(), "workspace name".to_string());
 | 
					
						
							|  |  |  |     folder_pad.workspaces.add_workspace(workspace).unwrap();
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     let json = folder_pad.to_json(false).unwrap();
 | 
					
						
							|  |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         json,
 | 
					
						
							|  |  |  |         r#"{"type":"folder","children":[{"type":"workspaces","children":[{"type":"workspace","attributes":{"id":"1","name":"workspace name"}}]},{"type":"trash"}]}"#
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         folder_pad.get_workspace("1").unwrap().get_name().unwrap(),
 | 
					
						
							|  |  |  |         "workspace name"
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn client_folder_delete_workspace_test() {
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |     let mut folder_pad = FolderNodePad::new();
 | 
					
						
							|  |  |  |     let workspace = WorkspaceNode::new(folder_pad.tree.clone(), "1".to_string(), "workspace name".to_string());
 | 
					
						
							|  |  |  |     folder_pad.workspaces.add_workspace(workspace).unwrap();
 | 
					
						
							|  |  |  |     folder_pad.workspaces.remove_workspace("1");
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     let json = folder_pad.to_json(false).unwrap();
 | 
					
						
							|  |  |  |     assert_eq!(
 | 
					
						
							|  |  |  |         json,
 | 
					
						
							|  |  |  |         r#"{"type":"folder","children":[{"type":"workspaces"},{"type":"trash"}]}"#
 | 
					
						
							|  |  |  |     );
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[test]
 | 
					
						
							|  |  |  | fn client_folder_update_workspace_name_test() {
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |     let mut folder_pad = FolderNodePad::new();
 | 
					
						
							|  |  |  |     let workspace = WorkspaceNode::new(folder_pad.tree.clone(), "1".to_string(), "workspace name".to_string());
 | 
					
						
							|  |  |  |     folder_pad.workspaces.add_workspace(workspace).unwrap();
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     folder_pad
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |         .workspaces
 | 
					
						
							|  |  |  |         .get_mut_workspace("1")
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |         .unwrap()
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |         .set_name("my first workspace".to_string());
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     assert_eq!(
 | 
					
						
							| 
									
										
										
										
											2022-12-04 15:23:24 +08:00
										 |  |  |         folder_pad.workspaces.get_workspace("1").unwrap().get_name().unwrap(),
 | 
					
						
							|  |  |  |         "my first workspace"
 | 
					
						
							| 
									
										
										
										
											2022-12-02 22:31:03 +08:00
										 |  |  |     );
 | 
					
						
							|  |  |  | }
 |