Browse now skips top-level when it only has one mount
This commit is contained in:
parent
d492afc885
commit
570c2b3894
2 changed files with 35 additions and 5 deletions
src
|
@ -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,
|
||||
|
@ -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.len(), 1);
|
||||
assert_eq!(files[0], File::Directory(PathBuf::from_iter(["Music"])));
|
||||
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[..],
|
||||
[File::Directory(PathBuf::from_iter([
|
||||
"Music",
|
||||
"Iron Maiden"
|
||||
])),]
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -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]
|
||||
|
|
Loading…
Add table
Reference in a new issue