| 1 | fn narrow_frame( |
| 2 | ctx: &egui::Context, |
| 3 | app: &mut ArchiveApp, |
| 4 | time: f64, |
| 5 | events: Vec<egui::Event>, |
| 6 | ) -> egui::FullOutput { |
| 7 | let mut output = ctx.run_ui( |
| 8 | egui::RawInput { |
| 9 | screen_rect: Some(egui::Rect::from_min_size( |
| 10 | egui::Pos2::ZERO, |
| 11 | egui::vec2(760.0, 540.0), |
| 12 | )), |
| 13 | time: Some(time), |
| 14 | events, |
| 15 | ..Default::default() |
| 16 | }, |
| 17 | |ui| app.show(ui), |
| 18 | ); |
| 19 | output.textures_delta.clear(); |
| 20 | output |
| 21 | } |
| 22 | |
| 23 | fn layout_text(output: &egui::FullOutput) -> Vec<(String, egui::Rect, bool)> { |
| 24 | fn walk(shape: &Shape, result: &mut Vec<(String, egui::Rect, bool)>) { |
| 25 | match shape { |
| 26 | Shape::Text(text) => result.push(( |
| 27 | text.galley.job.text.clone(), |
| 28 | text.galley.rect.translate(text.pos.to_vec2()), |
| 29 | text.galley.elided, |
| 30 | )), |
| 31 | Shape::Vec(shapes) => { |
| 32 | for shape in shapes { |
| 33 | walk(shape, result); |
| 34 | } |
| 35 | } |
| 36 | _ => {} |
| 37 | } |
| 38 | } |
| 39 | let mut result = Vec::new(); |
| 40 | for shape in &output.shapes { |
| 41 | walk(&shape.shape, &mut result); |
| 42 | } |
| 43 | result |
| 44 | } |
| 45 | |
| 46 | fn assert_narrow_text(output: &egui::FullOutput) { |
| 47 | for (text, rect, _) in layout_text(output) { |
| 48 | assert!( |
| 49 | rect.left() >= -1.0 && rect.right() <= 761.0, |
| 50 | "{text:?}: {rect:?}" |
| 51 | ); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | fn assert_full_tooltip(ctx: &egui::Context, app: &mut ArchiveApp, point: egui::Pos2, full: &str) { |
| 56 | ctx.style_mut_of(egui::Theme::Light, |style| { |
| 57 | style.interaction.tooltip_delay = 0.0 |
| 58 | }); |
| 59 | let mut output = narrow_frame(ctx, app, 10.0, vec![egui::Event::PointerMoved(point)]); |
| 60 | for time in [11.0, 12.0, 13.0] { |
| 61 | output = narrow_frame(ctx, app, time, vec![]); |
| 62 | } |
| 63 | assert!( |
| 64 | layout_text(&output) |
| 65 | .iter() |
| 66 | .any(|(text, _, elided)| text == full && !elided), |
| 67 | "전체 툴팁 없음: {full} point={point:?} shown={:?}", |
| 68 | layout_text(&output) |
| 69 | ); |
| 70 | assert_narrow_text(&output); |
| 71 | } |
| 72 | |
| 73 | #[test] |
| 74 | fn narrow_archive_keeps_columns_and_virtualizes_thousands_of_long_names() { |
| 75 | let scratch = Folder::new(); |
| 76 | let factory = FakeFactory::default(); |
| 77 | let mut app = loaded(&scratch, &factory); |
| 78 | let name = format!("{}.txt", "W".repeat(220)); |
| 79 | app.model.entries = (0..5000) |
| 80 | .map(|id| Entry { |
| 81 | id, |
| 82 | name: format!("{id:04}-{name}"), |
| 83 | kind: Kind::File, |
| 84 | bytes: Some(31), |
| 85 | packed: None, |
| 86 | encrypted: true, |
| 87 | }) |
| 88 | .collect(); |
| 89 | app.model.selected = (0..5000).collect(); |
| 90 | app.model.archive = Some( |
| 91 | scratch |
| 92 | .0 |
| 93 | .join("deep-folder/".repeat(30)) |
| 94 | .join(format!("{name}.zip")), |
| 95 | ); |
| 96 | let full_title = format!("{} — Zipelo", app.model.archive.as_ref().unwrap().display()); |
| 97 | let ctx = egui::Context::default(); |
| 98 | narrow_frame(&ctx, &mut app, 0.0, vec![]); |
| 99 | let output = narrow_frame(&ctx, &mut app, 1.0, vec![]); |
| 100 | assert_narrow_text(&output); |
| 101 | let text = layout_text(&output); |
| 102 | assert!(text.len() < 100); |
| 103 | // 암호가 걸린 항목은 이름 앞에 *가 붙음. |
| 104 | let first = text |
| 105 | .iter() |
| 106 | .find(|(text, _, _)| text.trim_start_matches('*') == format!("0000-{name}")) |
| 107 | .unwrap(); |
| 108 | assert!(first.2); |
| 109 | // 크기는 스크롤 막대 자리(오른쪽 24px)를 침범하지 않는 행 안쪽에 남음. |
| 110 | assert!( |
| 111 | text.iter() |
| 112 | .any(|(text, rect, _)| text == "31 B" && rect.right() <= 736.0) |
| 113 | ); |
| 114 | for expected in ["5000개 항목", "선택 5000개"] { |
| 115 | assert!(text.iter().any(|(text, _, _)| text == expected)); |
| 116 | } |
| 117 | // 열 제목 줄(이름, 크기, 암호)은 없고 암호는 이름 앞의 *로만 표시함. |
| 118 | for removed in ["이름", "크기", "암호"] { |
| 119 | assert!(!text.iter().any(|(text, _, _)| text == removed)); |
| 120 | } |
| 121 | let title = output |
| 122 | .viewport_output |
| 123 | .values() |
| 124 | .flat_map(|v| &v.commands) |
| 125 | .find_map(|cmd| match cmd { |
| 126 | egui::ViewportCommand::Title(title) => Some(title), |
| 127 | _ => None, |
| 128 | }) |
| 129 | .unwrap(); |
| 130 | assert!(title.contains('…') && title.ends_with(" — Zipelo")); |
| 131 | assert!(title.chars().count() < full_title.chars().count()); |
| 132 | // 툴팁은 표시용 *를 뺀 실제 이름을 보여 줌. |
| 133 | assert_full_tooltip( |
| 134 | &ctx, |
| 135 | &mut app, |
| 136 | first.1.center(), |
| 137 | first.0.trim_start_matches('*'), |
| 138 | ); |
| 139 | let output = narrow_frame(&ctx, &mut app, 14.0, vec![egui::Event::PointerGone]); |
| 140 | let point = layout_text(&output) |
| 141 | .into_iter() |
| 142 | .find(|(text, _, _)| text == "열기") |
| 143 | .unwrap() |
| 144 | .1 |
| 145 | .center(); |
| 146 | assert_full_tooltip(&ctx, &mut app, point, &full_title); |
| 147 | } |
| 148 | |
| 149 | #[test] |
| 150 | fn narrow_deep_folder_path_is_elided_without_displacing_search() { |
| 151 | let scratch = Folder::new(); |
| 152 | let factory = FakeFactory::default(); |
| 153 | let mut app = loaded(&scratch, &factory); |
| 154 | let folder = "deep-folder/".repeat(40).trim_end_matches('/').to_owned(); |
| 155 | app.model.entries[0].name = format!("{folder}/file.txt"); |
| 156 | app.browse_folder(&folder); |
| 157 | let ctx = egui::Context::default(); |
| 158 | narrow_frame(&ctx, &mut app, 0.0, vec![]); |
| 159 | let output = narrow_frame(&ctx, &mut app, 1.0, vec![]); |
| 160 | assert_narrow_text(&output); |
| 161 | let text = layout_text(&output); |
| 162 | let full = format!("/{folder}"); |
| 163 | let path = text.iter().find(|(text, _, _)| text == &full).unwrap(); |
| 164 | assert!(path.2); |
| 165 | assert!( |
| 166 | text.iter() |
| 167 | .any(|(text, rect, _)| text == "파일 검색" && rect.right() < 760.0) |
| 168 | ); |
| 169 | assert_full_tooltip(&ctx, &mut app, path.1.center(), &full); |
| 170 | } |
| 171 | |
| 172 | #[test] |
| 173 | fn narrow_create_sources_keep_names_and_footer_actions_visible() { |
| 174 | let scratch = Folder::new(); |
| 175 | let factory = FakeFactory::default(); |
| 176 | let mut app = loaded(&scratch, &factory); |
| 177 | let name = format!("{}.txt", "W".repeat(220)); |
| 178 | let path = scratch.0.join(&name); |
| 179 | fs::write(&path, b"source").unwrap(); |
| 180 | app.add_sources(vec![path]); |
| 181 | app.show_create(false); |
| 182 | let ctx = egui::Context::default(); |
| 183 | narrow_frame(&ctx, &mut app, 0.0, vec![]); |
| 184 | let output = narrow_frame(&ctx, &mut app, 1.0, vec![]); |
| 185 | assert_narrow_text(&output); |
| 186 | let text = layout_text(&output); |
| 187 | assert!( |
| 188 | text.iter() |
| 189 | .any(|(text, _, elided)| text == &name && *elided) |
| 190 | ); |
| 191 | for expected in ["취소", "압축하기"] { |
| 192 | assert!( |
| 193 | text.iter() |
| 194 | .any(|(text, rect, _)| text == expected && rect.bottom() <= 540.0) |
| 195 | ); |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | #[test] |
| 200 | fn narrow_result_path_is_elided_and_full_path_remains_in_tooltip() { |
| 201 | let scratch = Folder::new(); |
| 202 | let factory = FakeFactory::default(); |
| 203 | let mut app = loaded(&scratch, &factory); |
| 204 | let output_path = scratch.0.join("nested-output/".repeat(30)); |
| 205 | fs::create_dir_all(&output_path).unwrap(); |
| 206 | app.choose_destination(output_path.clone()); |
| 207 | assert!(app.begin_extract()); |
| 208 | pump(&mut app.model); |
| 209 | let ctx = egui::Context::default(); |
| 210 | for frame in 0..8 { |
| 211 | narrow_frame(&ctx, &mut app, frame as f64 / 10.0, vec![]); |
| 212 | } |
| 213 | let output = narrow_frame(&ctx, &mut app, 1.0, vec![]); |
| 214 | assert_narrow_text(&output); |
| 215 | let text = layout_text(&output); |
| 216 | let full = format!("{} 폴더에 저장했습니다.", output_path.display()); |
| 217 | let path = text.iter().find(|(text, _, _)| text == &full).unwrap(); |
| 218 | assert!(path.2); |
| 219 | for expected in ["확인", "폴더 열기"] { |
| 220 | assert!(text.iter().any(|(text, _, _)| text == expected)); |
| 221 | } |
| 222 | assert_full_tooltip(&ctx, &mut app, path.1.center(), &full); |
| 223 | } |