fixed tests
This commit is contained in:
parent
1e770974bb
commit
1952433aa9
11 changed files with 274 additions and 94 deletions
|
@ -11,12 +11,12 @@ class AlbumModel extends Album {
|
|||
@required String title,
|
||||
@required String artist,
|
||||
String albumArtPath,
|
||||
int pubYear,
|
||||
int year,
|
||||
}) : super(
|
||||
title: title,
|
||||
artist: artist,
|
||||
albumArtPath: albumArtPath,
|
||||
pubYear: pubYear,
|
||||
pubYear: year,
|
||||
);
|
||||
|
||||
factory AlbumModel.fromMoorAlbum(MoorAlbum moorAlbum) => AlbumModel(
|
||||
|
@ -24,7 +24,7 @@ class AlbumModel extends Album {
|
|||
title: moorAlbum.title,
|
||||
artist: moorAlbum.artist,
|
||||
albumArtPath: moorAlbum.albumArtPath,
|
||||
pubYear: moorAlbum.year,
|
||||
year: moorAlbum.year,
|
||||
);
|
||||
|
||||
factory AlbumModel.fromAlbumInfo(AlbumInfo albumInfo) {
|
||||
|
@ -35,7 +35,7 @@ class AlbumModel extends Album {
|
|||
title: albumInfo.title,
|
||||
artist: albumInfo.artist,
|
||||
albumArtPath: albumInfo.albumArt,
|
||||
pubYear: _year == null ? null : int.parse(_year),
|
||||
year: _year == null ? null : int.parse(_year),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -7,16 +7,16 @@ import '../../domain/entities/song.dart';
|
|||
import '../datasources/moor_music_data_source.dart';
|
||||
|
||||
class SongModel extends Song {
|
||||
SongModel({
|
||||
@required String title,
|
||||
const SongModel(
|
||||
{@required String title,
|
||||
@required String album,
|
||||
@required this.albumId,
|
||||
@required String artist,
|
||||
@required String path,
|
||||
@required int duration,
|
||||
int trackNumber,
|
||||
String albumArtPath,
|
||||
this.albumId
|
||||
}) : super(
|
||||
String albumArtPath})
|
||||
: super(
|
||||
title: title,
|
||||
album: album,
|
||||
artist: artist,
|
||||
|
@ -53,25 +53,55 @@ class SongModel extends Song {
|
|||
);
|
||||
}
|
||||
|
||||
// TODO: test
|
||||
factory SongModel.fromMediaItem(MediaItem mediaItem) {
|
||||
if (mediaItem == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final String artUri = mediaItem.artUri?.replaceFirst('file://', '');
|
||||
final tn = mediaItem.extras['trackNumber'];
|
||||
int trackNumber;
|
||||
|
||||
if (tn == null) {
|
||||
trackNumber = null;
|
||||
} else {
|
||||
trackNumber = tn as int;
|
||||
}
|
||||
|
||||
return SongModel(
|
||||
title: mediaItem.title,
|
||||
album: mediaItem.album,
|
||||
albumId: mediaItem.extras['albumId'] as int,
|
||||
artist: mediaItem.artist,
|
||||
path: mediaItem.id,
|
||||
duration: mediaItem.duration.inMilliseconds,
|
||||
albumArtPath: artUri,
|
||||
trackNumber: trackNumber,
|
||||
);
|
||||
}
|
||||
|
||||
int albumId;
|
||||
final int albumId;
|
||||
|
||||
SongModel copyWith({
|
||||
String title,
|
||||
String album,
|
||||
String artist,
|
||||
String path,
|
||||
int duration,
|
||||
int trackNumber,
|
||||
String albumArtPath,
|
||||
int albumId,
|
||||
}) =>
|
||||
SongModel(
|
||||
album: album ?? this.album,
|
||||
artist: artist ?? this.artist,
|
||||
duration: duration ?? this.duration,
|
||||
path: path ?? this.path,
|
||||
title: title ?? this.title,
|
||||
trackNumber: trackNumber ?? this.trackNumber,
|
||||
albumArtPath: albumArtPath ?? this.albumArtPath,
|
||||
albumId: albumId ?? this.albumId,
|
||||
);
|
||||
|
||||
SongsCompanion toSongsCompanion() => SongsCompanion(
|
||||
albumTitle: Value(album),
|
||||
|
@ -91,5 +121,9 @@ class SongModel extends Song {
|
|||
artist: artist,
|
||||
duration: Duration(milliseconds: duration),
|
||||
artUri: 'file://$albumArtPath',
|
||||
extras: {
|
||||
'albumId': albumId,
|
||||
'trackNumber': trackNumber,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -69,8 +69,7 @@ class MusicDataRepositoryImpl implements MusicDataRepository {
|
|||
if (storedSong != null) {
|
||||
await musicDataSource.flagSongPresent(storedSong);
|
||||
} else {
|
||||
final SongModel songToInsert = song;
|
||||
songToInsert.albumId = albumIdMap[song.albumId];
|
||||
final SongModel songToInsert = song.copyWith(albumId: albumIdMap[song.albumId]);
|
||||
|
||||
// TODO: fails if albumId is null
|
||||
await musicDataSource.insertSong(songToInsert);
|
||||
|
|
50
test/coverage_helper_test.dart
Normal file
50
test/coverage_helper_test.dart
Normal file
|
@ -0,0 +1,50 @@
|
|||
// Helper file to make coverage work for all dart files\n
|
||||
// ignore_for_file: unused_import
|
||||
import 'package:mucke/domain/entities/album.dart';
|
||||
import 'package:mucke/domain/entities/song.dart';
|
||||
import 'package:mucke/domain/entities/playback_state.dart';
|
||||
import 'package:mucke/domain/entities/artist.dart';
|
||||
import 'package:mucke/domain/usecases/get_albums.dart';
|
||||
import 'package:mucke/domain/usecases/get_songs.dart';
|
||||
import 'package:mucke/domain/usecases/update_database.dart';
|
||||
import 'package:mucke/domain/repositories/music_data_repository.dart';
|
||||
import 'package:mucke/domain/repositories/audio_repository.dart';
|
||||
import 'package:mucke/main.dart';
|
||||
import 'package:mucke/core/usecase.dart';
|
||||
import 'package:mucke/core/error/failures.dart';
|
||||
import 'package:mucke/presentation/state/audio_store.dart';
|
||||
import 'package:mucke/presentation/state/navigation_store.dart';
|
||||
import 'package:mucke/presentation/state/music_data_store.dart';
|
||||
import 'package:mucke/presentation/utils.dart';
|
||||
import 'package:mucke/presentation/theming.dart';
|
||||
import 'package:mucke/presentation/pages/home_page.dart';
|
||||
import 'package:mucke/presentation/pages/songs_page.dart';
|
||||
import 'package:mucke/presentation/pages/currently_playing.dart';
|
||||
import 'package:mucke/presentation/pages/albums_page.dart';
|
||||
import 'package:mucke/presentation/pages/library_tab_container.dart';
|
||||
import 'package:mucke/presentation/pages/settings_page.dart';
|
||||
import 'package:mucke/presentation/pages/album_details_page.dart';
|
||||
import 'package:mucke/presentation/pages/library_page.dart';
|
||||
import 'package:mucke/presentation/widgets/currently_playing_bar.dart';
|
||||
import 'package:mucke/presentation/widgets/queue_card.dart';
|
||||
import 'package:mucke/presentation/widgets/injection_widget.dart';
|
||||
import 'package:mucke/presentation/widgets/play_pause_button.dart';
|
||||
import 'package:mucke/presentation/widgets/album_art.dart';
|
||||
import 'package:mucke/presentation/widgets/navbar.dart';
|
||||
import 'package:mucke/presentation/widgets/time_progress_indicator.dart';
|
||||
import 'package:mucke/presentation/widgets/audio_service_widget.dart';
|
||||
import 'package:mucke/presentation/widgets/album_art_list_tile.dart';
|
||||
import 'package:mucke/system/datasources/music_data_source_contract.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher.dart';
|
||||
import 'package:mucke/system/datasources/audio_manager.dart';
|
||||
import 'package:mucke/system/datasources/audio_player_task.dart';
|
||||
import 'package:mucke/system/datasources/moor_music_data_source.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher_contract.dart';
|
||||
import 'package:mucke/system/datasources/audio_manager_contract.dart';
|
||||
import 'package:mucke/system/repositories/audio_repository_impl.dart';
|
||||
import 'package:mucke/system/repositories/music_data_repository_impl.dart';
|
||||
import 'package:mucke/system/models/playback_state_model.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
import 'package:mucke/injection_container.dart';
|
||||
void main(){}
|
|
@ -27,6 +27,7 @@ void main() {
|
|||
setUp(() {
|
||||
mockAlbumInfo = MockAlbumInfo();
|
||||
when(mockAlbumInfo.title).thenReturn(ALBUM_TITLE_1);
|
||||
when(mockAlbumInfo.id).thenReturn(ID_1.toString());
|
||||
when(mockAlbumInfo.albumArt).thenReturn(ALBUM_ART_PATH_1);
|
||||
when(mockAlbumInfo.artist).thenReturn(ARTIST_1);
|
||||
when(mockAlbumInfo.firstYear).thenReturn(FIRST_YEAR_1.toString());
|
||||
|
@ -70,8 +71,11 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
mockSongInfo = MockSongInfo();
|
||||
when(mockSongInfo.isMusic).thenReturn(true);
|
||||
|
||||
when(mockSongInfo.title).thenReturn(SONG_TITLE_3);
|
||||
when(mockSongInfo.album).thenReturn(ALBUM_TITLE_3);
|
||||
when(mockSongInfo.albumId).thenReturn(ALBUM_ID_3.toString());
|
||||
when(mockSongInfo.artist).thenReturn(ARTIST_3);
|
||||
when(mockSongInfo.filePath).thenReturn(PATH_3);
|
||||
when(mockSongInfo.track).thenReturn(TRACKNUMBER_3.toString());
|
||||
|
|
|
@ -19,12 +19,13 @@ void main() {
|
|||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
songModel = SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
|
|
|
@ -15,7 +15,7 @@ void main() {
|
|||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
test(
|
||||
|
@ -42,7 +42,7 @@ void main() {
|
|||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = albumModel.toAlbumsCompanion();
|
||||
|
@ -61,17 +61,20 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
present: PRESENT_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromMoorAlbum(moorAlbum);
|
||||
|
@ -85,15 +88,18 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
year: YEAR_1,
|
||||
present: PRESENT_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromMoorAlbum(moorAlbum);
|
||||
|
@ -107,9 +113,11 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
present: PRESENT_1,
|
||||
);
|
||||
|
||||
final expected = AlbumModel(
|
||||
|
@ -130,6 +138,7 @@ void main() {
|
|||
|
||||
setUp(() {
|
||||
mockAlbumInfo = MockAlbumInfo();
|
||||
when(mockAlbumInfo.id).thenReturn(ID_1.toString());
|
||||
when(mockAlbumInfo.title).thenReturn(ALBUM_TITLE_1);
|
||||
when(mockAlbumInfo.albumArt).thenReturn(ALBUM_ART_PATH_1);
|
||||
when(mockAlbumInfo.artist).thenReturn(ARTIST_1);
|
||||
|
@ -143,10 +152,11 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final expected = AlbumModel(
|
||||
id: ID_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: FIRST_YEAR_1,
|
||||
year: FIRST_YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromAlbumInfo(mockAlbumInfo);
|
||||
|
|
|
@ -15,6 +15,7 @@ void main() {
|
|||
final tSongModel = SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
|
@ -23,7 +24,7 @@ void main() {
|
|||
);
|
||||
|
||||
test(
|
||||
'should be subclass of Album entity',
|
||||
'should be subclass of Song entity',
|
||||
() async {
|
||||
// assert
|
||||
expect(tSongModel, isA<Song>());
|
||||
|
@ -36,7 +37,8 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final expected = SongsCompanion(
|
||||
album: Value(ALBUM_TITLE_3),
|
||||
albumTitle: Value(ALBUM_TITLE_3),
|
||||
albumId: Value(ALBUM_ID_3),
|
||||
artist: Value(ARTIST_3),
|
||||
title: Value(SONG_TITLE_3),
|
||||
path: Value(PATH_3),
|
||||
|
@ -47,6 +49,7 @@ void main() {
|
|||
|
||||
final songModel = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
|
@ -57,7 +60,8 @@ void main() {
|
|||
// act
|
||||
final result = songModel.toSongsCompanion();
|
||||
// assert
|
||||
expect(result.album.value, expected.album.value);
|
||||
expect(result.albumTitle.value, expected.albumTitle.value);
|
||||
expect(result.albumId.value, expected.albumId.value);
|
||||
expect(result.artist.value, expected.artist.value);
|
||||
expect(result.title.value, expected.title.value);
|
||||
expect(result.path.value, expected.path.value);
|
||||
|
@ -79,10 +83,14 @@ void main() {
|
|||
artist: ARTIST_3,
|
||||
duration: Duration(milliseconds: DURATION_3),
|
||||
artUri: 'file://$ALBUM_ART_PATH_3',
|
||||
);
|
||||
extras: {
|
||||
'albumId': ALBUM_ID_3,
|
||||
'trackNumber': TRACKNUMBER_3,
|
||||
});
|
||||
|
||||
final songModel = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
|
@ -99,6 +107,7 @@ void main() {
|
|||
expect(result.id, expected.id);
|
||||
expect(result.duration, expected.duration);
|
||||
expect(result.artUri, expected.artUri);
|
||||
expect(result.extras, expected.extras);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
@ -109,17 +118,20 @@ void main() {
|
|||
() async {
|
||||
// arrange
|
||||
final moorSong = MoorSong(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumTitle: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
present: PRESENT_3,
|
||||
);
|
||||
|
||||
final expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
|
@ -135,12 +147,13 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
group('fromAlbumInfo', () {
|
||||
group('fromSongInfo', () {
|
||||
MockSongInfo mockSongInfo;
|
||||
|
||||
setUp(() {
|
||||
mockSongInfo = MockSongInfo();
|
||||
when(mockSongInfo.album).thenReturn(ALBUM_TITLE_3);
|
||||
when(mockSongInfo.albumId).thenReturn(ALBUM_ID_3.toString());
|
||||
when(mockSongInfo.artist).thenReturn(ARTIST_3);
|
||||
when(mockSongInfo.title).thenReturn(SONG_TITLE_3);
|
||||
when(mockSongInfo.albumArtwork).thenReturn(ALBUM_ART_PATH_3);
|
||||
|
@ -155,6 +168,7 @@ void main() {
|
|||
// arrange
|
||||
final expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
|
@ -169,4 +183,115 @@ void main() {
|
|||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('fromMediaItem', () {
|
||||
test(
|
||||
'should create valid SongModel from MediaItem',
|
||||
() async {
|
||||
// arrange
|
||||
final mediaItem = MediaItem(
|
||||
id: PATH_3,
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
artist: ARTIST_3,
|
||||
duration: Duration(milliseconds: DURATION_3),
|
||||
artUri: 'file://$ALBUM_ART_PATH_3',
|
||||
extras: {
|
||||
'albumId': ALBUM_ID_3,
|
||||
'trackNumber': TRACKNUMBER_3,
|
||||
},
|
||||
);
|
||||
|
||||
final expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = SongModel.fromMediaItem(mediaItem);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should return null',
|
||||
() async {
|
||||
// arrange
|
||||
const mediaItem = null;
|
||||
const expected = null;
|
||||
// act
|
||||
final result = SongModel.fromMediaItem(mediaItem as MediaItem);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('copyWith', () {
|
||||
SongModel songModel;
|
||||
|
||||
setUp(() {
|
||||
songModel = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'should create SongModel with same values',
|
||||
() async {
|
||||
// arrange
|
||||
final expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = songModel.copyWith();
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should create SongModel with different album and albumId',
|
||||
() async {
|
||||
// arrange
|
||||
final expected = SongModel(
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = songModel.copyWith(
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ List<SongModel> setupSongList() => [
|
|||
SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
|
@ -46,6 +47,7 @@ List<SongModel> setupSongList() => [
|
|||
SongModel(
|
||||
title: SONG_TITLE_4,
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_4,
|
||||
path: PATH_4,
|
||||
duration: DURATION_4,
|
||||
|
|
|
@ -100,61 +100,7 @@ void main() {
|
|||
});
|
||||
|
||||
group('updateDatabase', () {
|
||||
setUp(() {
|
||||
when(mockLocalMusicFetcher.getSongs())
|
||||
.thenAnswer((_) async => tEmptySongList);
|
||||
when(mockMusicDataSource.songExists(any)).thenAnswer((_) async => false);
|
||||
});
|
||||
|
||||
test(
|
||||
'should fetch list of albums from LocalMusicFetcher',
|
||||
() async {
|
||||
when(mockLocalMusicFetcher.getAlbums())
|
||||
.thenAnswer((_) async => tAlbumList);
|
||||
|
||||
when(mockMusicDataSource.albumExists(any))
|
||||
.thenAnswer((_) async => false);
|
||||
// act
|
||||
repository.updateDatabase();
|
||||
// assert
|
||||
verify(mockLocalMusicFetcher.getAlbums());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should insert fetched albums to MusicDataSource',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockLocalMusicFetcher.getAlbums())
|
||||
.thenAnswer((_) async => tAlbumList);
|
||||
when(mockMusicDataSource.albumExists(any))
|
||||
.thenAnswer((_) async => false);
|
||||
// act
|
||||
await repository.updateDatabase();
|
||||
// assert
|
||||
for (final album in tAlbumList) {
|
||||
verify(mockMusicDataSource.insertAlbum(album));
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should not insert albums that are already stored in MusicDataSource',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockLocalMusicFetcher.getAlbums())
|
||||
.thenAnswer((_) async => tAlbumList);
|
||||
when(mockMusicDataSource.albumExists(tAlbumList[0]))
|
||||
.thenAnswer((_) async => true);
|
||||
when(mockMusicDataSource.albumExists(tAlbumList[1]))
|
||||
.thenAnswer((_) async => false);
|
||||
// act
|
||||
await repository.updateDatabase();
|
||||
// assert
|
||||
verifyNever(mockMusicDataSource.insertAlbum(tAlbumList[0]));
|
||||
verify(mockMusicDataSource.insertAlbum(tAlbumList[1]));
|
||||
},
|
||||
);
|
||||
// TODO: testing
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -163,13 +109,13 @@ List<AlbumModel> setupAlbumList() => [
|
|||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
pubYear: YEAR_1,
|
||||
year: YEAR_1,
|
||||
),
|
||||
AlbumModel(
|
||||
artist: ARTIST_2,
|
||||
title: ALBUM_TITLE_2,
|
||||
albumArtPath: ALBUM_ART_PATH_2,
|
||||
pubYear: YEAR_2,
|
||||
year: YEAR_2,
|
||||
),
|
||||
];
|
||||
|
||||
|
@ -177,6 +123,7 @@ List<SongModel> setupSongList() => [
|
|||
SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
|
@ -186,6 +133,7 @@ List<SongModel> setupSongList() => [
|
|||
SongModel(
|
||||
title: SONG_TITLE_4,
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_4,
|
||||
path: PATH_4,
|
||||
duration: DURATION_4,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
|
||||
// Albums
|
||||
const int ID_1 = 1;
|
||||
const String ALBUM_TITLE_1 = 'Back in Black';
|
||||
const String ARTIST_1 = 'AC/DC';
|
||||
const String ALBUM_ART_PATH_1 = '/music/acdc/backinblack.jpg';
|
||||
|
@ -7,7 +8,9 @@ const int YEAR_1 = 1980;
|
|||
const int FIRST_YEAR_1 = 1979;
|
||||
const int LAST_YEAR_1 = 1980;
|
||||
const int NUM_SONGS_1 = 10;
|
||||
const bool PRESENT_1 = true;
|
||||
|
||||
const int ID_2 = 2;
|
||||
const String ALBUM_TITLE_2 = 'Twilight Of The Thunder God';
|
||||
const String ARTIST_2 = 'Amon Amarth';
|
||||
const String ALBUM_ART_PATH_2 = '/music/amon-amarth/twilight.jpg';
|
||||
|
@ -18,15 +21,19 @@ const int YEAR_2 = 2008;
|
|||
const String SONG_TITLE_3 = 'Bottom Feeder';
|
||||
const String ALBUM_TITLE_3 = 'Ire';
|
||||
const String ARTIST_3 = 'Parkway Drive';
|
||||
const int ALBUM_ID_3 = 3;
|
||||
const String PATH_3 = '/music/parkwaydrive/bottom_feeder.mp3';
|
||||
const int DURATION_3 = 180000;
|
||||
const String ALBUM_ART_PATH_3 = '/music/parkwaydrive/ire.jpg';
|
||||
const int TRACKNUMBER_3 = 7;
|
||||
const bool PRESENT_3 = true;
|
||||
|
||||
const String SONG_TITLE_4 = 'Black Flame';
|
||||
const String ALBUM_TITLE_4 = 'Black Flame';
|
||||
const int ALBUM_ID_4 = 4;
|
||||
const String ARTIST_4 = 'Bury Tomorrow';
|
||||
const String PATH_4 = '/music/burytomorrow/blackflame.mp3';
|
||||
const int DURATION_4 = 240000;
|
||||
const String ALBUM_ART_PATH_4 = '/music/parkwaydrive/blackflame.jpg';
|
||||
const int TRACKNUMBER_4 = 3;
|
||||
const bool PRESENT_4 = false;
|
Loading…
Add table
Reference in a new issue