| | @@ -543,6 +543,89 @@ mod widgets { |
| 543 | 543 | assert!(matches!(result, Some(Choice::Paths(ref paths)) if paths == &vec![file])); |
| 544 | 544 | } |
| 545 | 545 | |
| 546 | +추가: fn focus_zip_action_with_tab(ctx: &egui::Context, app: &mut ArchiveApp, label: &str) { |
| 547 | +추가: render(ctx, app, vec![]); |
| 548 | +추가: let shown = render(ctx, app, vec![]); |
| 549 | +추가: let point = shown.iter().find(|(text, _)| text == label).unwrap().1; |
| 550 | +추가: for _ in 0..80 { |
| 551 | +추가: if ctx |
| 552 | +추가: .memory(|memory| memory.focused()) |
| 553 | +추가: .and_then(|id| ctx.read_response(id)) |
| 554 | +추가: .is_some_and(|response| response.rect.contains(point)) |
| 555 | +추가: { |
| 556 | +추가: return; |
| 557 | +추가: } |
| 558 | +추가: render(ctx, app, vec![key(egui::Key::Tab)]); |
| 559 | +추가: let mut released = key(egui::Key::Tab); |
| 560 | +추가: if let egui::Event::Key { pressed, .. } = &mut released { |
| 561 | +추가: *pressed = false; |
| 562 | +추가: } |
| 563 | +추가: render(ctx, app, vec![released]); |
| 564 | +추가: } |
| 565 | +추가: panic!("키보드 초점 없음: {label}"); |
| 566 | +추가: } |
| 567 | +추가: |
| 568 | +추가: #[test] |
| 569 | +추가: fn keyboard_cancel_and_escape_never_start_zip_creation() { |
| 570 | +추가: for escape in [false, true] { |
| 571 | +추가: let scratch = Folder::new(); |
| 572 | +추가: let factory = FakeFactory::manual(); |
| 573 | +추가: let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 574 | +추가: let source = scratch.0.join("source.txt"); |
| 575 | +추가: fs::write(&source, "fixture").unwrap(); |
| 576 | +추가: app.add_sources(vec![source]); |
| 577 | +추가: let ctx = egui::Context::default(); |
| 578 | +추가: focus_zip_action_with_tab(&ctx, &mut app, if escape { "만들기" } else { "취소" }); |
| 579 | +추가: let mut events = vec![key(egui::Key::Enter)]; |
| 580 | +추가: if escape { |
| 581 | +추가: events.push(key(egui::Key::Escape)); |
| 582 | +추가: } |
| 583 | +추가: render(&ctx, &mut app, events); |
| 584 | +추가: let shown = render(&ctx, &mut app, vec![]); |
| 585 | +추가: assert!(factory.state.borrow().starts.is_empty()); |
| 586 | +추가: assert!(!app.model.busy()); |
| 587 | +추가: assert!(!scratch.0.join("source.zip").exists()); |
| 588 | +추가: assert_eq!( |
| 589 | +추가: shown |
| 590 | +추가: .iter() |
| 591 | +추가: .filter(|(text, _)| text == "ZIP 만들기") |
| 592 | +추가: .count(), |
| 593 | +추가: 1 |
| 594 | +추가: ); |
| 595 | +추가: } |
| 596 | +추가: } |
| 597 | +추가: |
| 598 | +추가: #[test] |
| 599 | +추가: fn zip_creation_enter_only_activates_focused_make_button() { |
| 600 | +추가: for make_button in [false, true] { |
| 601 | +추가: let scratch = Folder::new(); |
| 602 | +추가: let factory = FakeFactory::manual(); |
| 603 | +추가: let mut app = ArchiveApp::new(Box::new(factory.clone()), None, false); |
| 604 | +추가: let source = scratch.0.join("source.txt"); |
| 605 | +추가: fs::write(&source, "fixture").unwrap(); |
| 606 | +추가: app.add_sources(vec![source.clone()]); |
| 607 | +추가: let ctx = egui::Context::default(); |
| 608 | +추가: render(&ctx, &mut app, vec![]); |
| 609 | +추가: if make_button { |
| 610 | +추가: focus_zip_action_with_tab(&ctx, &mut app, "만들기"); |
| 611 | +추가: } else { |
| 612 | +추가: ctx.memory_mut(|memory| memory.request_focus(egui::Id::unique("zip-name"))); |
| 613 | +추가: render(&ctx, &mut app, vec![]); |
| 614 | +추가: } |
| 615 | +추가: render(&ctx, &mut app, vec![key(egui::Key::Enter)]); |
| 616 | +추가: render(&ctx, &mut app, vec![]); |
| 617 | +추가: let state = factory.state.borrow(); |
| 618 | +추가: assert_eq!(state.starts.len(), usize::from(make_button)); |
| 619 | +추가: if make_button { |
| 620 | +추가: assert!( |
| 621 | +추가: matches!(state.starts.last(), Some(Start::CreateZip {sources, output_file, ..}) |
| 622 | +추가: if sources == &vec![(source, "source.txt".into())] |
| 623 | +추가: && output_file == &scratch.0.join("source.zip")) |
| 624 | +추가: ); |
| 625 | +추가: } |
| 626 | +추가: } |
| 627 | +추가: } |
| 628 | +추가: |
| 546 | 629 | fn picker_frame( |
| 547 | 630 | ctx: &egui::Context, |
| 548 | 631 | picker: &mut Picker, |