team-ljyzipelo

공개
221줄7.5 KB
1fn 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
23fn 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
46fn 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
55fn 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]
74fn 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 assert!(!text.iter().any(|(text, _, _)| text == "암호"));
119 let title = output
120 .viewport_output
121 .values()
122 .flat_map(|v| &v.commands)
123 .find_map(|cmd| match cmd {
124 egui::ViewportCommand::Title(title) => Some(title),
125 _ => None,
126 })
127 .unwrap();
128 assert!(title.contains('…') && title.ends_with(" — Zipelo"));
129 assert!(title.chars().count() < full_title.chars().count());
130 // 툴팁은 표시용 *를 뺀 실제 이름을 보여 줌.
131 assert_full_tooltip(
132 &ctx,
133 &mut app,
134 first.1.center(),
135 first.0.trim_start_matches('*'),
136 );
137 let output = narrow_frame(&ctx, &mut app, 14.0, vec![egui::Event::PointerGone]);
138 let point = layout_text(&output)
139 .into_iter()
140 .find(|(text, _, _)| text == "열기")
141 .unwrap()
142 .1
143 .center();
144 assert_full_tooltip(&ctx, &mut app, point, &full_title);
145}
146
147#[test]
148fn narrow_deep_folder_path_is_elided_without_displacing_search() {
149 let scratch = Folder::new();
150 let factory = FakeFactory::default();
151 let mut app = loaded(&scratch, &factory);
152 let folder = "deep-folder/".repeat(40).trim_end_matches('/').to_owned();
153 app.model.entries[0].name = format!("{folder}/file.txt");
154 app.browse_folder(&folder);
155 let ctx = egui::Context::default();
156 narrow_frame(&ctx, &mut app, 0.0, vec![]);
157 let output = narrow_frame(&ctx, &mut app, 1.0, vec![]);
158 assert_narrow_text(&output);
159 let text = layout_text(&output);
160 let full = format!("/{folder}");
161 let path = text.iter().find(|(text, _, _)| text == &full).unwrap();
162 assert!(path.2);
163 assert!(
164 text.iter()
165 .any(|(text, rect, _)| text == "파일 검색" && rect.right() < 760.0)
166 );
167 assert_full_tooltip(&ctx, &mut app, path.1.center(), &full);
168}
169
170#[test]
171fn narrow_create_sources_keep_remove_and_footer_actions_visible() {
172 let scratch = Folder::new();
173 let factory = FakeFactory::default();
174 let mut app = loaded(&scratch, &factory);
175 let name = format!("{}.txt", "W".repeat(220));
176 let path = scratch.0.join(&name);
177 fs::write(&path, b"source").unwrap();
178 app.add_sources(vec![path]);
179 app.show_create(false);
180 let ctx = egui::Context::default();
181 narrow_frame(&ctx, &mut app, 0.0, vec![]);
182 let output = narrow_frame(&ctx, &mut app, 1.0, vec![]);
183 assert_narrow_text(&output);
184 let text = layout_text(&output);
185 assert!(
186 text.iter()
187 .any(|(text, _, elided)| text == &name && *elided)
188 );
189 for expected in ["빼기", "취소", "압축하기"] {
190 assert!(
191 text.iter()
192 .any(|(text, rect, _)| text == expected && rect.bottom() <= 540.0)
193 );
194 }
195}
196
197#[test]
198fn narrow_result_path_is_elided_and_full_path_remains_in_tooltip() {
199 let scratch = Folder::new();
200 let factory = FakeFactory::default();
201 let mut app = loaded(&scratch, &factory);
202 let output_path = scratch.0.join("nested-output/".repeat(30));
203 fs::create_dir_all(&output_path).unwrap();
204 app.choose_destination(output_path.clone());
205 assert!(app.begin_extract());
206 pump(&mut app.model);
207 let ctx = egui::Context::default();
208 for frame in 0..8 {
209 narrow_frame(&ctx, &mut app, frame as f64 / 10.0, vec![]);
210 }
211 let output = narrow_frame(&ctx, &mut app, 1.0, vec![]);
212 assert_narrow_text(&output);
213 let text = layout_text(&output);
214 let full = format!("{} 폴더에 저장했습니다.", output_path.display());
215 let path = text.iter().find(|(text, _, _)| text == &full).unwrap();
216 assert!(path.2);
217 for expected in ["확인", "폴더 열기"] {
218 assert!(text.iter().any(|(text, _, _)| text == expected));
219 }
220 assert_full_tooltip(&ctx, &mut app, path.1.center(), &full);
221}