| 1 | use super::*; |
| 2 | use std::{ |
| 3 | collections::BTreeSet, |
| 4 | fs, |
| 5 | sync::atomic::{AtomicU64, Ordering}, |
| 6 | }; |
| 7 | use zipelo_ui_memory_app::archive_present::*; |
| 8 | |
| 9 | fn terminal() -> Terminal { |
| 10 | Terminal { |
| 11 | outcome: Outcome::Failed, |
| 12 | error: Some(ErrorCode::Io), |
| 13 | publication: Publication::Partial, |
| 14 | created_count: 1, |
| 15 | retained_partial_count: 0, |
| 16 | durability: Durability::Synced, |
| 17 | cleanup: Cleanup::Complete, |
| 18 | } |
| 19 | } |
| 20 | fn targets() -> BTreeSet<String> { |
| 21 | ["one.txt".into(), "two.txt".into()].into_iter().collect() |
| 22 | } |
| 23 | |
| 24 | #[test] |
| 25 | fn partial_extraction_requires_matching_file_reports() { |
| 26 | let t = terminal(); |
| 27 | assert_eq!( |
| 28 | warnings( |
| 29 | Some(&t), |
| 30 | true, |
| 31 | Some(&targets()), |
| 32 | &BTreeSet::new(), |
| 33 | &[("one.txt".into(), Disposition::Created)] |
| 34 | ), |
| 35 | vec![PARTIAL] |
| 36 | ); |
| 37 | } |
| 38 | #[test] |
| 39 | fn all_saved_with_temporary_leftover_is_not_partial_extraction() { |
| 40 | let mut t = terminal(); |
| 41 | t.retained_partial_count = 1; |
| 42 | t.cleanup = Cleanup::Failed; |
| 43 | let files = ["one.txt".into()].into_iter().collect(); |
| 44 | assert_eq!( |
| 45 | warnings( |
| 46 | Some(&t), |
| 47 | true, |
| 48 | Some(&files), |
| 49 | &BTreeSet::new(), |
| 50 | &[ |
| 51 | ("one.txt".into(), Disposition::Created), |
| 52 | ("temp".into(), Disposition::PartialRetained) |
| 53 | ] |
| 54 | ), |
| 55 | vec![LEFTOVERS] |
| 56 | ); |
| 57 | } |
| 58 | #[test] |
| 59 | fn leftover_without_file_reports_and_commit_uncertainty_are_unknown() { |
| 60 | let mut t = terminal(); |
| 61 | t.created_count = 0; |
| 62 | t.retained_partial_count = 1; |
| 63 | for outputs in [ |
| 64 | vec![("temp".into(), Disposition::PartialRetained)], |
| 65 | vec![("one.txt".into(), Disposition::CommitUncertain)], |
| 66 | ] { |
| 67 | assert!( |
| 68 | warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &outputs) |
| 69 | .contains(&UNCERTAIN) |
| 70 | ); |
| 71 | assert!( |
| 72 | !warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &outputs) |
| 73 | .contains(&PARTIAL) |
| 74 | ); |
| 75 | } |
| 76 | } |
| 77 | #[test] |
| 78 | fn synchronization_and_cleanup_warnings_are_both_visible() { |
| 79 | let mut t = terminal(); |
| 80 | t.created_count = 0; |
| 81 | t.durability = Durability::Unconfirmed; |
| 82 | t.cleanup = Cleanup::Failed; |
| 83 | let result = warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &[]); |
| 84 | assert!(result.contains(&SYNC_WARNING)); |
| 85 | assert!(result.contains(&CLEANUP_WARNING)); |
| 86 | } |
| 87 | #[test] |
| 88 | fn missing_terminal_exit_or_contradictory_reports_never_claim_unsaved() { |
| 89 | let mut t = terminal(); |
| 90 | t.publication = Publication::None; |
| 91 | t.created_count = 0; |
| 92 | assert!(definitely_unsaved(Some(&t), true, &[])); |
| 93 | assert!(!definitely_unsaved(None, true, &[])); |
| 94 | assert!(!definitely_unsaved(Some(&t), false, &[])); |
| 95 | let reports = [("one.txt".into(), Disposition::Created)]; |
| 96 | assert!(!definitely_unsaved(Some(&t), true, &reports)); |
| 97 | assert!( |
| 98 | warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &reports).contains(&UNCERTAIN) |
| 99 | ); |
| 100 | } |
| 101 | #[test] |
| 102 | fn unsafe_path_and_conflict_preserve_result_classification() { |
| 103 | for code in [ErrorCode::UnsafePath, ErrorCode::Conflict] { |
| 104 | let mut t = terminal(); |
| 105 | t.error = Some(code); |
| 106 | assert_eq!( |
| 107 | warnings( |
| 108 | Some(&t), |
| 109 | true, |
| 110 | Some(&targets()), |
| 111 | &BTreeSet::new(), |
| 112 | &[("one.txt".into(), Disposition::Created)] |
| 113 | ), |
| 114 | vec![PARTIAL] |
| 115 | ); |
| 116 | t.publication = Publication::Uncertain; |
| 117 | assert!( |
| 118 | warnings(Some(&t), true, Some(&targets()), &BTreeSet::new(), &[]).contains(&UNCERTAIN) |
| 119 | ); |
| 120 | t.publication = Publication::None; |
| 121 | t.created_count = 0; |
| 122 | assert!(definitely_unsaved(Some(&t), true, &[])); |
| 123 | } |
| 124 | } |
| 125 | #[test] |
| 126 | fn every_error_and_stage_has_user_facing_text() { |
| 127 | for code in [ |
| 128 | ErrorCode::Integrity, |
| 129 | ErrorCode::UnsupportedFormat, |
| 130 | ErrorCode::UnsupportedFeature, |
| 131 | ErrorCode::WrongPassword, |
| 132 | ErrorCode::UnsafePath, |
| 133 | ErrorCode::Conflict, |
| 134 | ErrorCode::Limit, |
| 135 | ErrorCode::Io, |
| 136 | ErrorCode::DiskFull, |
| 137 | ErrorCode::Protocol, |
| 138 | ErrorCode::Internal, |
| 139 | ErrorCode::SourceChanged, |
| 140 | ErrorCode::InvalidRequest, |
| 141 | ] { |
| 142 | assert!(!error_text(code).is_empty()); |
| 143 | assert!(!error_text(code).contains("작업자")); |
| 144 | } |
| 145 | assert_eq!(error_text(ErrorCode::Protocol), INTERNAL); |
| 146 | assert_eq!(error_text(ErrorCode::Internal), INTERNAL); |
| 147 | assert_eq!(progress_text(Stage::Decode, true), "압축하는 중"); |
| 148 | assert_eq!(progress_text(Stage::Decode, false), "압축을 푸는 중"); |
| 149 | } |
| 150 | #[test] |
| 151 | fn file_targets_follow_requested_ids_without_expanding_directories() { |
| 152 | let entries = vec![ |
| 153 | Entry { |
| 154 | id: 0, |
| 155 | name: "docs".into(), |
| 156 | kind: Kind::Directory, |
| 157 | bytes: None, |
| 158 | packed: None, |
| 159 | encrypted: false, |
| 160 | }, |
| 161 | Entry { |
| 162 | id: 1, |
| 163 | name: "docs/one.txt".into(), |
| 164 | kind: Kind::File, |
| 165 | bytes: None, |
| 166 | packed: None, |
| 167 | encrypted: false, |
| 168 | }, |
| 169 | Entry { |
| 170 | id: 2, |
| 171 | name: "docs-old/two.txt".into(), |
| 172 | kind: Kind::File, |
| 173 | bytes: None, |
| 174 | packed: None, |
| 175 | encrypted: false, |
| 176 | }, |
| 177 | ]; |
| 178 | assert_eq!( |
| 179 | target_files(&entries, &Selection::EntryIds(vec![0]), None), |
| 180 | Some(BTreeSet::new()) |
| 181 | ); |
| 182 | assert_eq!( |
| 183 | target_files(&entries, &Selection::EntryIds(vec![0, 2]), None), |
| 184 | Some(["docs-old/two.txt".into()].into_iter().collect()) |
| 185 | ); |
| 186 | assert_eq!( |
| 187 | target_files(&entries, &Selection::EntryIds(vec![1]), None), |
| 188 | Some(["docs/one.txt".into()].into_iter().collect()) |
| 189 | ); |
| 190 | assert_eq!( |
| 191 | target_files(&entries, &Selection::All, None), |
| 192 | Some( |
| 193 | ["docs/one.txt".into(), "docs-old/two.txt".into()] |
| 194 | .into_iter() |
| 195 | .collect() |
| 196 | ) |
| 197 | ); |
| 198 | } |
| 199 | |
| 200 | #[test] |
| 201 | fn directory_reports_allow_empty_and_mixed_archives_without_hiding_unknown_outputs() { |
| 202 | let directories = ["parent".into(), "parent/empty".into()] |
| 203 | .into_iter() |
| 204 | .collect(); |
| 205 | let empty = BTreeSet::new(); |
| 206 | let mut t = terminal(); |
| 207 | t.outcome = Outcome::Completed; |
| 208 | t.error = None; |
| 209 | t.publication = Publication::Complete; |
| 210 | t.created_count = 2; |
| 211 | let reports = [ |
| 212 | ("parent".into(), Disposition::Created), |
| 213 | ("parent/empty".into(), Disposition::Created), |
| 214 | ]; |
| 215 | assert!(warnings(Some(&t), true, Some(&empty), &directories, &reports).is_empty()); |
| 216 | t.created_count = 0; |
| 217 | assert!(warnings(Some(&t), true, Some(&empty), &directories, &[]).is_empty()); |
| 218 | let files = ["parent/file.txt".into()].into_iter().collect(); |
| 219 | t.created_count = 2; |
| 220 | let reports = [ |
| 221 | ("parent".into(), Disposition::Created), |
| 222 | ("parent/file.txt".into(), Disposition::Created), |
| 223 | ]; |
| 224 | assert!(warnings(Some(&t), true, Some(&files), &directories, &reports).is_empty()); |
| 225 | t.created_count = 1; |
| 226 | assert!( |
| 227 | warnings( |
| 228 | Some(&t), |
| 229 | true, |
| 230 | Some(&files), |
| 231 | &directories, |
| 232 | &[("parent".into(), Disposition::Created)] |
| 233 | ) |
| 234 | .contains(&UNCERTAIN) |
| 235 | ); |
| 236 | assert!( |
| 237 | warnings( |
| 238 | Some(&t), |
| 239 | true, |
| 240 | Some(&empty), |
| 241 | &directories, |
| 242 | &[("unknown".into(), Disposition::Created)] |
| 243 | ) |
| 244 | .contains(&UNCERTAIN) |
| 245 | ); |
| 246 | t.publication = Publication::Uncertain; |
| 247 | assert!( |
| 248 | warnings( |
| 249 | Some(&t), |
| 250 | true, |
| 251 | Some(&empty), |
| 252 | &directories, |
| 253 | &[("parent".into(), Disposition::CommitUncertain)] |
| 254 | ) |
| 255 | .contains(&UNCERTAIN) |
| 256 | ); |
| 257 | } |
| 258 | |
| 259 | #[test] |
| 260 | fn directory_targets_include_selected_members_and_implicit_parents() { |
| 261 | let entries = [ |
| 262 | Entry { |
| 263 | id: 0, |
| 264 | name: "top".into(), |
| 265 | kind: Kind::Directory, |
| 266 | bytes: None, |
| 267 | packed: None, |
| 268 | encrypted: false, |
| 269 | }, |
| 270 | Entry { |
| 271 | id: 1, |
| 272 | name: "top/empty".into(), |
| 273 | kind: Kind::Directory, |
| 274 | bytes: None, |
| 275 | packed: None, |
| 276 | encrypted: false, |
| 277 | }, |
| 278 | Entry { |
| 279 | id: 2, |
| 280 | name: "top/nested/file.txt".into(), |
| 281 | kind: Kind::File, |
| 282 | bytes: None, |
| 283 | packed: None, |
| 284 | encrypted: false, |
| 285 | }, |
| 286 | Entry { |
| 287 | id: 3, |
| 288 | name: "other/empty".into(), |
| 289 | kind: Kind::Directory, |
| 290 | bytes: None, |
| 291 | packed: None, |
| 292 | encrypted: false, |
| 293 | }, |
| 294 | ]; |
| 295 | assert_eq!( |
| 296 | target_directories(&entries, &Selection::EntryIds(vec![0])), |
| 297 | ["top".into()].into_iter().collect() |
| 298 | ); |
| 299 | assert_eq!( |
| 300 | target_directories(&entries, &Selection::EntryIds(vec![2])), |
| 301 | ["top".into(), "top/nested".into()].into_iter().collect() |
| 302 | ); |
| 303 | } |
| 304 | |
| 305 | #[test] |
| 306 | fn duplicate_names_prevent_file_completion_assumptions() { |
| 307 | let entry = Entry { |
| 308 | id: 0, |
| 309 | name: "same.txt".into(), |
| 310 | kind: Kind::File, |
| 311 | bytes: None, |
| 312 | packed: None, |
| 313 | encrypted: false, |
| 314 | }; |
| 315 | assert!(target_files(&[entry.clone(), entry], &Selection::All, None).is_none()); |
| 316 | assert_eq!( |
| 317 | warnings(Some(&terminal()), true, None, &BTreeSet::new(), &[]), |
| 318 | vec![UNCERTAIN] |
| 319 | ); |
| 320 | } |
| 321 | #[test] |
| 322 | fn default_names_and_middle_truncation_preserve_unicode() { |
| 323 | assert_eq!(default_destination(&path("자료.tar.gz")), path("자료")); |
| 324 | assert_eq!(default_destination(&path("자료.zip")), path("자료")); |
| 325 | assert_eq!(middle_text("가나다라마바사아자차", 7), "가나다…아자차"); |
| 326 | assert_eq!(bytes_text(21), "21 B"); |
| 327 | } |
| 328 | |
| 329 | static SCRATCH_ID: AtomicU64 = AtomicU64::new(0); |
| 330 | pub(super) struct Folder(pub(super) PathBuf); |
| 331 | impl Folder { |
| 332 | pub(super) fn new() -> Self { |
| 333 | let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../tests/rust-app-ui/runs"); |
| 334 | fs::create_dir_all(&root).unwrap(); |
| 335 | let path = root.join(format!( |
| 336 | "presentation-{}-{}", |
| 337 | std::process::id(), |
| 338 | SCRATCH_ID.fetch_add(1, Ordering::Relaxed) |
| 339 | )); |
| 340 | fs::create_dir(&path).unwrap(); |
| 341 | Self(path.canonicalize().unwrap()) |
| 342 | } |
| 343 | } |
| 344 | impl Drop for Folder { |
| 345 | fn drop(&mut self) { |
| 346 | fs::remove_dir_all(&self.0).unwrap(); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | #[test] |
| 351 | fn automatic_destination_creation_and_failure_are_distinct() { |
| 352 | let scratch = Folder::new(); |
| 353 | let output = scratch.0.join("output"); |
| 354 | assert!(prepare_destination(&output, true).unwrap()); |
| 355 | assert!(!prepare_destination(&output, true).unwrap()); |
| 356 | assert!(prepare_destination(&scratch.0.join("missing/child"), true).is_err()); |
| 357 | assert!(prepare_destination(&scratch.0.join("chosen-missing"), false).is_err()); |
| 358 | let file = scratch.0.join("file"); |
| 359 | fs::write(&file, "existing").unwrap(); |
| 360 | assert!(prepare_destination(&file, true).is_err()); |
| 361 | assert_eq!(fs::read_to_string(file).unwrap(), "existing"); |
| 362 | } |
| 363 | #[test] |
| 364 | fn only_new_empty_output_is_removed_and_nonempty_is_preserved() { |
| 365 | let scratch = Folder::new(); |
| 366 | let empty = scratch.0.join("empty"); |
| 367 | assert!(prepare_destination(&empty, true).unwrap()); |
| 368 | remove_owned_empty(&empty); |
| 369 | assert!(!empty.exists()); |
| 370 | let nonempty = scratch.0.join("nonempty"); |
| 371 | assert!(prepare_destination(&nonempty, true).unwrap()); |
| 372 | fs::write(nonempty.join("existing"), "keep").unwrap(); |
| 373 | remove_owned_empty(&nonempty); |
| 374 | assert_eq!( |
| 375 | fs::read_to_string(nonempty.join("existing")).unwrap(), |
| 376 | "keep" |
| 377 | ); |
| 378 | assert!(!prepare_destination(&scratch.0, false).unwrap()); |
| 379 | assert!(scratch.0.is_dir()); |
| 380 | } |
| 381 | #[cfg(unix)] |
| 382 | #[test] |
| 383 | fn browser_and_output_do_not_follow_symbolic_links() { |
| 384 | let scratch = Folder::new(); |
| 385 | let link = scratch.0.join("link"); |
| 386 | std::os::unix::fs::symlink(&scratch.0, &link).unwrap(); |
| 387 | let rows = directory_entries(&scratch.0).unwrap(); |
| 388 | assert!(rows.iter().any(|entry| entry.link && entry.path == link)); |
| 389 | assert!(directory_entries(&link).is_err()); |
| 390 | assert!(prepare_destination(&link, true).is_err()); |
| 391 | } |
| 392 | |
| 393 | #[cfg(feature = "ui")] |
| 394 | mod widgets { |
| 395 | use super::*; |
| 396 | use eframe::egui::{self, epaint::Shape}; |
| 397 | use zipelo_ui_memory_app::{ |
| 398 | archive_picker::{Choice, Picker, Purpose}, |
| 399 | archive_screen::ArchiveApp, |
| 400 | }; |
| 401 | |
| 402 | fn labels(shapes: &[egui::epaint::ClippedShape]) -> Vec<(String, egui::Pos2)> { |
| 403 | fn walk(shape: &Shape, result: &mut Vec<(String, egui::Pos2)>) { |
| 404 | match shape { |
| 405 | Shape::Text(text) => result.push(( |
| 406 | text.galley.job.text.clone(), |
| 407 | text.pos + text.galley.rect.size() / 2.0, |
| 408 | )), |
| 409 | Shape::Vec(shapes) => { |
| 410 | for shape in shapes { |
| 411 | walk(shape, result); |
| 412 | } |
| 413 | } |
| 414 | _ => {} |
| 415 | } |
| 416 | } |
| 417 | let mut result = Vec::new(); |
| 418 | for shape in shapes { |
| 419 | walk(&shape.shape, &mut result); |
| 420 | } |
| 421 | result |
| 422 | } |
| 423 | fn render( |
| 424 | ctx: &egui::Context, |
| 425 | app: &mut ArchiveApp, |
| 426 | events: Vec<egui::Event>, |
| 427 | ) -> Vec<(String, egui::Pos2)> { |
| 428 | let mut output = ctx.run_ui( |
| 429 | egui::RawInput { |
| 430 | screen_rect: Some(egui::Rect::from_min_size( |
| 431 | egui::Pos2::ZERO, |
| 432 | egui::vec2(760.0, 540.0), |
| 433 | )), |
| 434 | events, |
| 435 | ..Default::default() |
| 436 | }, |
| 437 | |ui| app.show(ui), |
| 438 | ); |
| 439 | output.textures_delta.clear(); |
| 440 | labels(&output.shapes) |
| 441 | } |
| 442 | fn click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 443 | render(ctx, app, vec![]); |
| 444 | let point = render(ctx, app, vec![]) |
| 445 | .into_iter() |
| 446 | .filter(|(text, _)| text == label) |
| 447 | .max_by(|a, b| a.1.y.total_cmp(&b.1.y)) |
| 448 | .unwrap_or_else(|| panic!("항목 없음: {label}")) |
| 449 | .1; |
| 450 | for pressed in [true, false] { |
| 451 | render( |
| 452 | ctx, |
| 453 | app, |
| 454 | vec![ |
| 455 | egui::Event::PointerMoved(point), |
| 456 | egui::Event::PointerButton { |
| 457 | pos: point, |
| 458 | button: egui::PointerButton::Primary, |
| 459 | pressed, |
| 460 | modifiers: egui::Modifiers::NONE, |
| 461 | }, |
| 462 | ], |
| 463 | ); |
| 464 | } |
| 465 | } |
| 466 | fn key(key: egui::Key) -> egui::Event { |
| 467 | egui::Event::Key { |
| 468 | key, |
| 469 | physical_key: None, |
| 470 | pressed: true, |
| 471 | repeat: false, |
| 472 | modifiers: egui::Modifiers::NONE, |
| 473 | } |
| 474 | } |
| 475 | fn text(ctx: &egui::Context, app: &mut ArchiveApp, id: &str, value: &str) { |
| 476 | ctx.memory_mut(|memory| memory.request_focus(egui::Id::unique(id))); |
| 477 | render( |
| 478 | ctx, |
| 479 | app, |
| 480 | vec![ |
| 481 | egui::Event::Key { |
| 482 | key: egui::Key::A, |
| 483 | physical_key: None, |
| 484 | pressed: true, |
| 485 | repeat: false, |
| 486 | modifiers: egui::Modifiers::COMMAND, |
| 487 | }, |
| 488 | egui::Event::Text(value.into()), |
| 489 | ], |
| 490 | ); |
| 491 | } |
| 492 | fn loaded(scratch: &Folder, factory: &FakeFactory) -> ArchiveApp { |
| 493 | let mut app = ArchiveApp::new( |
| 494 | Box::new(factory.clone()), |
| 495 | Some(scratch.0.join("sample.zip")), |
| 496 | false, |
| 497 | ); |
| 498 | pump(&mut app.model); |
| 499 | app |
| 500 | } |
| 501 | #[test] |
| 502 | fn empty_view_has_no_internal_status_and_keyboard_focus_is_reachable() { |
| 503 | let ctx = egui::Context::default(); |
| 504 | let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false); |
| 505 | render(&ctx, &mut app, vec![]); |
| 506 | let shown = render(&ctx, &mut app, vec![key(egui::Key::Tab)]); |
| 507 | assert!( |
| 508 | shown |
| 509 | .iter() |
| 510 | .any(|(text, _)| text == "압축파일을 여기에 끌어 놓으세요") |
| 511 | ); |
| 512 | assert!(!shown.iter().any(|(text, _)| text.contains("게시") |
| 513 | || text.contains("동기화") |
| 514 | || text.contains("시험 모드"))); |
| 515 | assert!(ctx.memory(|memory| memory.focused().is_some())); |
| 516 | app.model.request_close(); |
| 517 | let closing = render(&ctx, &mut app, vec![]); |
| 518 | assert!(!closing.iter().any(|(text, _)| text == UNCERTAIN)); |
| 519 | } |
| 520 | #[test] |
| 521 | fn empty_selection_and_empty_zip_sources_do_not_start_work() { |
| 522 | let scratch = Folder::new(); |
| 523 | let ctx = egui::Context::default(); |
| 524 | let factory = FakeFactory::default(); |
| 525 | let mut app = loaded(&scratch, &factory); |
| 526 | render(&ctx, &mut app, vec![]); |
| 527 | click(&ctx, &mut app, "선택한 항목만 풀기"); |
| 528 | click(&ctx, &mut app, "풀기"); |
| 529 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 530 | click(&ctx, &mut app, "ZIP 만들기"); |
| 531 | click(&ctx, &mut app, "만들기"); |
| 532 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 533 | assert!(!app.model.busy()); |
| 534 | } |
| 535 | #[test] |
| 536 | fn destination_failure_sends_no_request_and_explains_folder_change() { |
| 537 | let scratch = Folder::new(); |
| 538 | let factory = FakeFactory::default(); |
| 539 | let mut app = loaded(&scratch, &factory); |
| 540 | let file = scratch.0.join("existing.txt"); |
| 541 | fs::write(&file, "preserve").unwrap(); |
| 542 | app.choose_destination(file.clone()); |
| 543 | assert!(!app.begin_extract()); |
| 544 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 545 | let ctx = egui::Context::default(); |
| 546 | render(&ctx, &mut app, vec![]); |
| 547 | assert!( |
| 548 | render(&ctx, &mut app, vec![]) |
| 549 | .iter() |
| 550 | .any(|(text, _)| text == FOLDER_ERROR) |
| 551 | ); |
| 552 | assert_eq!(fs::read_to_string(file).unwrap(), "preserve"); |
| 553 | } |
| 554 | #[test] |
| 555 | fn cancelling_removes_only_automatically_created_empty_folder() { |
| 556 | for case in ["automatic-empty", "automatic-nonempty", "chosen-empty"] { |
| 557 | let scratch = Folder::new(); |
| 558 | let factory = FakeFactory::default(); |
| 559 | let mut app = loaded(&scratch, &factory); |
| 560 | factory.state.borrow_mut().manual = true; |
| 561 | let destination = if case == "chosen-empty" { |
| 562 | let path = scratch.0.join("chosen"); |
| 563 | fs::create_dir(&path).unwrap(); |
| 564 | app.choose_destination(path.clone()); |
| 565 | path |
| 566 | } else { |
| 567 | scratch.0.join("sample") |
| 568 | }; |
| 569 | assert!(app.begin_extract()); |
| 570 | if case == "automatic-nonempty" { |
| 571 | fs::write(destination.join("preserve"), "keep").unwrap(); |
| 572 | } |
| 573 | { |
| 574 | let mut state = factory.state.borrow_mut(); |
| 575 | state.frame(Event::Accepted { encryption: true }); |
| 576 | state.finish(Outcome::Cancelled, Publication::None); |
| 577 | } |
| 578 | let ctx = egui::Context::default(); |
| 579 | for _ in 0..30 { |
| 580 | render(&ctx, &mut app, vec![]); |
| 581 | } |
| 582 | assert!(!app.model.busy()); |
| 583 | assert_eq!(destination.exists(), case != "automatic-empty"); |
| 584 | } |
| 585 | } |
| 586 | #[test] |
| 587 | fn password_confirmation_requires_match_and_enter_sends_once() { |
| 588 | let scratch = Folder::new(); |
| 589 | let factory = FakeFactory::manual(); |
| 590 | let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 591 | assert!(app.model.begin( |
| 592 | Start::CreateZip { |
| 593 | sources: vec![(scratch.0.join("source"), "source".into())], |
| 594 | output_file: scratch.0.join("new.zip"), |
| 595 | method: Method::Deflate, |
| 596 | aes256: true |
| 597 | }, |
| 598 | &mut factory.clone() |
| 599 | )); |
| 600 | { |
| 601 | let mut state = factory.state.borrow_mut(); |
| 602 | state.frame(Event::Accepted { encryption: true }); |
| 603 | state.frame(Event::PasswordRequired { |
| 604 | challenge_id: 17, |
| 605 | attempt: 1, |
| 606 | encrypt: true, |
| 607 | }); |
| 608 | } |
| 609 | let ctx = egui::Context::default(); |
| 610 | for _ in 0..12 { |
| 611 | render(&ctx, &mut app, vec![]); |
| 612 | } |
| 613 | assert_eq!( |
| 614 | ctx.memory(|memory| memory.focused()), |
| 615 | Some(egui::Id::unique("archive-password-input")) |
| 616 | ); |
| 617 | text(&ctx, &mut app, "archive-password-input", "fixture-secret"); |
| 618 | text(&ctx, &mut app, "archive-password-confirm", "different"); |
| 619 | click(&ctx, &mut app, "확인"); |
| 620 | assert!(!factory.state.borrow().password_seen); |
| 621 | text(&ctx, &mut app, "archive-password-confirm", "fixture-secret"); |
| 622 | let shown = render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 623 | assert!( |
| 624 | !shown |
| 625 | .iter() |
| 626 | .any(|(text, _)| text.contains("fixture-secret")) |
| 627 | ); |
| 628 | assert!(factory.state.borrow().password_seen); |
| 629 | assert!(app.model.challenge.is_none()); |
| 630 | } |
| 631 | #[test] |
| 632 | fn picker_fits_minimum_window_and_opens_selected_file_with_enter() { |
| 633 | let scratch = Folder::new(); |
| 634 | let file = scratch.0.join("one.zip"); |
| 635 | fs::write(&file, "fixture").unwrap(); |
| 636 | let ctx = egui::Context::default(); |
| 637 | let mut picker = Picker::new(Purpose::Open, &scratch.0); |
| 638 | let mut result = None; |
| 639 | let mut draw = |events| { |
| 640 | let mut output = ctx.run_ui( |
| 641 | egui::RawInput { |
| 642 | screen_rect: Some(egui::Rect::from_min_size( |
| 643 | egui::Pos2::ZERO, |
| 644 | egui::vec2(760.0, 540.0), |
| 645 | )), |
| 646 | events, |
| 647 | ..Default::default() |
| 648 | }, |
| 649 | |_ui| { |
| 650 | result = picker.show(&ctx); |
| 651 | }, |
| 652 | ); |
| 653 | output.textures_delta.clear(); |
| 654 | labels(&output.shapes) |
| 655 | }; |
| 656 | draw(vec![]); |
| 657 | let shown = draw(vec![]); |
| 658 | for label in ["파일 열기", "열기", "홈"] { |
| 659 | let (_, point) = shown.iter().find(|(text, _)| text == label).unwrap(); |
| 660 | assert!((0.0..540.0).contains(&point.y), "{label}: {point:?}"); |
| 661 | } |
| 662 | let cancel = shown.iter().find(|(text, _)| text == "취소").unwrap().1; |
| 663 | let confirm = shown.iter().find(|(text, _)| text == "열기").unwrap().1; |
| 664 | assert!(cancel.x < confirm.x); |
| 665 | let point = shown.iter().find(|(text, _)| text == "one.zip").unwrap().1; |
| 666 | for pressed in [true, false] { |
| 667 | draw(vec![ |
| 668 | egui::Event::PointerMoved(point), |
| 669 | egui::Event::PointerButton { |
| 670 | pos: point, |
| 671 | button: egui::PointerButton::Primary, |
| 672 | pressed, |
| 673 | modifiers: egui::Modifiers::NONE, |
| 674 | }, |
| 675 | ]); |
| 676 | } |
| 677 | for _ in 0..40 { |
| 678 | if ctx |
| 679 | .memory(|memory| memory.focused()) |
| 680 | .and_then(|id| ctx.read_response(id)) |
| 681 | .is_some_and(|response| response.rect.contains(confirm)) |
| 682 | { |
| 683 | break; |
| 684 | } |
| 685 | draw(vec![key(egui::Key::Tab)]); |
| 686 | let mut released = key(egui::Key::Tab); |
| 687 | if let egui::Event::Key { pressed, .. } = &mut released { |
| 688 | *pressed = false; |
| 689 | } |
| 690 | draw(vec![released]); |
| 691 | } |
| 692 | assert!( |
| 693 | ctx.memory(|memory| memory.focused()) |
| 694 | .and_then(|id| ctx.read_response(id)) |
| 695 | .is_some_and(|response| response.rect.contains(confirm)) |
| 696 | ); |
| 697 | draw(vec![key(egui::Key::Enter)]); |
| 698 | assert!(matches!(result, Some(Choice::Paths(ref paths)) if paths == &vec![file])); |
| 699 | } |
| 700 | |
| 701 | fn focus_zip_action_with_tab(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 702 | render(ctx, app, vec![]); |
| 703 | let shown = render(ctx, app, vec![]); |
| 704 | let point = shown.iter().find(|(text, _)| text == label).unwrap().1; |
| 705 | for _ in 0..80 { |
| 706 | if ctx |
| 707 | .memory(|memory| memory.focused()) |
| 708 | .and_then(|id| ctx.read_response(id)) |
| 709 | .is_some_and(|response| response.rect.contains(point)) |
| 710 | { |
| 711 | return; |
| 712 | } |
| 713 | render(ctx, app, vec![key(egui::Key::Tab)]); |
| 714 | let mut released = key(egui::Key::Tab); |
| 715 | if let egui::Event::Key { pressed, .. } = &mut released { |
| 716 | *pressed = false; |
| 717 | } |
| 718 | render(ctx, app, vec![released]); |
| 719 | } |
| 720 | panic!("키보드 초점 없음: {label}"); |
| 721 | } |
| 722 | |
| 723 | #[test] |
| 724 | fn keyboard_cancel_and_escape_never_start_zip_creation() { |
| 725 | for escape in [false, true] { |
| 726 | let scratch = Folder::new(); |
| 727 | let factory = FakeFactory::manual(); |
| 728 | let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 729 | let source = scratch.0.join("source.txt"); |
| 730 | fs::write(&source, "fixture").unwrap(); |
| 731 | app.add_sources(vec![source]); |
| 732 | let ctx = egui::Context::default(); |
| 733 | focus_zip_action_with_tab(&ctx, &mut app, if escape { "만들기" } else { "취소" }); |
| 734 | let mut events = vec![key(egui::Key::Enter)]; |
| 735 | if escape { |
| 736 | events.push(key(egui::Key::Escape)); |
| 737 | } |
| 738 | render(&ctx, &mut app, events); |
| 739 | let shown = render(&ctx, &mut app, vec![]); |
| 740 | assert!(factory.state.borrow().starts.is_empty()); |
| 741 | assert!(!app.model.busy()); |
| 742 | assert!(!scratch.0.join("source.zip").exists()); |
| 743 | assert_eq!( |
| 744 | shown |
| 745 | .iter() |
| 746 | .filter(|(text, _)| text == "ZIP 만들기") |
| 747 | .count(), |
| 748 | 1 |
| 749 | ); |
| 750 | } |
| 751 | } |
| 752 | |
| 753 | #[test] |
| 754 | fn zip_creation_enter_only_activates_focused_make_button() { |
| 755 | for make_button in [false, true] { |
| 756 | let scratch = Folder::new(); |
| 757 | let factory = FakeFactory::manual(); |
| 758 | let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 759 | let source = scratch.0.join("source.txt"); |
| 760 | fs::write(&source, "fixture").unwrap(); |
| 761 | app.add_sources(vec![source.clone()]); |
| 762 | let ctx = egui::Context::default(); |
| 763 | render(&ctx, &mut app, vec![]); |
| 764 | if make_button { |
| 765 | focus_zip_action_with_tab(&ctx, &mut app, "만들기"); |
| 766 | } else { |
| 767 | ctx.memory_mut(|memory| memory.request_focus(egui::Id::unique("zip-name"))); |
| 768 | render(&ctx, &mut app, vec![]); |
| 769 | } |
| 770 | render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 771 | render(&ctx, &mut app, vec![]); |
| 772 | let state = factory.state.borrow(); |
| 773 | assert_eq!(state.starts.len(), usize::from(make_button)); |
| 774 | if make_button { |
| 775 | assert!( |
| 776 | matches!(state.starts.last(), Some(Start::CreateZip {sources, output_file, ..}) |
| 777 | if sources == &vec![(source, "source.txt".into())] |
| 778 | && output_file == &scratch.0.join("source.zip")) |
| 779 | ); |
| 780 | } |
| 781 | } |
| 782 | } |
| 783 | |
| 784 | fn policy_render( |
| 785 | ctx: &egui::Context, |
| 786 | app: &mut ArchiveApp, |
| 787 | events: Vec<egui::Event>, |
| 788 | ) -> Vec<(String, egui::Pos2)> { |
| 789 | let mut output = ctx.run_ui( |
| 790 | egui::RawInput { |
| 791 | screen_rect: Some(egui::Rect::from_min_size( |
| 792 | egui::Pos2::ZERO, |
| 793 | egui::vec2(1060.0, 720.0), |
| 794 | )), |
| 795 | events, |
| 796 | ..Default::default() |
| 797 | }, |
| 798 | |ui| app.show(ui), |
| 799 | ); |
| 800 | output.textures_delta.clear(); |
| 801 | labels(&output.shapes) |
| 802 | } |
| 803 | |
| 804 | fn policy_focus(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 805 | policy_render(ctx, app, vec![]); |
| 806 | for _ in 0..100 { |
| 807 | let shown = policy_render(ctx, app, vec![]); |
| 808 | let point = shown |
| 809 | .iter() |
| 810 | .rev() |
| 811 | .find(|(text, _)| text == label) |
| 812 | .unwrap_or_else(|| panic!("표시 없음: {label}")) |
| 813 | .1; |
| 814 | if ctx |
| 815 | .memory(|memory| memory.focused()) |
| 816 | .and_then(|id| ctx.read_response(id)) |
| 817 | .is_some_and(|response| response.rect.contains(point)) |
| 818 | { |
| 819 | return; |
| 820 | } |
| 821 | policy_render(ctx, app, vec![key(egui::Key::Tab)]); |
| 822 | let mut released = key(egui::Key::Tab); |
| 823 | if let egui::Event::Key { pressed, .. } = &mut released { |
| 824 | *pressed = false; |
| 825 | } |
| 826 | policy_render(ctx, app, vec![released]); |
| 827 | } |
| 828 | panic!("키보드 초점 없음: {label}"); |
| 829 | } |
| 830 | |
| 831 | fn policy_click(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 832 | policy_render(ctx, app, vec![]); |
| 833 | let point = policy_render(ctx, app, vec![]) |
| 834 | .iter() |
| 835 | .rev() |
| 836 | .find(|(text, _)| text == label) |
| 837 | .unwrap() |
| 838 | .1; |
| 839 | for pressed in [true, false] { |
| 840 | policy_render( |
| 841 | ctx, |
| 842 | app, |
| 843 | vec![ |
| 844 | egui::Event::PointerMoved(point), |
| 845 | egui::Event::PointerButton { |
| 846 | pos: point, |
| 847 | button: egui::PointerButton::Primary, |
| 848 | pressed, |
| 849 | modifiers: egui::Modifiers::NONE, |
| 850 | }, |
| 851 | ], |
| 852 | ); |
| 853 | } |
| 854 | } |
| 855 | |
| 856 | #[test] |
| 857 | fn secondary_button_enter_matrix_never_starts_creation_or_extraction() { |
| 858 | let cases = vec![ |
| 859 | ("archive", "ZIP 만들기"), |
| 860 | ("archive", "다른 파일"), |
| 861 | ("archive", "폴더 바꾸기"), |
| 862 | ("archive", "선택한 항목만 풀기"), |
| 863 | ("create", "파일 추가"), |
| 864 | ("create", "폴더 추가"), |
| 865 | ("create", "빼기"), |
| 866 | ("create", "폴더 바꾸기"), |
| 867 | ("create", "암호로 보호하기"), |
| 868 | ("create", "자세한 설정"), |
| 869 | ("create", "취소"), |
| 870 | ("result", "자세히 보기"), |
| 871 | ("result", "자세히 닫기"), |
| 872 | ("result", "확인"), |
| 873 | ("progress", "취소"), |
| 874 | ("close-confirm", "계속 작업"), |
| 875 | ("close-confirm", "취소하고 닫기"), |
| 876 | ("close-wait", "닫기 취소"), |
| 877 | ("close-review", "계속 작업"), |
| 878 | ("close-review", "닫기"), |
| 879 | ]; |
| 880 | let mut cases = cases |
| 881 | .into_iter() |
| 882 | .map(|(state, label)| (state, label.to_owned())) |
| 883 | .collect::<Vec<_>>(); |
| 884 | for state in [ |
| 885 | "picker-open", |
| 886 | "picker-destination", |
| 887 | "picker-files", |
| 888 | "picker-folder", |
| 889 | "picker-zip", |
| 890 | ] { |
| 891 | for (label, _) in shortcuts() { |
| 892 | cases.push((state, label)); |
| 893 | } |
| 894 | for label in ["상위 폴더", "취소", "breadcrumb"] { |
| 895 | cases.push((state, label.to_owned())); |
| 896 | } |
| 897 | } |
| 898 | for (state, label) in cases { |
| 899 | let scratch = Folder::new(); |
| 900 | let factory = FakeFactory::default(); |
| 901 | let ctx = egui::Context::default(); |
| 902 | let creating = matches!( |
| 903 | state, |
| 904 | "create" | "picker-files" | "picker-folder" | "picker-zip" |
| 905 | ); |
| 906 | let mut app = ArchiveApp::new( |
| 907 | Box::new(factory.clone()), |
| 908 | (!creating).then(|| scratch.0.join("sample.zip")), |
| 909 | false, |
| 910 | ); |
| 911 | if !creating { |
| 912 | pump(&mut app.model); |
| 913 | } |
| 914 | factory.state.borrow_mut().manual = true; |
| 915 | if creating { |
| 916 | let source = scratch.0.join("source.txt"); |
| 917 | fs::write(&source, "fixture").unwrap(); |
| 918 | app.add_sources(vec![source]); |
| 919 | } |
| 920 | if matches!( |
| 921 | state, |
| 922 | "progress" | "result" | "close-confirm" | "close-wait" | "close-review" |
| 923 | ) { |
| 924 | assert!(app.begin_extract()); |
| 925 | if matches!(state, "result" | "close-review") { |
| 926 | let mut worker = factory.state.borrow_mut(); |
| 927 | worker.frame(Event::Accepted { encryption: false }); |
| 928 | worker.finish(Outcome::Failed, Publication::None); |
| 929 | drop(worker); |
| 930 | for _ in 0..30 { |
| 931 | policy_render(&ctx, &mut app, vec![]); |
| 932 | } |
| 933 | } |
| 934 | if state.starts_with("close-") { |
| 935 | app.model.request_close(); |
| 936 | if state == "close-wait" { |
| 937 | app.model.confirm_close(); |
| 938 | } |
| 939 | } |
| 940 | } |
| 941 | match state { |
| 942 | "picker-open" => policy_click(&ctx, &mut app, "다른 파일"), |
| 943 | "picker-destination" | "picker-zip" => policy_click(&ctx, &mut app, "폴더 바꾸기"), |
| 944 | "picker-files" => policy_click(&ctx, &mut app, "파일 추가"), |
| 945 | "picker-folder" => policy_click(&ctx, &mut app, "폴더 추가"), |
| 946 | _ => {} |
| 947 | } |
| 948 | if state == "result" && label == "자세히 닫기" { |
| 949 | policy_click(&ctx, &mut app, "자세히 보기"); |
| 950 | } |
| 951 | let before = factory.state.borrow().starts.len(); |
| 952 | let label = if label == "breadcrumb" { |
| 953 | scratch |
| 954 | .0 |
| 955 | .ancestors() |
| 956 | .last() |
| 957 | .unwrap() |
| 958 | .as_os_str() |
| 959 | .to_str() |
| 960 | .unwrap() |
| 961 | } else { |
| 962 | label.as_str() |
| 963 | }; |
| 964 | policy_focus(&ctx, &mut app, label); |
| 965 | policy_render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 966 | policy_render(&ctx, &mut app, vec![]); |
| 967 | assert_eq!( |
| 968 | factory.state.borrow().starts.len(), |
| 969 | before, |
| 970 | "{state}: {label}" |
| 971 | ); |
| 972 | } |
| 973 | let scratch = Folder::new(); |
| 974 | let factory = FakeFactory::default(); |
| 975 | let mut app = loaded(&scratch, &factory); |
| 976 | factory.state.borrow_mut().manual = true; |
| 977 | let ctx = egui::Context::default(); |
| 978 | policy_focus(&ctx, &mut app, "풀기"); |
| 979 | policy_render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 980 | assert!(matches!( |
| 981 | factory.state.borrow().starts.last(), |
| 982 | Some(Start::Extract { .. }) |
| 983 | )); |
| 984 | assert_eq!(factory.state.borrow().starts.len(), 2); |
| 985 | } |
| 986 | |
| 987 | #[test] |
| 988 | fn password_secondary_enter_does_not_submit_valid_input() { |
| 989 | for encrypt in [false, true] { |
| 990 | for label in ["보기", "숨기기", "취소"] { |
| 991 | let scratch = Folder::new(); |
| 992 | let factory = FakeFactory::manual(); |
| 993 | let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 994 | assert!(app.model.begin( |
| 995 | Start::CreateZip { |
| 996 | sources: vec![(scratch.0.join("source"), "source".into())], |
| 997 | output_file: scratch.0.join("output.zip"), |
| 998 | method: Method::Deflate, |
| 999 | aes256: true |
| 1000 | }, |
| 1001 | &mut factory.clone() |
| 1002 | )); |
| 1003 | { |
| 1004 | let mut worker = factory.state.borrow_mut(); |
| 1005 | worker.frame(Event::Accepted { encryption: true }); |
| 1006 | worker.frame(Event::PasswordRequired { |
| 1007 | challenge_id: 17, |
| 1008 | attempt: 1, |
| 1009 | encrypt, |
| 1010 | }); |
| 1011 | } |
| 1012 | let ctx = egui::Context::default(); |
| 1013 | for _ in 0..12 { |
| 1014 | policy_render(&ctx, &mut app, vec![]); |
| 1015 | } |
| 1016 | text(&ctx, &mut app, "archive-password-input", "fixture-secret"); |
| 1017 | if encrypt { |
| 1018 | text(&ctx, &mut app, "archive-password-confirm", "fixture-secret"); |
| 1019 | } |
| 1020 | if label == "숨기기" { |
| 1021 | policy_click(&ctx, &mut app, "보기"); |
| 1022 | } |
| 1023 | policy_focus(&ctx, &mut app, label); |
| 1024 | policy_render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 1025 | assert!(!factory.state.borrow().password_seen, "{label}"); |
| 1026 | assert_eq!(factory.state.borrow().starts.len(), 1); |
| 1027 | } |
| 1028 | } |
| 1029 | } |
| 1030 | |
| 1031 | #[test] |
| 1032 | fn directory_only_extraction_displays_success() { |
| 1033 | let scratch = Folder::new(); |
| 1034 | let factory = FakeFactory::default(); |
| 1035 | let mut app = loaded(&scratch, &factory); |
| 1036 | app.model.entries = vec![Entry { |
| 1037 | id: 0, |
| 1038 | name: "empty".into(), |
| 1039 | kind: Kind::Directory, |
| 1040 | bytes: Some(0), |
| 1041 | packed: None, |
| 1042 | encrypted: false, |
| 1043 | }]; |
| 1044 | factory.state.borrow_mut().manual = true; |
| 1045 | assert!(app.begin_extract()); |
| 1046 | { |
| 1047 | let mut worker = factory.state.borrow_mut(); |
| 1048 | worker.frame(Event::Accepted { encryption: false }); |
| 1049 | worker.frame(Event::Output { |
| 1050 | entry_id: None, |
| 1051 | relative_name: "empty".into(), |
| 1052 | disposition: Disposition::Created, |
| 1053 | }); |
| 1054 | worker.finish(Outcome::Completed, Publication::Complete); |
| 1055 | } |
| 1056 | let ctx = egui::Context::default(); |
| 1057 | for _ in 0..30 { |
| 1058 | policy_render(&ctx, &mut app, vec![]); |
| 1059 | } |
| 1060 | let shown = policy_render(&ctx, &mut app, vec![]); |
| 1061 | assert!(shown.iter().any(|(text, _)| text == "압축을 풀었습니다")); |
| 1062 | assert!(!shown.iter().any(|(text, _)| text == UNCERTAIN)); |
| 1063 | } |
| 1064 | |
| 1065 | #[test] |
| 1066 | fn completed_results_keep_folder_action_and_distinguish_durability() { |
| 1067 | for creating in [false, true] { |
| 1068 | for durability in [ |
| 1069 | Durability::Synced, |
| 1070 | Durability::Unconfirmed, |
| 1071 | Durability::Failed, |
| 1072 | ] { |
| 1073 | let scratch = Folder::new(); |
| 1074 | let factory = FakeFactory::default(); |
| 1075 | let mut app = loaded(&scratch, &factory); |
| 1076 | factory.state.borrow_mut().manual = true; |
| 1077 | let ctx = egui::Context::default(); |
| 1078 | let name = if creating { |
| 1079 | let source = scratch.0.join("source.txt"); |
| 1080 | fs::write(&source, b"source").unwrap(); |
| 1081 | app.add_sources(vec![source]); |
| 1082 | policy_render(&ctx, &mut app, vec![]); |
| 1083 | policy_click(&ctx, &mut app, "만들기"); |
| 1084 | match factory.state.borrow().starts.last().unwrap() { |
| 1085 | Start::CreateZip { output_file, .. } => output_file |
| 1086 | .file_name() |
| 1087 | .unwrap() |
| 1088 | .to_str() |
| 1089 | .unwrap() |
| 1090 | .to_owned(), |
| 1091 | _ => panic!("생성 요청 누락"), |
| 1092 | } |
| 1093 | } else { |
| 1094 | assert!(app.begin_extract()); |
| 1095 | "읽어주세요.txt".to_owned() |
| 1096 | }; |
| 1097 | { |
| 1098 | let mut worker = factory.state.borrow_mut(); |
| 1099 | worker.frame(Event::Accepted { encryption: false }); |
| 1100 | worker.frame(Event::Output { |
| 1101 | entry_id: None, |
| 1102 | relative_name: name, |
| 1103 | disposition: Disposition::Created, |
| 1104 | }); |
| 1105 | worker.finish(Outcome::Completed, Publication::Complete); |
| 1106 | for event in &mut worker.queue { |
| 1107 | if let HostEvent::Frame { |
| 1108 | event: Event::Terminal(terminal), |
| 1109 | .. |
| 1110 | } = event |
| 1111 | { |
| 1112 | terminal.durability = durability; |
| 1113 | } |
| 1114 | } |
| 1115 | } |
| 1116 | for _ in 0..30 { |
| 1117 | policy_render(&ctx, &mut app, vec![]); |
| 1118 | } |
| 1119 | let shown = policy_render(&ctx, &mut app, vec![]); |
| 1120 | let title = if creating { |
| 1121 | "ZIP 파일을 만들었습니다" |
| 1122 | } else { |
| 1123 | "압축을 풀었습니다" |
| 1124 | }; |
| 1125 | assert!( |
| 1126 | shown.iter().any(|(text, _)| text == title), |
| 1127 | "{durability:?}: {shown:?}" |
| 1128 | ); |
| 1129 | assert!(shown.iter().any(|(text, _)| text == "폴더 열기")); |
| 1130 | assert!(!shown.iter().any(|(text, _)| text == "다시 시도")); |
| 1131 | assert!(!shown.iter().any(|(text, _)| text == SYNC_WARNING)); |
| 1132 | assert_eq!( |
| 1133 | shown.iter().any(|(text, _)| text == "파일을 디스크에 완전히 저장하지 못했습니다. 풀 위치 폴더를 확인하세요."), |
| 1134 | durability == Durability::Failed |
| 1135 | ); |
| 1136 | policy_click(&ctx, &mut app, "자세히 보기"); |
| 1137 | let details = policy_render(&ctx, &mut app, vec![]); |
| 1138 | assert_eq!( |
| 1139 | details.iter().any(|(text, _)| text == SYNC_WARNING), |
| 1140 | durability == Durability::Unconfirmed |
| 1141 | ); |
| 1142 | policy_click(&ctx, &mut app, "자세히 닫기"); |
| 1143 | let closed = policy_render(&ctx, &mut app, vec![]); |
| 1144 | assert!(!closed.iter().any(|(text, _)| text == SYNC_WARNING)); |
| 1145 | assert_eq!( |
| 1146 | closed.iter().any(|(text, _)| text == "파일을 디스크에 완전히 저장하지 못했습니다. 풀 위치 폴더를 확인하세요."), |
| 1147 | durability == Durability::Failed |
| 1148 | ); |
| 1149 | assert!(closed.iter().any(|(text, _)| text == "폴더 열기")); |
| 1150 | } |
| 1151 | } |
| 1152 | } |
| 1153 | |
| 1154 | #[test] |
| 1155 | fn durability_warning_visibility_matches_completed_failed_and_partial_results() { |
| 1156 | for (outcome, publication, saved, expected_files) in [ |
| 1157 | (Outcome::Completed, Publication::Complete, 1, 1), |
| 1158 | (Outcome::Failed, Publication::None, 0, 1), |
| 1159 | (Outcome::Failed, Publication::Partial, 1, 2), |
| 1160 | ] { |
| 1161 | for durability in [ |
| 1162 | Durability::Synced, |
| 1163 | Durability::Unconfirmed, |
| 1164 | Durability::Failed, |
| 1165 | ] { |
| 1166 | let scratch = Folder::new(); |
| 1167 | let factory = FakeFactory::default(); |
| 1168 | let mut app = loaded(&scratch, &factory); |
| 1169 | app.model.entries = (0..expected_files) |
| 1170 | .map(|id| Entry { |
| 1171 | id, |
| 1172 | name: format!("{id}.txt"), |
| 1173 | kind: Kind::File, |
| 1174 | bytes: Some(1), |
| 1175 | packed: None, |
| 1176 | encrypted: false, |
| 1177 | }) |
| 1178 | .collect(); |
| 1179 | factory.state.borrow_mut().manual = true; |
| 1180 | assert!(app.begin_extract()); |
| 1181 | { |
| 1182 | let mut worker = factory.state.borrow_mut(); |
| 1183 | worker.frame(Event::Accepted { encryption: false }); |
| 1184 | if saved > 0 { |
| 1185 | worker.frame(Event::Output { |
| 1186 | entry_id: Some(0), |
| 1187 | relative_name: "0.txt".into(), |
| 1188 | disposition: Disposition::Created, |
| 1189 | }); |
| 1190 | } |
| 1191 | worker.finish(outcome, publication); |
| 1192 | for event in &mut worker.queue { |
| 1193 | if let HostEvent::Frame { |
| 1194 | event: Event::Terminal(terminal), |
| 1195 | .. |
| 1196 | } = event |
| 1197 | { |
| 1198 | terminal.created_count = saved; |
| 1199 | terminal.durability = durability; |
| 1200 | terminal.error = (outcome == Outcome::Failed).then_some(ErrorCode::Io); |
| 1201 | } |
| 1202 | } |
| 1203 | } |
| 1204 | let ctx = egui::Context::default(); |
| 1205 | for _ in 0..30 { |
| 1206 | policy_render(&ctx, &mut app, vec![]); |
| 1207 | } |
| 1208 | let completed = outcome == Outcome::Completed; |
| 1209 | let shown = policy_render(&ctx, &mut app, vec![]); |
| 1210 | let warning = match durability { |
| 1211 | Durability::Unconfirmed => Some(SYNC_WARNING), |
| 1212 | Durability::Failed => Some( |
| 1213 | "파일을 디스크에 완전히 저장하지 못했습니다. 풀 위치 폴더를 확인하세요.", |
| 1214 | ), |
| 1215 | _ => None, |
| 1216 | }; |
| 1217 | let visible = |
| 1218 | warning.is_some() && !(completed && durability == Durability::Unconfirmed); |
| 1219 | assert_eq!( |
| 1220 | shown.iter().any(|(text, _)| Some(text.as_str()) == warning), |
| 1221 | visible, |
| 1222 | "{outcome:?}/{publication:?}: {shown:?}" |
| 1223 | ); |
| 1224 | assert_eq!(shown.iter().any(|(text, _)| text == "폴더 열기"), completed); |
| 1225 | assert_eq!( |
| 1226 | shown.iter().any(|(text, _)| text == "압축을 풀었습니다"), |
| 1227 | completed |
| 1228 | ); |
| 1229 | assert_eq!( |
| 1230 | shown |
| 1231 | .iter() |
| 1232 | .any(|(text, _)| text == "압축을 풀지 못했습니다"), |
| 1233 | !completed |
| 1234 | ); |
| 1235 | assert_eq!( |
| 1236 | shown.iter().any(|(text, _)| text == PARTIAL), |
| 1237 | publication == Publication::Partial |
| 1238 | ); |
| 1239 | policy_click(&ctx, &mut app, "자세히 보기"); |
| 1240 | let details = policy_render(&ctx, &mut app, vec![]); |
| 1241 | assert_eq!( |
| 1242 | details |
| 1243 | .iter() |
| 1244 | .filter(|(text, _)| Some(text.as_str()) == warning) |
| 1245 | .count(), |
| 1246 | usize::from(warning.is_some()), |
| 1247 | "{outcome:?}/{publication:?}: {details:?}" |
| 1248 | ); |
| 1249 | policy_click(&ctx, &mut app, "자세히 닫기"); |
| 1250 | let closed = policy_render(&ctx, &mut app, vec![]); |
| 1251 | assert_eq!( |
| 1252 | closed |
| 1253 | .iter() |
| 1254 | .any(|(text, _)| Some(text.as_str()) == warning), |
| 1255 | visible |
| 1256 | ); |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | |
| 1261 | fn picker_frame( |
| 1262 | ctx: &egui::Context, |
| 1263 | picker: &mut Picker, |
| 1264 | events: Vec<egui::Event>, |
| 1265 | ) -> (Vec<(String, egui::Pos2)>, Option<Choice>) { |
| 1266 | let mut choice = None; |
| 1267 | let mut output = ctx.run_ui( |
| 1268 | egui::RawInput { |
| 1269 | screen_rect: Some(egui::Rect::from_min_size( |
| 1270 | egui::Pos2::ZERO, |
| 1271 | egui::vec2(760.0, 540.0), |
| 1272 | )), |
| 1273 | events, |
| 1274 | ..Default::default() |
| 1275 | }, |
| 1276 | |_ui| choice = picker.show(ctx), |
| 1277 | ); |
| 1278 | output.textures_delta.clear(); |
| 1279 | (labels(&output.shapes), choice) |
| 1280 | } |
| 1281 | |
| 1282 | fn keyboard_activate_picker( |
| 1283 | ctx: &egui::Context, |
| 1284 | picker: &mut Picker, |
| 1285 | label: &str, |
| 1286 | ) -> Option<Choice> { |
| 1287 | picker_frame(ctx, picker, vec![]); |
| 1288 | let shown = picker_frame(ctx, picker, vec![]).0; |
| 1289 | let point = shown.iter().find(|(text, _)| text == label).unwrap().1; |
| 1290 | for _ in 0..80 { |
| 1291 | let focused = ctx.memory(|memory| memory.focused()); |
| 1292 | if focused |
| 1293 | .and_then(|id| ctx.read_response(id)) |
| 1294 | .is_some_and(|response| response.rect.contains(point)) |
| 1295 | { |
| 1296 | let choice = picker_frame(ctx, picker, vec![key(egui::Key::Enter)]).1; |
| 1297 | let mut released = key(egui::Key::Enter); |
| 1298 | if let egui::Event::Key { pressed, .. } = &mut released { |
| 1299 | *pressed = false; |
| 1300 | } |
| 1301 | picker_frame(ctx, picker, vec![released]); |
| 1302 | return choice; |
| 1303 | } |
| 1304 | picker_frame(ctx, picker, vec![key(egui::Key::Tab)]); |
| 1305 | let mut released = key(egui::Key::Tab); |
| 1306 | if let egui::Event::Key { pressed, .. } = &mut released { |
| 1307 | *pressed = false; |
| 1308 | } |
| 1309 | picker_frame(ctx, picker, vec![released]); |
| 1310 | } |
| 1311 | panic!("키보드 초점 없음: {label}"); |
| 1312 | } |
| 1313 | |
| 1314 | #[test] |
| 1315 | fn keyboard_file_pickers_enter_child_before_confirming_file() { |
| 1316 | for purpose in [Purpose::Open, Purpose::Files] { |
| 1317 | let scratch = Folder::new(); |
| 1318 | let child = scratch.0.join("child"); |
| 1319 | fs::create_dir(&child).unwrap(); |
| 1320 | let file = child.join("inside.zip"); |
| 1321 | fs::write(&file, "fixture").unwrap(); |
| 1322 | let ctx = egui::Context::default(); |
| 1323 | let mut picker = Picker::new(purpose, &scratch.0); |
| 1324 | assert!(keyboard_activate_picker(&ctx, &mut picker, "child").is_none()); |
| 1325 | assert!( |
| 1326 | picker_frame(&ctx, &mut picker, vec![]) |
| 1327 | .0 |
| 1328 | .iter() |
| 1329 | .any(|(text, _)| text == "inside.zip") |
| 1330 | ); |
| 1331 | let choice = keyboard_activate_picker(&ctx, &mut picker, "inside.zip"); |
| 1332 | assert!(matches!(choice, Some(Choice::Paths(paths)) if paths == vec![file])); |
| 1333 | } |
| 1334 | } |
| 1335 | |
| 1336 | #[test] |
| 1337 | fn keyboard_folder_pickers_navigate_before_explicit_folder_confirmation() { |
| 1338 | for purpose in [ |
| 1339 | Purpose::Destination, |
| 1340 | Purpose::Retry, |
| 1341 | Purpose::Folder, |
| 1342 | Purpose::ZipFolder, |
| 1343 | ] { |
| 1344 | let scratch = Folder::new(); |
| 1345 | let child = scratch.0.join("child"); |
| 1346 | fs::create_dir(&child).unwrap(); |
| 1347 | fs::write(child.join("inside.zip"), "fixture").unwrap(); |
| 1348 | let ctx = egui::Context::default(); |
| 1349 | let mut picker = Picker::new(purpose, &scratch.0); |
| 1350 | assert!(keyboard_activate_picker(&ctx, &mut picker, "child").is_none()); |
| 1351 | assert!( |
| 1352 | picker_frame(&ctx, &mut picker, vec![]) |
| 1353 | .0 |
| 1354 | .iter() |
| 1355 | .any(|(text, _)| text == "inside.zip") |
| 1356 | ); |
| 1357 | let choice = keyboard_activate_picker(&ctx, &mut picker, "이 폴더 선택"); |
| 1358 | assert!(matches!(choice, Some(Choice::Paths(paths)) if paths == vec![child])); |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | #[test] |
| 1363 | fn changed_zip_sources_retry_creation_with_or_without_open_archive() { |
| 1364 | for opened in [false, true] { |
| 1365 | let scratch = Folder::new(); |
| 1366 | let factory = FakeFactory::default(); |
| 1367 | let mut app = ArchiveApp::new( |
| 1368 | Box::new(factory.clone()), |
| 1369 | opened.then(|| scratch.0.join("unrelated.zip")), |
| 1370 | false, |
| 1371 | ); |
| 1372 | if opened { |
| 1373 | pump(&mut app.model); |
| 1374 | } |
| 1375 | factory.state.borrow_mut().manual = true; |
| 1376 | let source = scratch.0.join("source.txt"); |
| 1377 | fs::write(&source, "fixture").unwrap(); |
| 1378 | app.add_sources(vec![source]); |
| 1379 | let ctx = egui::Context::default(); |
| 1380 | click(&ctx, &mut app, "만들기"); |
| 1381 | assert!(app.model.busy()); |
| 1382 | let request = factory.state.borrow().starts.last().unwrap().clone(); |
| 1383 | assert!(matches!(request, Start::CreateZip { .. })); |
| 1384 | { |
| 1385 | let mut state = factory.state.borrow_mut(); |
| 1386 | state.frame(Event::Accepted { encryption: false }); |
| 1387 | state.frame(Event::Terminal(Terminal { |
| 1388 | outcome: Outcome::Failed, |
| 1389 | error: Some(ErrorCode::SourceChanged), |
| 1390 | publication: Publication::None, |
| 1391 | created_count: 0, |
| 1392 | retained_partial_count: 0, |
| 1393 | durability: Durability::NotApplicable, |
| 1394 | cleanup: Cleanup::Complete, |
| 1395 | })); |
| 1396 | state.queue.extend([ |
| 1397 | HostEvent::StdoutEof, |
| 1398 | HostEvent::StderrEof, |
| 1399 | HostEvent::Exited { success: true }, |
| 1400 | ]); |
| 1401 | } |
| 1402 | for _ in 0..30 { |
| 1403 | render(&ctx, &mut app, vec![]); |
| 1404 | } |
| 1405 | assert!(!app.model.busy()); |
| 1406 | let shown = render(&ctx, &mut app, vec![]); |
| 1407 | assert!( |
| 1408 | shown |
| 1409 | .iter() |
| 1410 | .any(|(text, _)| text.contains("묶을 파일이 바뀌었습니다")) |
| 1411 | ); |
| 1412 | assert!(!shown.iter().any(|(text, _)| text == "압축파일 다시 열기")); |
| 1413 | let count = factory.state.borrow().starts.len(); |
| 1414 | click(&ctx, &mut app, "다시 만들기"); |
| 1415 | assert!(app.model.busy()); |
| 1416 | let state = factory.state.borrow(); |
| 1417 | assert_eq!(state.starts.len(), count + 1); |
| 1418 | assert_eq!(state.starts.last(), Some(&request)); |
| 1419 | } |
| 1420 | } |
| 1421 | } |
| 1422 | |
| 1423 | #[cfg(feature = "ui")] |
| 1424 | #[test] |
| 1425 | fn conflict_retry_waits_for_folder_choice_and_preserves_selection() { |
| 1426 | use eframe::egui; |
| 1427 | use zipelo_ui_memory_app::archive_screen::ArchiveApp; |
| 1428 | let scratch = Folder::new(); |
| 1429 | let factory = FakeFactory::default(); |
| 1430 | let mut app = ArchiveApp::new( |
| 1431 | Box::new(factory.clone()), |
| 1432 | Some(scratch.0.join("sample.zip")), |
| 1433 | false, |
| 1434 | ); |
| 1435 | pump(&mut app.model); |
| 1436 | app.model.selected.insert(0); |
| 1437 | factory.state.borrow_mut().manual = true; |
| 1438 | let ctx = egui::Context::default(); |
| 1439 | let render = |app: &mut ArchiveApp, events| { |
| 1440 | let mut output = ctx.run_ui( |
| 1441 | egui::RawInput { |
| 1442 | screen_rect: Some(egui::Rect::from_min_size( |
| 1443 | egui::Pos2::ZERO, |
| 1444 | egui::vec2(760.0, 540.0), |
| 1445 | )), |
| 1446 | events, |
| 1447 | ..Default::default() |
| 1448 | }, |
| 1449 | |ui| app.show(ui), |
| 1450 | ); |
| 1451 | output.textures_delta.clear(); |
| 1452 | fn walk(shape: &egui::epaint::Shape, labels: &mut Vec<(String, egui::Pos2)>) { |
| 1453 | match shape { |
| 1454 | egui::epaint::Shape::Text(text) => labels.push(( |
| 1455 | text.galley.job.text.clone(), |
| 1456 | text.pos + text.galley.rect.size() / 2.0, |
| 1457 | )), |
| 1458 | egui::epaint::Shape::Vec(shapes) => { |
| 1459 | for shape in shapes { |
| 1460 | walk(shape, labels); |
| 1461 | } |
| 1462 | } |
| 1463 | _ => {} |
| 1464 | } |
| 1465 | } |
| 1466 | let mut labels = Vec::new(); |
| 1467 | for shape in &output.shapes { |
| 1468 | walk(&shape.shape, &mut labels); |
| 1469 | } |
| 1470 | labels |
| 1471 | }; |
| 1472 | let click = |app: &mut ArchiveApp, text: &str| { |
| 1473 | render(app, vec![]); |
| 1474 | let point = render(app, vec![]) |
| 1475 | .into_iter() |
| 1476 | .filter(|(value, _)| value == text) |
| 1477 | .max_by(|a, b| a.1.y.total_cmp(&b.1.y)) |
| 1478 | .unwrap_or_else(|| panic!("항목 없음: {text}")) |
| 1479 | .1; |
| 1480 | for pressed in [true, false] { |
| 1481 | render( |
| 1482 | app, |
| 1483 | vec![ |
| 1484 | egui::Event::PointerMoved(point), |
| 1485 | egui::Event::PointerButton { |
| 1486 | pos: point, |
| 1487 | button: egui::PointerButton::Primary, |
| 1488 | pressed, |
| 1489 | modifiers: egui::Modifiers::NONE, |
| 1490 | }, |
| 1491 | ], |
| 1492 | ); |
| 1493 | } |
| 1494 | }; |
| 1495 | render(&mut app, vec![]); |
| 1496 | click(&mut app, "선택한 항목만 풀기"); |
| 1497 | assert!(app.begin_extract()); |
| 1498 | let old = scratch.0.join("sample"); |
| 1499 | fs::write(old.join("existing"), "preserve").unwrap(); |
| 1500 | let chosen = scratch.0.join("chosen"); |
| 1501 | fs::create_dir(&chosen).unwrap(); |
| 1502 | { |
| 1503 | let mut state = factory.state.borrow_mut(); |
| 1504 | state.frame(Event::Accepted { encryption: true }); |
| 1505 | state.frame(Event::Terminal(Terminal { |
| 1506 | outcome: Outcome::Failed, |
| 1507 | error: Some(ErrorCode::Conflict), |
| 1508 | publication: Publication::None, |
| 1509 | created_count: 0, |
| 1510 | retained_partial_count: 0, |
| 1511 | durability: Durability::NotApplicable, |
| 1512 | cleanup: Cleanup::Complete, |
| 1513 | })); |
| 1514 | state.queue.extend([ |
| 1515 | HostEvent::StdoutEof, |
| 1516 | HostEvent::StderrEof, |
| 1517 | HostEvent::Exited { success: true }, |
| 1518 | ]); |
| 1519 | } |
| 1520 | for _ in 0..30 { |
| 1521 | render(&mut app, vec![]); |
| 1522 | } |
| 1523 | assert_eq!(factory.state.borrow().starts.len(), 2); |
| 1524 | click(&mut app, "다른 폴더에 풀기"); |
| 1525 | assert_eq!(factory.state.borrow().starts.len(), 2); |
| 1526 | click(&mut app, "상위 폴더"); |
| 1527 | click(&mut app, "chosen"); |
| 1528 | click(&mut app, "이 폴더 선택"); |
| 1529 | assert!(matches!(factory.state.borrow().starts.last(), |
| 1530 | Some(Start::Extract { destination, selection: Selection::EntryIds(ids), .. }) |
| 1531 | if destination == &chosen && ids == &vec![0])); |
| 1532 | assert_eq!( |
| 1533 | fs::read_to_string(old.join("existing")).unwrap(), |
| 1534 | "preserve" |
| 1535 | ); |
| 1536 | } |
| 1537 | |
| 1538 | #[cfg(feature = "ui")] |
| 1539 | #[test] |
| 1540 | fn create_dialog_keeps_title_and_actions_visible_after_resize() { |
| 1541 | use eframe::egui::{self, epaint::Shape}; |
| 1542 | use zipelo_ui_memory_app::archive_screen::ArchiveApp; |
| 1543 | let scratch = Folder::new(); |
| 1544 | let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false); |
| 1545 | app.add_sources(vec![scratch.0.join("one.txt"), scratch.0.join("photos")]); |
| 1546 | let ctx = egui::Context::default(); |
| 1547 | for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] { |
| 1548 | let mut texts = Vec::new(); |
| 1549 | for _ in 0..8 { |
| 1550 | let mut output = ctx.run_ui( |
| 1551 | egui::RawInput { |
| 1552 | screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)), |
| 1553 | ..Default::default() |
| 1554 | }, |
| 1555 | |ui| app.show(ui), |
| 1556 | ); |
| 1557 | output.textures_delta.clear(); |
| 1558 | fn walk(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) { |
| 1559 | match shape { |
| 1560 | Shape::Text(text) => output.push(( |
| 1561 | text.galley.job.text.clone(), |
| 1562 | text.pos + text.galley.rect.size() / 2.0, |
| 1563 | )), |
| 1564 | Shape::Vec(shapes) => { |
| 1565 | for shape in shapes { |
| 1566 | walk(shape, output); |
| 1567 | } |
| 1568 | } |
| 1569 | _ => {} |
| 1570 | } |
| 1571 | } |
| 1572 | texts.clear(); |
| 1573 | for shape in &output.shapes { |
| 1574 | walk(&shape.shape, &mut texts); |
| 1575 | } |
| 1576 | } |
| 1577 | for label in ["ZIP 만들기", "만들기", "취소"] { |
| 1578 | let positions = texts |
| 1579 | .iter() |
| 1580 | .filter(|(text, _)| text == label) |
| 1581 | .map(|(_, p)| p) |
| 1582 | .collect::<Vec<_>>(); |
| 1583 | assert!(!positions.is_empty(), "{label}"); |
| 1584 | assert!( |
| 1585 | positions.iter().all(|p| p.y >= 0.0 && p.y <= size.y), |
| 1586 | "{label}: {positions:?}" |
| 1587 | ); |
| 1588 | } |
| 1589 | } |
| 1590 | } |
| 1591 | #[test] |
| 1592 | fn folder_open_command_preserves_shell_characters_as_one_argument() { |
| 1593 | let path = path("한글 폴더 ; $(touch unexpected)"); |
| 1594 | let command = folder_command(&path); |
| 1595 | assert_eq!( |
| 1596 | command.get_program(), |
| 1597 | if cfg!(windows) { |
| 1598 | "explorer" |
| 1599 | } else { |
| 1600 | "xdg-open" |
| 1601 | } |
| 1602 | ); |
| 1603 | assert_eq!( |
| 1604 | command.get_args().collect::<Vec<_>>(), |
| 1605 | vec![path.as_os_str()] |
| 1606 | ); |
| 1607 | } |
| 1608 | |
| 1609 | #[test] |
| 1610 | fn late_cancel_and_terminal_wait_use_finishing_text() { |
| 1611 | let mut model = Model::default(); |
| 1612 | model.progress = Some((Stage::Decode, 1, Some(2), 0)); |
| 1613 | assert_eq!(activity_text(&model, false), "압축을 푸는 중"); |
| 1614 | model.cancel = Some(CancelStatus::Requested); |
| 1615 | assert_eq!(activity_text(&model, false), "취소하는 중..."); |
| 1616 | for state in [CancelStatus::TooLate, CancelStatus::Finished] { |
| 1617 | model.cancel = Some(state); |
| 1618 | assert_eq!(activity_text(&model, false), "마무리하는 중"); |
| 1619 | } |
| 1620 | model.cancel = Some(CancelStatus::Requested); |
| 1621 | model.terminal = Some(terminal()); |
| 1622 | assert_eq!(activity_text(&model, false), "마무리하는 중"); |
| 1623 | } |
| 1624 | #[test] |
| 1625 | fn client_protocol_errors_hide_internal_terms_but_preserve_exit_uncertainty() { |
| 1626 | for error in [ |
| 1627 | "작업 ID 한도에 도달했습니다", |
| 1628 | "작업자 응답 순서나 작업 ID가 일치하지 않습니다", |
| 1629 | "작업 승인 응답이 없습니다", |
| 1630 | "출력 보고 한도 초과", |
| 1631 | ] { |
| 1632 | assert_eq!(client_error_text(error), INTERNAL); |
| 1633 | } |
| 1634 | assert_eq!( |
| 1635 | client_error_text("작업자 종료 결과를 확인할 수 없습니다. 출력 상태를 확인하세요"), |
| 1636 | UNCONFIRMED_FINISH |
| 1637 | ); |
| 1638 | } |