Provide a keyboard shortcut to pull all release groups of an artist #233
@ -144,17 +144,26 @@ impl AlbumStatus {
|
||||
}
|
||||
|
||||
impl Album {
|
||||
pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>(
|
||||
id: Id,
|
||||
date: Date,
|
||||
pub fn new<Id: Into<AlbumId>>(id: Id) -> Self {
|
||||
Album {
|
||||
meta: AlbumMeta::new(id),
|
||||
tracks: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self {
|
||||
self.meta.date = date.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_type<Id: Into<AlbumId>, Date: Into<AlbumDate>>(
|
||||
mut self,
|
||||
primary_type: Option<AlbumPrimaryType>,
|
||||
secondary_types: Vec<AlbumSecondaryType>,
|
||||
) -> Self {
|
||||
let info = AlbumInfo::new(MbRefOption::None, primary_type, secondary_types);
|
||||
Album {
|
||||
meta: AlbumMeta::new(id, date, info),
|
||||
tracks: vec![],
|
||||
}
|
||||
self.meta.info.primary_type = primary_type;
|
||||
self.meta.info.secondary_types = secondary_types;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_status(&self) -> AlbumStatus {
|
||||
@ -183,19 +192,25 @@ impl Merge for Album {
|
||||
}
|
||||
|
||||
impl AlbumMeta {
|
||||
pub fn new<Id: Into<AlbumId>, Date: Into<AlbumDate>>(
|
||||
id: Id,
|
||||
date: Date,
|
||||
info: AlbumInfo,
|
||||
) -> Self {
|
||||
pub fn new<Id: Into<AlbumId>>(id: Id) -> Self {
|
||||
AlbumMeta {
|
||||
id: id.into(),
|
||||
date: date.into(),
|
||||
date: AlbumDate::default(),
|
||||
seq: AlbumSeq::default(),
|
||||
info,
|
||||
info: AlbumInfo::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_date<Date: Into<AlbumDate>>(mut self, date: Date) -> Self {
|
||||
self.date = date.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_info(mut self, info: AlbumInfo) -> Self {
|
||||
self.info = info;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn get_sort_key(&self) -> (&AlbumDate, &AlbumSeq, &AlbumId) {
|
||||
(&self.date, &self.seq, &self.id)
|
||||
}
|
||||
@ -313,13 +328,13 @@ mod tests {
|
||||
let album_id_1 = AlbumId {
|
||||
title: String::from("album z"),
|
||||
};
|
||||
let mut album_1 = Album::new(album_id_1, date.clone(), None, vec![]);
|
||||
let mut album_1 = Album::new(album_id_1).with_date(date.clone());
|
||||
album_1.meta.set_seq(AlbumSeq(1));
|
||||
|
||||
let album_id_2 = AlbumId {
|
||||
title: String::from("album a"),
|
||||
};
|
||||
let mut album_2 = Album::new(album_id_2, date.clone(), None, vec![]);
|
||||
let mut album_2 = Album::new(album_id_2).with_date(date.clone());
|
||||
album_2.meta.set_seq(AlbumSeq(2));
|
||||
|
||||
assert_ne!(album_1, album_2);
|
||||
@ -329,7 +344,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn set_clear_seq() {
|
||||
let mut album = Album::new("An album", AlbumDate::default(), None, vec![]);
|
||||
let mut album = Album::new("An album");
|
||||
|
||||
assert_eq!(album.meta.seq, AlbumSeq(0));
|
||||
|
||||
|
@ -392,7 +392,7 @@ mod tests {
|
||||
musicbrainz::{MbArtistRef, MbRefOption},
|
||||
},
|
||||
core::{
|
||||
collection::{album::AlbumDate, artist::ArtistId},
|
||||
collection::artist::ArtistId,
|
||||
interface::database::{self, MockIDatabase},
|
||||
musichoard::{base::IMusicHoardBase, NoLibrary},
|
||||
testmod::FULL_COLLECTION,
|
||||
@ -652,6 +652,62 @@ mod tests {
|
||||
assert!(music_hoard.collection[0].meta.info.properties.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn album_new_delete() {
|
||||
let album_id = AlbumId::new("an album");
|
||||
let album_meta = AlbumMeta::new(album_id.clone());
|
||||
let album_id_2 = AlbumId::new("another album");
|
||||
let album_meta_2 = AlbumMeta::new(album_id_2);
|
||||
|
||||
let collection = FULL_COLLECTION.to_owned();
|
||||
let artist_id = collection[0].meta.id.clone();
|
||||
let mut with_album = collection.clone();
|
||||
with_album[0].albums.push(Album::new(album_id));
|
||||
with_album[0].albums.sort_unstable();
|
||||
|
||||
let mut database = MockIDatabase::new();
|
||||
let mut seq = Sequence::new();
|
||||
database
|
||||
.expect_load()
|
||||
.times(1)
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.returning(|| Ok(FULL_COLLECTION.to_owned()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(with_album.clone()))
|
||||
.returning(|_| Ok(()));
|
||||
database
|
||||
.expect_save()
|
||||
.times(1)
|
||||
.in_sequence(&mut seq)
|
||||
.with(predicate::eq(collection.clone()))
|
||||
.returning(|_| Ok(()));
|
||||
|
||||
let mut music_hoard = MusicHoard::database(database).unwrap();
|
||||
assert_eq!(music_hoard.collection, collection);
|
||||
|
||||
assert!(music_hoard
|
||||
.add_album(&artist_id, album_meta.clone())
|
||||
.is_ok());
|
||||
assert_eq!(music_hoard.collection, with_album);
|
||||
|
||||
assert!(music_hoard
|
||||
.add_album(&artist_id, album_meta.clone())
|
||||
.is_ok());
|
||||
assert_eq!(music_hoard.collection, with_album);
|
||||
|
||||
assert!(music_hoard
|
||||
.remove_album(&artist_id, &album_meta_2.id)
|
||||
.is_ok());
|
||||
assert_eq!(music_hoard.collection, with_album);
|
||||
|
||||
assert!(music_hoard.remove_album(&artist_id, &album_meta.id).is_ok());
|
||||
assert_eq!(music_hoard.collection, collection);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn set_clear_album_seq() {
|
||||
let mut database = MockIDatabase::new();
|
||||
@ -661,12 +717,7 @@ mod tests {
|
||||
let album_id_2 = AlbumId::new("another album");
|
||||
|
||||
let mut database_result = vec![Artist::new(artist_id.clone())];
|
||||
database_result[0].albums.push(Album::new(
|
||||
album_id.clone(),
|
||||
AlbumDate::default(),
|
||||
None,
|
||||
vec![],
|
||||
));
|
||||
database_result[0].albums.push(Album::new(album_id.clone()));
|
||||
|
||||
database
|
||||
.expect_load()
|
||||
@ -706,12 +757,7 @@ mod tests {
|
||||
let album_id_2 = AlbumId::new("another album");
|
||||
|
||||
let mut database_result = vec![Artist::new(artist_id.clone())];
|
||||
database_result[0].albums.push(Album::new(
|
||||
album_id.clone(),
|
||||
AlbumDate::default(),
|
||||
None,
|
||||
vec![],
|
||||
));
|
||||
database_result[0].albums.push(Album::new(album_id.clone()));
|
||||
|
||||
database
|
||||
.expect_load()
|
||||
|
@ -109,7 +109,7 @@ impl<Database, Library: ILibrary> MusicHoard<Database, Library> {
|
||||
{
|
||||
Some(album) => album.tracks.push(track),
|
||||
None => {
|
||||
let mut album = Album::new(album_id, album_date, None, vec![]);
|
||||
let mut album = Album::new(album_id).with_date(album_date);
|
||||
album.tracks.push(track);
|
||||
artist.albums.push(album);
|
||||
}
|
||||
|
@ -319,15 +319,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn album_meta(id: AlbumId) -> AlbumMeta {
|
||||
AlbumMeta::new(
|
||||
id,
|
||||
AlbumDate::new(Some(1990), Some(5), None),
|
||||
AlbumInfo::new(
|
||||
AlbumMeta::new(id)
|
||||
.with_date(AlbumDate::new(Some(1990), Some(5), None))
|
||||
.with_info(AlbumInfo::new(
|
||||
MbRefOption::Some(mbid().into()),
|
||||
Some(AlbumPrimaryType::Album),
|
||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||
),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn album_match() -> EntityMatches {
|
||||
@ -625,7 +623,7 @@ mod tests {
|
||||
fn select_manual_input_album() {
|
||||
let mut mb_job_sender = MockIMbJobSender::new();
|
||||
let artist_id = ArtistId::new("Artist");
|
||||
let album = AlbumMeta::new("Album", 1990, AlbumInfo::default());
|
||||
let album = AlbumMeta::new("Album").with_date(1990);
|
||||
let requests = VecDeque::from([MbParams::lookup_release_group(
|
||||
artist_id.clone(),
|
||||
album.id.clone(),
|
||||
|
@ -289,9 +289,7 @@ mod tests {
|
||||
#[test]
|
||||
fn empty_album() {
|
||||
let mut artists: Vec<Artist> = vec![Artist::new(ArtistId::new("An artist"))];
|
||||
artists[0]
|
||||
.albums
|
||||
.push(Album::new("An album", AlbumDate::default(), None, vec![]));
|
||||
artists[0].albums.push(Album::new("An album"));
|
||||
let mut selection = Selection::new(&artists);
|
||||
|
||||
draw_test_suite(&artists, &mut selection);
|
||||
@ -361,15 +359,13 @@ mod tests {
|
||||
}
|
||||
|
||||
fn album_meta(id: AlbumId) -> AlbumMeta {
|
||||
AlbumMeta::new(
|
||||
id,
|
||||
AlbumDate::new(Some(1990), Some(5), None),
|
||||
AlbumInfo::new(
|
||||
AlbumMeta::new(id)
|
||||
.with_date(AlbumDate::new(Some(1990), Some(5), None))
|
||||
.with_info(AlbumInfo::new(
|
||||
MbRefOption::None,
|
||||
Some(AlbumPrimaryType::Album),
|
||||
vec![AlbumSecondaryType::Live, AlbumSecondaryType::Compilation],
|
||||
),
|
||||
)
|
||||
))
|
||||
}
|
||||
|
||||
fn album_matches() -> EntityMatches {
|
||||
|
Loading…
x
Reference in New Issue
Block a user