| 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 | ).unwrap(); |
| 9 | target |
| 10 | } |
| 11 | |
| 12 | #[test] |
| 13 | fn raw_gzip_save_dialog_corrects_names_and_preserves_cancel_and_conflict_retry() { |
| 14 | use zipelo_ui_memory_app::archive_dialog::Purpose; |
| 15 | let mut names = vec![".gz", "report.GZ", "report.Gz", "report.gz"]; |
| 16 | #[cfg(unix)] |
| 17 | names.push("report:2026.gz"); |
| 18 | for name in names { |
| 19 | let scratch = Scratch::new(); |
| 20 | let archive = native_fixture(&scratch, "sample.gz", name); |
| 21 | let original = fs::read(&archive).unwrap(); |
| 22 | let output = make_directory(&scratch.path("output")); |
| 23 | let (factory, observed) = observed_factory(); |
| 24 | let mut screen = Screen::new(factory); |
| 25 | screen.open(&archive); |
| 26 | assert_eq!(screen.app.model.list_id.as_ref().unwrap().format, Format::Gzip); |
| 27 | screen.click("압축해제"); |
| 28 | assert!(!screen.app.model.busy()); |
| 29 | assert_eq!(observed.borrow().jobs.len(), 1); |
| 30 | let request = screen.dialogs.0.borrow().requests.last().unwrap().clone(); |
| 31 | assert_eq!(request.purpose, Purpose::SaveGzip); |
| 32 | assert_eq!(request.directory, scratch.0); |
| 33 | assert_eq!(request.file_name, if name == ".gz" || name.contains(':') { "압축 해제 파일" } else { "report" }); |
| 34 | let existing = output.join("기존 파일.txt"); |
| 35 | fs::write(&existing, b"preserve").unwrap(); |
| 36 | screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![existing.clone()])); |
| 37 | screen.click("압축해제"); |
| 38 | let deadline = Instant::now() + Duration::from_secs(10); |
| 39 | while screen.app.model.busy() { |
| 40 | screen.render(vec![]); |
| 41 | assert!(Instant::now() < deadline); |
| 42 | std::thread::sleep(Duration::from_millis(2)); |
| 43 | } |
| 44 | assert_eq!(screen.app.model.terminal.as_ref().unwrap().error, Some(ErrorCode::Conflict)); |
| 45 | assert_eq!(fs::read(&existing).unwrap(), b"preserve"); |
| 46 | screen.click("다른 이름으로 저장"); |
| 47 | assert!(!screen.app.model.busy()); |
| 48 | assert_eq!(observed.borrow().jobs.len(), 2); |
| 49 | assert_eq!(screen.dialogs.0.borrow().requests.last().unwrap().purpose, Purpose::RetryGzip); |
| 50 | let saved = output.join("사용자 이름.txt"); |
| 51 | screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![saved.clone()])); |
| 52 | screen.click("다른 이름으로 저장"); |
| 53 | screen.settle(); |
| 54 | assert_eq!(fs::read(saved).unwrap(), b"Zipelo real worker flow\n"); |
| 55 | assert_eq!(fs::read(existing).unwrap(), b"preserve"); |
| 56 | assert_eq!(fs::read(&archive).unwrap(), original); |
| 57 | assert!(matches!( |
| 58 | observed.borrow().starts.last(), |
| 59 | Some(Start::Extract { destination, gzip_output_name: Some(name), .. }) |
| 60 | if destination == &output && name == "사용자 이름.txt" |
| 61 | )); |
| 62 | assert_reaped(&observed); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | #[test] |
| 67 | fn mixed_case_zip_names_open_and_extract_through_native_dialog_responses() { |
| 68 | use zipelo_ui_memory_app::archive_dialog::Purpose; |
| 69 | for name in ["sample.ZIP", "sample.Zip", "sample.zIp"] { |
| 70 | let scratch = Scratch::new(); |
| 71 | let archive = native_fixture(&scratch, "sample.zip", name); |
| 72 | let original = fs::read(&archive).unwrap(); |
| 73 | let output = make_directory(&scratch.path("output")); |
| 74 | let (factory, observed) = observed_factory(); |
| 75 | let mut screen = Screen::new(factory); |
| 76 | screen.dialogs.0.borrow_mut().answers.push_back(Some(vec![archive.clone()])); |
| 77 | screen.click("열기"); |
| 78 | screen.settle(); |
| 79 | assert_eq!(screen.dialogs.0.borrow().requests[0].purpose, Purpose::Open); |
| 80 | assert_eq!(screen.app.model.list_id.as_ref().unwrap().format, Format::Zip); |
| 81 | screen.extract(&output); |
| 82 | assert_eq!(fs::read(output.join("content.txt")).unwrap(), b"Zipelo real worker flow\n"); |
| 83 | assert_eq!(fs::read(archive).unwrap(), original); |
| 84 | assert_reaped(&observed); |
| 85 | } |
| 86 | } |