|
10 | 10 | //! * Synchronize with the defaults imports the new photos and leaves missing ones alone. |
11 | 11 | //! * Ticking "Remove missing photos" also moves those to Recently Deleted. |
12 | 12 | //! * Cancel leaves the library as it was. |
| 13 | +//! * A folder that has nothing to bring in only says so: the dialog has one Close and no |
| 14 | +//! choices, and closing it starts nothing. |
13 | 15 | //! * Synchronize hands the work to the background at once: the dialog closes, the app keeps |
14 | 16 | //! answering, and the photos arrive over the next frames under a row in the activity stack, as one undo |
15 | 17 | //! step. |
@@ -62,12 +64,19 @@ fn write_png(path: &str, seed: u8) { |
62 | 64 | /// The app with `trip/a.png` and `trip/b.png` imported, then `c.png` added and `b.png` deleted |
63 | 65 | /// on disk behind its back. |
64 | 66 | fn changed_folder(dir: &Scratch) -> Headless { |
| 67 | + imported_folder(dir, || { |
| 68 | + write_png(&dir.path("trip/c.png"), 3); |
| 69 | + std::fs::remove_file(dir.path("trip/b.png")).unwrap(); |
| 70 | + }) |
| 71 | +} |
| 72 | + |
| 73 | +/// The app with `trip/a.png` and `trip/b.png` imported, and `then` done on disk after. |
| 74 | +fn imported_folder(dir: &Scratch, then: impl FnOnce()) -> Headless { |
65 | 75 | write_png(&dir.path("trip/a.png"), 1); |
66 | 76 | write_png(&dir.path("trip/b.png"), 2); |
67 | 77 | let mut session = lightcraft_engine::Session::new().with_fs(); |
68 | 78 | session.execute("library.import", &json!({"paths": [dir.path("trip")]})).unwrap(); |
69 | | - write_png(&dir.path("trip/c.png"), 3); |
70 | | - std::fs::remove_file(dir.path("trip/b.png")).unwrap(); |
| 79 | + then(); |
71 | 80 | let app = LightcraftApp::new(session, Services { png: None, ..Default::default() }); |
72 | 81 | let mut h = Headless::new(app, [1400.0, 900.0], 1.0); |
73 | 82 | let r = h.request("ui.set", json!({"view": "photoGrid", "leftPanel": true}), T); |
@@ -182,6 +191,42 @@ fn cancel_leaves_the_library_as_it_was() { |
182 | 191 | assert!(h.app.session.folder_changes.is_none(), "the scan is let go"); |
183 | 192 | } |
184 | 193 |
|
| 194 | +fn shown(h: &Headless, widget: &str) -> bool { |
| 195 | + h.app.widgets.iter().any(|(w, _)| w == widget) |
| 196 | +} |
| 197 | + |
| 198 | +#[test] |
| 199 | +fn a_folder_with_nothing_to_bring_in_is_only_reported() { |
| 200 | + let dir = Scratch::new("uptodate"); |
| 201 | + let mut h = imported_folder(&dir, || {}); |
| 202 | + open_and_scan(&mut h, &dir.path("trip")); |
| 203 | + h.step(); |
| 204 | + assert!(shown(&h, "button:dialogOk"), "one button, to close it"); |
| 205 | + for gone in ["button:dialogCancel", "syncImportNew", "syncRelinkMoved", "syncRemoveMissing", "syncReadMetadata"] { |
| 206 | + assert!(!shown(&h, gone), "nothing to choose: {gone}"); |
| 207 | + } |
| 208 | + let r = h.request("ui.clickWidget", json!({"id": "button:dialogOk"}), T); |
| 209 | + assert_eq!(r["ok"], true, "{r}"); |
| 210 | + assert!(h.step_until(T, |h| h.app.ui.dialog.is_none()), "the button closes it"); |
| 211 | + assert!(h.app.sync_run.is_none() && h.app.session.activity.list().is_empty(), "and starts nothing"); |
| 212 | + assert!(h.app.session.folder_changes.is_none(), "the scan is let go"); |
| 213 | + assert_eq!(in_library(&h), vec!["a.png", "b.png"]); |
| 214 | +} |
| 215 | + |
| 216 | +#[test] |
| 217 | +fn confirming_a_folder_with_nothing_to_bring_in_starts_nothing() { |
| 218 | + let dir = Scratch::new("uptodate-agent"); |
| 219 | + let mut h = imported_folder(&dir, || {}); |
| 220 | + open_and_scan(&mut h, &dir.path("trip")); |
| 221 | + let r = h.request("ui.dialog.confirm", json!({}), T); |
| 222 | + assert_eq!(r["ok"], true, "{r}"); |
| 223 | + assert_eq!(r["result"]["upToDate"], true, "{r}"); |
| 224 | + assert!(h.app.ui.dialog.is_none()); |
| 225 | + assert!(h.app.sync_run.is_none() && h.app.session.activity.list().is_empty(), "no job that does nothing"); |
| 226 | + h.step(); |
| 227 | + assert!(h.app.session.folder_changes.is_none(), "the scan is let go"); |
| 228 | +} |
| 229 | + |
185 | 230 | #[test] |
186 | 231 | fn an_agents_scan_is_kept_between_frames() { |
187 | 232 | let dir = Scratch::new("agent"); |
@@ -250,7 +295,7 @@ fn a_synchronize_and_an_import_never_run_at_once() { |
250 | 295 | path: dir.path("trip"), |
251 | 296 | name: "trip".into(), |
252 | 297 | disk: false, |
253 | | - counts: Some(Default::default()), |
| 298 | + counts: Some(crate::state::SyncCounts { new: 1, ..Default::default() }), |
254 | 299 | import_new: true, |
255 | 300 | relink_moved: true, |
256 | 301 | remove_missing: false, |
|
0 commit comments