team-ljyzipelo

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