|
| 1 | +use cap_project::ProjectConfiguration; |
| 2 | +use serde_json::json; |
| 3 | + |
| 4 | +#[test] |
| 5 | +fn loading_sorts_scenes_without_changing_clip_edits() { |
| 6 | + let project = tempfile::tempdir().unwrap(); |
| 7 | + let path = project.path().join("project-config.json"); |
| 8 | + std::fs::write( |
| 9 | + &path, |
| 10 | + serde_json::to_vec(&json!({ |
| 11 | + "timeline": { |
| 12 | + "segments": [ |
| 13 | + { "recordingSegment": 1, "start": 20.0, "end": 22.0, "timescale": 0.25, "name": "Opening", "volume": 0.5 }, |
| 14 | + { "recordingSegment": 0, "start": 10.0, "end": 10.0, "timescale": 1.0 }, |
| 15 | + { "recordingSegment": 0, "start": 0.0, "end": 32.0, "timescale": 8.0 } |
| 16 | + ], |
| 17 | + "zoomSegments": [], |
| 18 | + "sceneSegments": [ |
| 19 | + { "start": 8.0, "end": 10.0, "mode": "cameraOnly" }, |
| 20 | + { "start": 1.0, "end": 3.0, "mode": "cameraOnly" }, |
| 21 | + { "start": 5.0, "end": 7.0, "mode": "hideCamera" } |
| 22 | + ] |
| 23 | + } |
| 24 | + })) |
| 25 | + .unwrap(), |
| 26 | + ) |
| 27 | + .unwrap(); |
| 28 | + |
| 29 | + let loaded = ProjectConfiguration::load(project.path()).unwrap(); |
| 30 | + loaded.write(project.path()).unwrap(); |
| 31 | + let reloaded = ProjectConfiguration::load(project.path()).unwrap(); |
| 32 | + for config in [&loaded, &reloaded] { |
| 33 | + let timeline = config.timeline.as_ref().unwrap(); |
| 34 | + assert_eq!( |
| 35 | + timeline |
| 36 | + .scene_segments |
| 37 | + .iter() |
| 38 | + .map(|scene| scene.start) |
| 39 | + .collect::<Vec<_>>(), |
| 40 | + [1.0, 5.0, 8.0] |
| 41 | + ); |
| 42 | + assert_eq!(timeline.duration(), 12.0); |
| 43 | + let (source_time, clip) = timeline.get_segment_time(0.0).unwrap(); |
| 44 | + assert_eq!((source_time, clip.recording_clip), (20.0, 1)); |
| 45 | + assert_eq!(clip.name.as_deref(), Some("Opening")); |
| 46 | + assert_eq!(clip.volume(), 0.5); |
| 47 | + let (source_time, clip) = timeline.get_segment_time(9.0).unwrap(); |
| 48 | + assert_eq!((source_time, clip.recording_clip), (8.0, 0)); |
| 49 | + assert_eq!(timeline.segments.len(), 3); |
| 50 | + assert_eq!(timeline.segments[1].duration(), 0.0); |
| 51 | + } |
| 52 | +} |
0 commit comments