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
|
@ -70,6 +70,12 @@ impl Browser {
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.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| {
|
files.sort_by(|a, b| {
|
||||||
let (a, b) = match (a, b) {
|
let (a, b) = match (a, b) {
|
||||||
(File::Directory(_), File::Song(_)) => return Ordering::Less,
|
(File::Directory(_), File::Song(_)) => return Ordering::Less,
|
||||||
|
@ -224,11 +230,35 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_browse_top_level() {
|
fn can_browse_top_level() {
|
||||||
let song_a = PathBuf::from_iter(["Music", "Iron Maiden", "Moonchild.mp3"]);
|
let (browser, strings) = setup_test(HashSet::from([
|
||||||
let (browser, strings) = setup_test(HashSet::from([song_a]));
|
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();
|
let files = browser.browse(&strings, PathBuf::new()).unwrap();
|
||||||
assert_eq!(files.len(), 1);
|
assert_eq!(
|
||||||
assert_eq!(files[0], File::Directory(PathBuf::from_iter(["Music"])));
|
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]
|
#[test]
|
||||||
|
|
|
@ -28,7 +28,7 @@ async fn browse_root() {
|
||||||
.await;
|
.await;
|
||||||
assert_eq!(response.status(), StatusCode::OK);
|
assert_eq!(response.status(), StatusCode::OK);
|
||||||
let entries = response.body();
|
let entries = response.body();
|
||||||
assert_eq!(entries.len(), 1);
|
assert!(entries.len() > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|
Loading…
Add table
Reference in a new issue