2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  ' dart:io ' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-21 18:53:59 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  ' package:appflowy/core/config/kv_keys.dart ' ;  
						 
					
						
							
								
									
										
										
										
											2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  ' package:archive/archive_io.dart ' ;  
						 
					
						
							
								
									
										
										
										
											2024-09-12 14:40:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								import  ' package:flutter/services.dart ' ;  
						 
					
						
							
								
									
										
										
										
											2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								import  ' package:path/path.dart '  as  p ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  ' package:path_provider/path_provider.dart ' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								import  ' package:shared_preferences/shared_preferences.dart ' ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								enum  TestWorkspace  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  board ( " board " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-03 10:22:16 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  emptyDocument ( " empty_document " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-03 07:43:11 +00:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  aiWorkSpace ( " ai_workspace " ) , 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-03 10:22:16 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  coverImage ( " cover_image " ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  TestWorkspace ( this . _name ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  final  String  _name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Future < File >  get  zip  async  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  Directory  parent  =  await  TestWorkspace . _parent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  File  out  =  File ( p . join ( parent . path ,  ' $ _name .zip ' ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( await  out . exists ( ) )  return  out ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await  out . create ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  ByteData  data  =  await  rootBundle . load ( _asset ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await  out . writeAsBytes ( data . buffer . asUint8List ( ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  out ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Future < Directory >  get  root  async  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  Directory  parent  =  await  TestWorkspace . _parent ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  Directory ( p . join ( parent . path ,  _name ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  static  Future < Directory >  get  _parent  async  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  Directory  root  =  await  getTemporaryDirectory ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    if  ( await  root . exists ( ) )  return  root ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    await  root . create ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    return  root ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  String  get  _asset  = >  ' assets/test/workspaces/ $ _name .zip ' ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  TestWorkspaceService  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const  TestWorkspaceService ( this . workspace ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  final  TestWorkspace  workspace ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /// Instructs the application to read workspace data from the workspace found under this [TestWorkspace]'s path.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Future < void >  setUpAll ( )  async  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-06-11 14:19:44 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    final  root  =  await  workspace . root ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  path  =  root . path ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-30 14:09:08 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    SharedPreferences . setMockInitialValues ( { KVKeys . pathLocation:  path } ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  /// Workspaces that are checked into source are compressed. [TestWorkspaceService.setUp()] decompresses the file into an ephemeral directory that will be ignored by source control.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  Future < void >  setUp ( )  async  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  inputStream  = 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        InputFileStream ( await  workspace . zip . then ( ( value )  = >  value . path ) ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    final  archive  =  ZipDecoder ( ) . decodeBuffer ( inputStream ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-09-12 14:40:19 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    await  extractArchiveToDisk ( 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-10 15:10:42 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								      archive , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      await  TestWorkspace . _parent . then ( ( value )  = >  value . path ) , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-04-03 18:50:22 -10:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}