| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  | use crate::grid::field_test::util::create_text_field;
 | 
					
						
							| 
									
										
										
										
											2023-02-02 23:02:49 +08:00
										 |  |  | use crate::grid::snapshot_test::script::{DatabaseSnapshotTest, SnapshotScript::*};
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							|  |  |  | async fn snapshot_create_test() {
 | 
					
						
							| 
									
										
										
										
											2023-02-02 23:02:49 +08:00
										 |  |  |     let mut test = DatabaseSnapshotTest::new().await;
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let (_, field_rev) = create_text_field(&test.grid_id());
 | 
					
						
							|  |  |  |     let scripts = vec![CreateField { field_rev }, WriteSnapshot];
 | 
					
						
							|  |  |  |     test.run_scripts(scripts).await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     let snapshot = test.current_snapshot.clone().unwrap();
 | 
					
						
							|  |  |  |     let content = test.grid_pad().await.json_str().unwrap();
 | 
					
						
							|  |  |  |     test.run_scripts(vec![AssertSnapshotContent {
 | 
					
						
							|  |  |  |         snapshot,
 | 
					
						
							|  |  |  |         expected: content,
 | 
					
						
							|  |  |  |     }])
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #[tokio::test]
 | 
					
						
							|  |  |  | async fn snapshot_multi_version_test() {
 | 
					
						
							| 
									
										
										
										
											2023-02-02 23:02:49 +08:00
										 |  |  |     let mut test = DatabaseSnapshotTest::new().await;
 | 
					
						
							| 
									
										
										
										
											2022-12-09 09:19:47 +08:00
										 |  |  |     let original_content = test.grid_pad().await.json_str().unwrap();
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Create a field
 | 
					
						
							|  |  |  |     let (_, field_rev) = create_text_field(&test.grid_id());
 | 
					
						
							|  |  |  |     let scripts = vec![
 | 
					
						
							|  |  |  |         CreateField {
 | 
					
						
							|  |  |  |             field_rev: field_rev.clone(),
 | 
					
						
							|  |  |  |         },
 | 
					
						
							|  |  |  |         WriteSnapshot,
 | 
					
						
							|  |  |  |     ];
 | 
					
						
							|  |  |  |     test.run_scripts(scripts).await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Delete a field
 | 
					
						
							|  |  |  |     let scripts = vec![DeleteField { field_rev }, WriteSnapshot];
 | 
					
						
							|  |  |  |     test.run_scripts(scripts).await;
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // The latest snapshot will be the same as the original content.
 | 
					
						
							|  |  |  |     test.run_scripts(vec![AssertSnapshotContent {
 | 
					
						
							|  |  |  |         snapshot: test.get_latest_snapshot().await.unwrap(),
 | 
					
						
							|  |  |  |         expected: original_content,
 | 
					
						
							|  |  |  |     }])
 | 
					
						
							|  |  |  |     .await;
 | 
					
						
							|  |  |  | }
 |