team-ljyzipelo

공개
1,616줄58 KB
1use super::*;
2use std::{
3 collections::BTreeSet,
4 fs,
5 sync::atomic::{AtomicU64, Ordering},
6};
7use zipelo_ui_memory_app::archive_present::*;
8
9fn 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}
20fn targets() -> BTreeSet<String> {
21 ["one.txt".into(), "two.txt".into()].into_iter().collect()
22}
23
24#[test]
25fn 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]
39fn 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]
59fn 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]
78fn 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]
88fn 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]
102fn 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]
126fn 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]
151fn 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]
201fn 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]
260fn 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]
306fn 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]
322fn 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
329static SCRATCH_ID: AtomicU64 = AtomicU64::new(0);
330pub(super) struct Folder(pub(super) PathBuf);
331impl 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}
344impl Drop for Folder {
345 fn drop(&mut self) {
346 fs::remove_dir_all(&self.0).unwrap();
347 }
348}
349
350#[test]
351fn 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]
364fn 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]
383fn 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")]
394mod 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_show_durability_only_in_details() {
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!(
1131 !shown
1132 .iter()
1133 .any(|(text, _)| text == "다시 시도" || text == SYNC_WARNING)
1134 );
1135 policy_click(&ctx, &mut app, "자세히 보기");
1136 let details = policy_render(&ctx, &mut app, vec![]);
1137 assert_eq!(
1138 details.iter().any(|(text, _)| text == SYNC_WARNING),
1139 durability != Durability::Synced
1140 );
1141 policy_click(&ctx, &mut app, "자세히 닫기");
1142 let closed = policy_render(&ctx, &mut app, vec![]);
1143 assert!(!closed.iter().any(|(text, _)| text == SYNC_WARNING));
1144 assert!(closed.iter().any(|(text, _)| text == "폴더 열기"));
1145 }
1146 }
1147 }
1148
1149 #[test]
1150 fn durability_warning_visibility_matches_completed_failed_and_partial_results() {
1151 for (outcome, publication, saved, expected_files) in [
1152 (Outcome::Completed, Publication::Complete, 1, 1),
1153 (Outcome::Failed, Publication::None, 0, 1),
1154 (Outcome::Failed, Publication::Partial, 1, 2),
1155 ] {
1156 let scratch = Folder::new();
1157 let factory = FakeFactory::default();
1158 let mut app = loaded(&scratch, &factory);
1159 app.model.entries = (0..expected_files)
1160 .map(|id| Entry {
1161 id,
1162 name: format!("{id}.txt"),
1163 kind: Kind::File,
1164 bytes: Some(1),
1165 packed: None,
1166 encrypted: false,
1167 })
1168 .collect();
1169 factory.state.borrow_mut().manual = true;
1170 assert!(app.begin_extract());
1171 {
1172 let mut worker = factory.state.borrow_mut();
1173 worker.frame(Event::Accepted { encryption: false });
1174 if saved > 0 {
1175 worker.frame(Event::Output {
1176 entry_id: Some(0),
1177 relative_name: "0.txt".into(),
1178 disposition: Disposition::Created,
1179 });
1180 }
1181 worker.finish(outcome, publication);
1182 for event in &mut worker.queue {
1183 if let HostEvent::Frame {
1184 event: Event::Terminal(terminal),
1185 ..
1186 } = event
1187 {
1188 terminal.created_count = saved;
1189 terminal.durability = Durability::Unconfirmed;
1190 terminal.error = (outcome == Outcome::Failed).then_some(ErrorCode::Io);
1191 }
1192 }
1193 }
1194 let ctx = egui::Context::default();
1195 for _ in 0..30 {
1196 policy_render(&ctx, &mut app, vec![]);
1197 }
1198 let completed = outcome == Outcome::Completed;
1199 let shown = policy_render(&ctx, &mut app, vec![]);
1200 assert_eq!(
1201 shown.iter().any(|(text, _)| text == SYNC_WARNING),
1202 !completed,
1203 "{outcome:?}/{publication:?}: {shown:?}"
1204 );
1205 assert_eq!(shown.iter().any(|(text, _)| text == "폴더 열기"), completed);
1206 assert_eq!(
1207 shown.iter().any(|(text, _)| text == "압축을 풀었습니다"),
1208 completed
1209 );
1210 assert_eq!(
1211 shown
1212 .iter()
1213 .any(|(text, _)| text == "압축을 풀지 못했습니다"),
1214 !completed
1215 );
1216 assert_eq!(
1217 shown.iter().any(|(text, _)| text == PARTIAL),
1218 publication == Publication::Partial
1219 );
1220 policy_click(&ctx, &mut app, "자세히 보기");
1221 let details = policy_render(&ctx, &mut app, vec![]);
1222 assert_eq!(
1223 details
1224 .iter()
1225 .filter(|(text, _)| text == SYNC_WARNING)
1226 .count(),
1227 1,
1228 "{outcome:?}/{publication:?}: {details:?}"
1229 );
1230 policy_click(&ctx, &mut app, "자세히 닫기");
1231 let closed = policy_render(&ctx, &mut app, vec![]);
1232 assert_eq!(
1233 closed.iter().any(|(text, _)| text == SYNC_WARNING),
1234 !completed
1235 );
1236 }
1237 }
1238
1239 fn picker_frame(
1240 ctx: &egui::Context,
1241 picker: &mut Picker,
1242 events: Vec<egui::Event>,
1243 ) -> (Vec<(String, egui::Pos2)>, Option<Choice>) {
1244 let mut choice = None;
1245 let mut output = ctx.run_ui(
1246 egui::RawInput {
1247 screen_rect: Some(egui::Rect::from_min_size(
1248 egui::Pos2::ZERO,
1249 egui::vec2(760.0, 540.0),
1250 )),
1251 events,
1252 ..Default::default()
1253 },
1254 |_ui| choice = picker.show(ctx),
1255 );
1256 output.textures_delta.clear();
1257 (labels(&output.shapes), choice)
1258 }
1259
1260 fn keyboard_activate_picker(
1261 ctx: &egui::Context,
1262 picker: &mut Picker,
1263 label: &str,
1264 ) -> Option<Choice> {
1265 picker_frame(ctx, picker, vec![]);
1266 let shown = picker_frame(ctx, picker, vec![]).0;
1267 let point = shown.iter().find(|(text, _)| text == label).unwrap().1;
1268 for _ in 0..80 {
1269 let focused = ctx.memory(|memory| memory.focused());
1270 if focused
1271 .and_then(|id| ctx.read_response(id))
1272 .is_some_and(|response| response.rect.contains(point))
1273 {
1274 let choice = picker_frame(ctx, picker, vec![key(egui::Key::Enter)]).1;
1275 let mut released = key(egui::Key::Enter);
1276 if let egui::Event::Key { pressed, .. } = &mut released {
1277 *pressed = false;
1278 }
1279 picker_frame(ctx, picker, vec![released]);
1280 return choice;
1281 }
1282 picker_frame(ctx, picker, vec![key(egui::Key::Tab)]);
1283 let mut released = key(egui::Key::Tab);
1284 if let egui::Event::Key { pressed, .. } = &mut released {
1285 *pressed = false;
1286 }
1287 picker_frame(ctx, picker, vec![released]);
1288 }
1289 panic!("키보드 초점 없음: {label}");
1290 }
1291
1292 #[test]
1293 fn keyboard_file_pickers_enter_child_before_confirming_file() {
1294 for purpose in [Purpose::Open, Purpose::Files] {
1295 let scratch = Folder::new();
1296 let child = scratch.0.join("child");
1297 fs::create_dir(&child).unwrap();
1298 let file = child.join("inside.zip");
1299 fs::write(&file, "fixture").unwrap();
1300 let ctx = egui::Context::default();
1301 let mut picker = Picker::new(purpose, &scratch.0);
1302 assert!(keyboard_activate_picker(&ctx, &mut picker, "child").is_none());
1303 assert!(
1304 picker_frame(&ctx, &mut picker, vec![])
1305 .0
1306 .iter()
1307 .any(|(text, _)| text == "inside.zip")
1308 );
1309 let choice = keyboard_activate_picker(&ctx, &mut picker, "inside.zip");
1310 assert!(matches!(choice, Some(Choice::Paths(paths)) if paths == vec![file]));
1311 }
1312 }
1313
1314 #[test]
1315 fn keyboard_folder_pickers_navigate_before_explicit_folder_confirmation() {
1316 for purpose in [
1317 Purpose::Destination,
1318 Purpose::Retry,
1319 Purpose::Folder,
1320 Purpose::ZipFolder,
1321 ] {
1322 let scratch = Folder::new();
1323 let child = scratch.0.join("child");
1324 fs::create_dir(&child).unwrap();
1325 fs::write(child.join("inside.zip"), "fixture").unwrap();
1326 let ctx = egui::Context::default();
1327 let mut picker = Picker::new(purpose, &scratch.0);
1328 assert!(keyboard_activate_picker(&ctx, &mut picker, "child").is_none());
1329 assert!(
1330 picker_frame(&ctx, &mut picker, vec![])
1331 .0
1332 .iter()
1333 .any(|(text, _)| text == "inside.zip")
1334 );
1335 let choice = keyboard_activate_picker(&ctx, &mut picker, "이 폴더 선택");
1336 assert!(matches!(choice, Some(Choice::Paths(paths)) if paths == vec![child]));
1337 }
1338 }
1339
1340 #[test]
1341 fn changed_zip_sources_retry_creation_with_or_without_open_archive() {
1342 for opened in [false, true] {
1343 let scratch = Folder::new();
1344 let factory = FakeFactory::default();
1345 let mut app = ArchiveApp::new(
1346 Box::new(factory.clone()),
1347 opened.then(|| scratch.0.join("unrelated.zip")),
1348 false,
1349 );
1350 if opened {
1351 pump(&mut app.model);
1352 }
1353 factory.state.borrow_mut().manual = true;
1354 let source = scratch.0.join("source.txt");
1355 fs::write(&source, "fixture").unwrap();
1356 app.add_sources(vec![source]);
1357 let ctx = egui::Context::default();
1358 click(&ctx, &mut app, "만들기");
1359 assert!(app.model.busy());
1360 let request = factory.state.borrow().starts.last().unwrap().clone();
1361 assert!(matches!(request, Start::CreateZip { .. }));
1362 {
1363 let mut state = factory.state.borrow_mut();
1364 state.frame(Event::Accepted { encryption: false });
1365 state.frame(Event::Terminal(Terminal {
1366 outcome: Outcome::Failed,
1367 error: Some(ErrorCode::SourceChanged),
1368 publication: Publication::None,
1369 created_count: 0,
1370 retained_partial_count: 0,
1371 durability: Durability::NotApplicable,
1372 cleanup: Cleanup::Complete,
1373 }));
1374 state.queue.extend([
1375 HostEvent::StdoutEof,
1376 HostEvent::StderrEof,
1377 HostEvent::Exited { success: true },
1378 ]);
1379 }
1380 for _ in 0..30 {
1381 render(&ctx, &mut app, vec![]);
1382 }
1383 assert!(!app.model.busy());
1384 let shown = render(&ctx, &mut app, vec![]);
1385 assert!(
1386 shown
1387 .iter()
1388 .any(|(text, _)| text.contains("묶을 파일이 바뀌었습니다"))
1389 );
1390 assert!(!shown.iter().any(|(text, _)| text == "압축파일 다시 열기"));
1391 let count = factory.state.borrow().starts.len();
1392 click(&ctx, &mut app, "다시 만들기");
1393 assert!(app.model.busy());
1394 let state = factory.state.borrow();
1395 assert_eq!(state.starts.len(), count + 1);
1396 assert_eq!(state.starts.last(), Some(&request));
1397 }
1398 }
1399}
1400
1401#[cfg(feature = "ui")]
1402#[test]
1403fn conflict_retry_waits_for_folder_choice_and_preserves_selection() {
1404 use eframe::egui;
1405 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
1406 let scratch = Folder::new();
1407 let factory = FakeFactory::default();
1408 let mut app = ArchiveApp::new(
1409 Box::new(factory.clone()),
1410 Some(scratch.0.join("sample.zip")),
1411 false,
1412 );
1413 pump(&mut app.model);
1414 app.model.selected.insert(0);
1415 factory.state.borrow_mut().manual = true;
1416 let ctx = egui::Context::default();
1417 let render = |app: &mut ArchiveApp, events| {
1418 let mut output = ctx.run_ui(
1419 egui::RawInput {
1420 screen_rect: Some(egui::Rect::from_min_size(
1421 egui::Pos2::ZERO,
1422 egui::vec2(760.0, 540.0),
1423 )),
1424 events,
1425 ..Default::default()
1426 },
1427 |ui| app.show(ui),
1428 );
1429 output.textures_delta.clear();
1430 fn walk(shape: &egui::epaint::Shape, labels: &mut Vec<(String, egui::Pos2)>) {
1431 match shape {
1432 egui::epaint::Shape::Text(text) => labels.push((
1433 text.galley.job.text.clone(),
1434 text.pos + text.galley.rect.size() / 2.0,
1435 )),
1436 egui::epaint::Shape::Vec(shapes) => {
1437 for shape in shapes {
1438 walk(shape, labels);
1439 }
1440 }
1441 _ => {}
1442 }
1443 }
1444 let mut labels = Vec::new();
1445 for shape in &output.shapes {
1446 walk(&shape.shape, &mut labels);
1447 }
1448 labels
1449 };
1450 let click = |app: &mut ArchiveApp, text: &str| {
1451 render(app, vec![]);
1452 let point = render(app, vec![])
1453 .into_iter()
1454 .filter(|(value, _)| value == text)
1455 .max_by(|a, b| a.1.y.total_cmp(&b.1.y))
1456 .unwrap_or_else(|| panic!("항목 없음: {text}"))
1457 .1;
1458 for pressed in [true, false] {
1459 render(
1460 app,
1461 vec![
1462 egui::Event::PointerMoved(point),
1463 egui::Event::PointerButton {
1464 pos: point,
1465 button: egui::PointerButton::Primary,
1466 pressed,
1467 modifiers: egui::Modifiers::NONE,
1468 },
1469 ],
1470 );
1471 }
1472 };
1473 render(&mut app, vec![]);
1474 click(&mut app, "선택한 항목만 풀기");
1475 assert!(app.begin_extract());
1476 let old = scratch.0.join("sample");
1477 fs::write(old.join("existing"), "preserve").unwrap();
1478 let chosen = scratch.0.join("chosen");
1479 fs::create_dir(&chosen).unwrap();
1480 {
1481 let mut state = factory.state.borrow_mut();
1482 state.frame(Event::Accepted { encryption: true });
1483 state.frame(Event::Terminal(Terminal {
1484 outcome: Outcome::Failed,
1485 error: Some(ErrorCode::Conflict),
1486 publication: Publication::None,
1487 created_count: 0,
1488 retained_partial_count: 0,
1489 durability: Durability::NotApplicable,
1490 cleanup: Cleanup::Complete,
1491 }));
1492 state.queue.extend([
1493 HostEvent::StdoutEof,
1494 HostEvent::StderrEof,
1495 HostEvent::Exited { success: true },
1496 ]);
1497 }
1498 for _ in 0..30 {
1499 render(&mut app, vec![]);
1500 }
1501 assert_eq!(factory.state.borrow().starts.len(), 2);
1502 click(&mut app, "다른 폴더에 풀기");
1503 assert_eq!(factory.state.borrow().starts.len(), 2);
1504 click(&mut app, "상위 폴더");
1505 click(&mut app, "chosen");
1506 click(&mut app, "이 폴더 선택");
1507 assert!(matches!(factory.state.borrow().starts.last(),
1508 Some(Start::Extract { destination, selection: Selection::EntryIds(ids), .. })
1509 if destination == &chosen && ids == &vec![0]));
1510 assert_eq!(
1511 fs::read_to_string(old.join("existing")).unwrap(),
1512 "preserve"
1513 );
1514}
1515
1516#[cfg(feature = "ui")]
1517#[test]
1518fn create_dialog_keeps_title_and_actions_visible_after_resize() {
1519 use eframe::egui::{self, epaint::Shape};
1520 use zipelo_ui_memory_app::archive_screen::ArchiveApp;
1521 let scratch = Folder::new();
1522 let mut app = ArchiveApp::new(Box::new(FakeFactory::default()), None, false);
1523 app.add_sources(vec![scratch.0.join("one.txt"), scratch.0.join("photos")]);
1524 let ctx = egui::Context::default();
1525 for size in [egui::vec2(1060.0, 720.0), egui::vec2(760.0, 540.0)] {
1526 let mut texts = Vec::new();
1527 for _ in 0..8 {
1528 let mut output = ctx.run_ui(
1529 egui::RawInput {
1530 screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, size)),
1531 ..Default::default()
1532 },
1533 |ui| app.show(ui),
1534 );
1535 output.textures_delta.clear();
1536 fn walk(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) {
1537 match shape {
1538 Shape::Text(text) => output.push((
1539 text.galley.job.text.clone(),
1540 text.pos + text.galley.rect.size() / 2.0,
1541 )),
1542 Shape::Vec(shapes) => {
1543 for shape in shapes {
1544 walk(shape, output);
1545 }
1546 }
1547 _ => {}
1548 }
1549 }
1550 texts.clear();
1551 for shape in &output.shapes {
1552 walk(&shape.shape, &mut texts);
1553 }
1554 }
1555 for label in ["ZIP 만들기", "만들기", "취소"] {
1556 let positions = texts
1557 .iter()
1558 .filter(|(text, _)| text == label)
1559 .map(|(_, p)| p)
1560 .collect::<Vec<_>>();
1561 assert!(!positions.is_empty(), "{label}");
1562 assert!(
1563 positions.iter().all(|p| p.y >= 0.0 && p.y <= size.y),
1564 "{label}: {positions:?}"
1565 );
1566 }
1567 }
1568}
1569#[test]
1570fn folder_open_command_preserves_shell_characters_as_one_argument() {
1571 let path = path("한글 폴더 ; $(touch unexpected)");
1572 let command = folder_command(&path);
1573 assert_eq!(
1574 command.get_program(),
1575 if cfg!(windows) {
1576 "explorer"
1577 } else {
1578 "xdg-open"
1579 }
1580 );
1581 assert_eq!(
1582 command.get_args().collect::<Vec<_>>(),
1583 vec![path.as_os_str()]
1584 );
1585}
1586
1587#[test]
1588fn late_cancel_and_terminal_wait_use_finishing_text() {
1589 let mut model = Model::default();
1590 model.progress = Some((Stage::Decode, 1, Some(2), 0));
1591 assert_eq!(activity_text(&model, false), "압축을 푸는 중");
1592 model.cancel = Some(CancelStatus::Requested);
1593 assert_eq!(activity_text(&model, false), "취소하는 중...");
1594 for state in [CancelStatus::TooLate, CancelStatus::Finished] {
1595 model.cancel = Some(state);
1596 assert_eq!(activity_text(&model, false), "마무리하는 중");
1597 }
1598 model.cancel = Some(CancelStatus::Requested);
1599 model.terminal = Some(terminal());
1600 assert_eq!(activity_text(&model, false), "마무리하는 중");
1601}
1602#[test]
1603fn client_protocol_errors_hide_internal_terms_but_preserve_exit_uncertainty() {
1604 for error in [
1605 "작업 ID 한도에 도달했습니다",
1606 "작업자 응답 순서나 작업 ID가 일치하지 않습니다",
1607 "작업 승인 응답이 없습니다",
1608 "출력 보고 한도 초과",
1609 ] {
1610 assert_eq!(client_error_text(error), INTERNAL);
1611 }
1612 assert_eq!(
1613 client_error_text("작업자 종료 결과를 확인할 수 없습니다. 출력 상태를 확인하세요"),
1614 UNCONFIRMED_FINISH
1615 );
1616}