Skip to content

Commit

Permalink
Browse now skips top-level when it only has one mount
Browse files Browse the repository at this point in the history
  • Loading branch information
agersant committed Aug 16, 2024
1 parent d492afc commit 570c2b3
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
38 changes: 34 additions & 4 deletions src/app/index/browser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ impl Browser {
})
.collect::<Vec<_>>();

if virtual_path.as_ref().parent().is_none() {
if let [File::Directory(ref p)] = files[..] {
return self.browse(strings, p);
}
}

files.sort_by(|a, b| {
let (a, b) = match (a, b) {
(File::Directory(_), File::Song(_)) => return Ordering::Less,
Expand Down Expand Up @@ -224,11 +230,35 @@ mod test {

#[test]
fn can_browse_top_level() {
let song_a = PathBuf::from_iter(["Music", "Iron Maiden", "Moonchild.mp3"]);
let (browser, strings) = setup_test(HashSet::from([song_a]));
let (browser, strings) = setup_test(HashSet::from([
PathBuf::from_iter(["Music", "Iron Maiden", "Moonchild.mp3"]),
PathBuf::from_iter(["Also Music", "Iron Maiden", "The Prisoner.mp3"]),
]));
let files = browser.browse(&strings, PathBuf::new()).unwrap();
assert_eq!(
files[..],
[
File::Directory(PathBuf::from_iter(["Also Music"])),
File::Directory(PathBuf::from_iter(["Music"])),
]
);
}

#[test]
fn browse_skips_redundant_top_level() {
let (browser, strings) = setup_test(HashSet::from([PathBuf::from_iter([
"Music",
"Iron Maiden",
"Moonchild.mp3",
])]));
let files = browser.browse(&strings, PathBuf::new()).unwrap();
assert_eq!(files.len(), 1);
assert_eq!(files[0], File::Directory(PathBuf::from_iter(["Music"])));
assert_eq!(
files[..],
[File::Directory(PathBuf::from_iter([
"Music",
"Iron Maiden"
])),]
);
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion src/server/test/collection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ async fn browse_root() {
.await;
assert_eq!(response.status(), StatusCode::OK);
let entries = response.body();
assert_eq!(entries.len(), 1);
assert!(entries.len() > 0);
}

#[tokio::test]
Expand Down

0 comments on commit 570c2b3

Please sign in to comment.