| 1 | fn native_fixture(scratch: &Scratch, fixture: &str, name: &str) -> PathBuf { |
| 2 | let target = scratch.path(name); |
| 3 | fs::copy( |
| 4 | Path::new(env!("CARGO_MANIFEST_DIR")) |
| 5 | .join("../../tests/rust-app-real-worker/fixtures") |
| 6 | .join(fixture), |
| 7 | &target, |
| 8 | ) |
| 9 | .unwrap(); |
| 10 | target |
| 11 | } |
| 12 | |
| 13 | #[test] |
| 14 | fn raw_gzip_save_dialog_corrects_names_and_preserves_cancel_and_conflict_choice() { |
| 15 | use zipelo_ui_memory_app::archive_dialog::Purpose; |
| 16 | let mut names = vec![".gz", "report.GZ", "report.Gz", "report.gz"]; |
| 17 | #[cfg(unix)] |
| 18 | names.push("report:2026.gz"); |
| 19 | for name in names { |
| 20 | let scratch = Scratch::new(); |
| 21 | let archive = native_fixture(&scratch, "sample.gz", name); |
| 22 | let original = fs::read(&archive).unwrap(); |
| 23 | let output = make_directory(&scratch.path("output")); |
| 24 | let (factory, observed) = observed_factory(); |
| 25 | let mut screen = Screen::new(factory); |
| 26 | screen.open(&archive); |
| 27 | assert_eq!( |
| 28 | screen.app.model.list_id.as_ref().unwrap().format, |
| 29 | Format::Gzip |
| 30 | ); |
| 31 | screen.click("압축해제"); |
| 32 | assert!(!screen.app.model.busy()); |
| 33 | assert_eq!(observed.borrow().jobs.len(), 1); |
| 34 | let request = screen.dialogs.0.borrow().requests.last().unwrap().clone(); |
| 35 | assert_eq!(request.purpose, Purpose::SaveGzip); |
| 36 | assert_eq!(request.directory, scratch.0); |
| 37 | assert_eq!( |
| 38 | request.file_name, |
| 39 | if name == ".gz" || name.contains(':') { |
| 40 | "압축 해제 파일" |
| 41 | } else { |
| 42 | "report" |
| 43 | } |
| 44 | ); |
| 45 | let existing = output.join("기존 파일.txt"); |
| 46 | fs::write(&existing, b"preserve").unwrap(); |
| 47 | screen |
| 48 | .dialogs |
| 49 | .0 |
| 50 | .borrow_mut() |
| 51 | .answers |
| 52 | .push_back(Some(vec![existing.clone()])); |
| 53 | screen.click("압축해제"); |
| 54 | let conflict = screen.await_conflict(); |
| 55 | assert_eq!(conflict.relative_name, "기존 파일.txt"); |
| 56 | screen.click("이름 바꿔 저장"); |
| 57 | screen.settle_conflict_result(); |
| 58 | completed(&screen.app.model); |
| 59 | let saved = output.join("기존 파일 (1).txt"); |
| 60 | assert_eq!(fs::read(saved).unwrap(), b"Zipelo real worker flow\n"); |
| 61 | assert_eq!(fs::read(existing).unwrap(), b"preserve"); |
| 62 | assert_eq!(fs::read(&archive).unwrap(), original); |
| 63 | assert!(matches!( |
| 64 | observed.borrow().starts.last(), |
| 65 | Some(Start::Extract { destination, gzip_output_name: Some(name), .. }) |
| 66 | if destination == &output && name == "기존 파일.txt" |
| 67 | )); |
| 68 | assert_reaped(&observed); |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | #[test] |
| 73 | fn mixed_case_zip_names_open_and_extract_through_native_dialog_responses() { |
| 74 | use zipelo_ui_memory_app::archive_dialog::Purpose; |
| 75 | for name in ["sample.ZIP", "sample.Zip", "sample.zIp"] { |
| 76 | let scratch = Scratch::new(); |
| 77 | let archive = native_fixture(&scratch, "sample.zip", name); |
| 78 | let original = fs::read(&archive).unwrap(); |
| 79 | let output = make_directory(&scratch.path("output")); |
| 80 | let (factory, observed) = observed_factory(); |
| 81 | let mut screen = Screen::new(factory); |
| 82 | screen |
| 83 | .dialogs |
| 84 | .0 |
| 85 | .borrow_mut() |
| 86 | .answers |
| 87 | .push_back(Some(vec![archive.clone()])); |
| 88 | screen.click("열기"); |
| 89 | screen.settle(); |
| 90 | assert_eq!(screen.dialogs.0.borrow().requests[0].purpose, Purpose::Open); |
| 91 | assert_eq!( |
| 92 | screen.app.model.list_id.as_ref().unwrap().format, |
| 93 | Format::Zip |
| 94 | ); |
| 95 | screen.extract(&output); |
| 96 | assert_eq!( |
| 97 | fs::read(output.join("content.txt")).unwrap(), |
| 98 | b"Zipelo real worker flow\n" |
| 99 | ); |
| 100 | assert_eq!(fs::read(archive).unwrap(), original); |
| 101 | assert_reaped(&observed); |
| 102 | } |
| 103 | } |