team-ljyzipelo

공개
291줄9.0 KB
1use super::*;
2use std::collections::BTreeSet;
3use zipelo_ui_memory_app::archive_present as present;
4
5fn waiting() -> (Model, FakeFactory) {
6 let mut factory = FakeFactory::default();
7 let mut model = Model::default();
8 list(&mut model, &mut factory);
9 factory.state.borrow_mut().manual = true;
10 assert!(model.extract(path("output"), false, None, &mut factory));
11 factory
12 .state
13 .borrow_mut()
14 .frame(Event::Accepted { encryption: false });
15 ask(&mut model, &factory, 29);
16 (model, factory)
17}
18
19fn ask(model: &mut Model, factory: &FakeFactory, challenge_id: u64) {
20 factory
21 .state
22 .borrow_mut()
23 .frame(Event::ConflictRequired(Conflict {
24 challenge_id,
25 entry_id: 0,
26 relative_name: "읽어주세요.txt".into(),
27 incoming_size: 31,
28 existing_size: 128,
29 }));
30 for _ in 0..8 {
31 model.poll();
32 }
33}
34
35#[test]
36fn each_choice_sends_one_scoped_reply_and_does_not_claim_a_saved_file() {
37 for choice in [
38 ConflictChoice::Overwrite,
39 ConflictChoice::Skip,
40 ConflictChoice::Rename,
41 ] {
42 for apply in [false, true] {
43 let (mut model, factory) = waiting();
44 assert_eq!(model.conflict.as_ref().unwrap().existing_size, 128);
45 assert!(model.resolve_conflict(choice, apply));
46 assert!(model.conflict.is_none());
47 assert!(model.outputs.is_empty());
48 assert!(!model.resolve_conflict(choice, apply));
49 assert_eq!(
50 factory.state.borrow().conflict_replies,
51 vec![(29, choice, apply)]
52 );
53 assert_eq!(
54 factory.state.borrow().requests.last(),
55 Some(&(1, "conflict"))
56 );
57 }
58 }
59}
60
61#[test]
62fn cancellation_clears_question_and_rejects_a_late_click() {
63 let (mut model, factory) = waiting();
64 model.cancel();
65 assert!(model.conflict.is_none());
66 assert!(!model.resolve_conflict(ConflictChoice::Overwrite, true));
67 ask(&mut model, &factory, 30);
68 assert!(model.conflict.is_none());
69 assert!(factory.state.borrow().conflict_replies.is_empty());
70}
71
72#[test]
73fn duplicate_challenge_and_duplicate_resolution_are_rejected() {
74 let (mut model, factory) = waiting();
75 assert!(model.resolve_conflict(ConflictChoice::Skip, false));
76 ask(&mut model, &factory, 29);
77 assert!(model.error.is_some());
78 let (mut model, factory) = waiting();
79 let resolution = Resolution {
80 entry_id: 0,
81 relative_name: "읽어주세요.txt".into(),
82 choice: ConflictChoice::Skip,
83 };
84 for _ in 0..2 {
85 factory
86 .state
87 .borrow_mut()
88 .frame(Event::ConflictResolved(resolution.clone()));
89 }
90 for _ in 0..8 {
91 model.poll();
92 }
93 assert!(model.error.is_some());
94}
95
96fn completed(created_count: u64) -> Terminal {
97 Terminal {
98 outcome: Outcome::Completed,
99 error: None,
100 publication: if created_count == 0 {
101 Publication::None
102 } else {
103 Publication::Complete
104 },
105 created_count,
106 retained_partial_count: 0,
107 durability: if created_count == 0 {
108 Durability::NotApplicable
109 } else {
110 Durability::Synced
111 },
112 cleanup: Cleanup::Complete,
113 }
114}
115
116#[test]
117fn auto_applied_results_adjust_targets_but_created_reports_confirm_saves() {
118 for choice in [
119 ConflictChoice::Overwrite,
120 ConflictChoice::Skip,
121 ConflictChoice::Rename,
122 ] {
123 let (mut model, factory) = waiting();
124 assert!(model.resolve_conflict(choice, true));
125 let name = if choice == ConflictChoice::Rename {
126 "읽어주세요 (1).txt"
127 } else {
128 "읽어주세요.txt"
129 };
130 factory
131 .state
132 .borrow_mut()
133 .frame(Event::ConflictResolved(Resolution {
134 entry_id: 0,
135 relative_name: name.into(),
136 choice,
137 }));
138 for _ in 0..8 {
139 model.poll();
140 }
141 assert!(model.outputs.is_empty());
142 let targets = ["읽어주세요.txt".to_owned()].into_iter().collect();
143 let targets =
144 present::resolved_targets(Some(&targets), &model.entries, None, &model.resolutions)
145 .unwrap();
146 assert_eq!(targets.len(), usize::from(choice != ConflictChoice::Skip));
147 let count = u64::from(choice != ConflictChoice::Skip);
148 let terminal = completed(count);
149 if count != 0 {
150 assert!(
151 present::publication_warnings(
152 Some(&terminal),
153 true,
154 Some(&targets),
155 &BTreeSet::new(),
156 &[]
157 )
158 .contains(&present::UNCERTAIN)
159 );
160 factory.state.borrow_mut().frame(Event::Output {
161 entry_id: Some(0),
162 relative_name: name.into(),
163 disposition: Disposition::Created,
164 });
165 }
166 factory
167 .state
168 .borrow_mut()
169 .frame(Event::Terminal(terminal.clone()));
170 factory.state.borrow_mut().queue.extend([
171 HostEvent::StdoutEof,
172 HostEvent::StderrEof,
173 HostEvent::Exited { success: true },
174 ]);
175 pump(&mut model);
176 assert!(model.confirmed);
177 assert!(model.conflict.is_none());
178 assert!(
179 present::publication_warnings(
180 Some(&terminal),
181 model.confirmed,
182 Some(&targets),
183 &BTreeSet::new(),
184 &model.outputs
185 )
186 .is_empty()
187 );
188 }
189}
190
191#[test]
192fn skipped_files_still_allow_created_directories_to_be_counted() {
193 let terminal = completed(1);
194 assert!(
195 present::publication_warnings(
196 Some(&terminal),
197 true,
198 Some(&BTreeSet::new()),
199 &["사진".into()].into_iter().collect(),
200 &[("사진".into(), Disposition::Created)],
201 )
202 .is_empty()
203 );
204}
205
206#[cfg(all(feature = "ui-fixture", debug_assertions))]
207#[test]
208fn conflict_modal_buttons_and_escape_use_the_pending_question() {
209 use eframe::egui::{self, epaint::Shape};
210 use zipelo_ui_memory_app::archive_screen::{ArchiveApp, scenarios};
211 for label in [
212 "덮어쓰기",
213 "건너뛰기",
214 "이름 바꿔 저장",
215 "작업 취소",
216 "escape",
217 ] {
218 let ctx = egui::Context::default();
219 let mut app = scenarios::parse("conflict-choice").unwrap().build();
220 let frame = |app: &mut ArchiveApp, events| {
221 let mut output = ctx.run_ui(
222 egui::RawInput {
223 screen_rect: Some(egui::Rect::from_min_size(
224 egui::Pos2::ZERO,
225 egui::vec2(760.0, 540.0),
226 )),
227 events,
228 ..Default::default()
229 },
230 |ui| app.show(ui),
231 );
232 output.textures_delta.clear();
233 output
234 };
235 fn labels(shape: &Shape, output: &mut Vec<(String, egui::Pos2)>) {
236 match shape {
237 Shape::Text(t) => {
238 output.push((t.galley.text().into(), t.pos + t.galley.rect.size() / 2.0))
239 }
240 Shape::Vec(shapes) => {
241 for shape in shapes {
242 labels(shape, output);
243 }
244 }
245 _ => {}
246 }
247 }
248 let mut texts = Vec::new();
249 for _ in 0..3 {
250 texts.clear();
251 for shape in frame(&mut app, vec![]).shapes {
252 labels(&shape.shape, &mut texts);
253 }
254 }
255 if label == "escape" {
256 frame(
257 &mut app,
258 vec![egui::Event::Key {
259 key: egui::Key::Escape,
260 physical_key: None,
261 pressed: true,
262 repeat: false,
263 modifiers: egui::Modifiers::NONE,
264 }],
265 );
266 } else {
267 let point = texts.iter().find(|(text, _)| text == label).unwrap().1;
268 for pressed in [true, false] {
269 frame(
270 &mut app,
271 vec![
272 egui::Event::PointerMoved(point),
273 egui::Event::PointerButton {
274 pos: point,
275 button: egui::PointerButton::Primary,
276 pressed,
277 modifiers: egui::Modifiers::NONE,
278 },
279 ],
280 );
281 }
282 }
283 assert!(app.model.conflict.is_none(), "{label}");
284 assert!(app.model.busy());
285 assert!(app.model.outputs.is_empty());
286 assert_eq!(
287 app.model.cancellation_requested(),
288 matches!(label, "작업 취소" | "escape")
289 );
290 }
291}