removed tests
This commit is contained in:
parent
af17a97778
commit
3edc5c2ff1
9 changed files with 0 additions and 1129 deletions
|
@ -1,54 +0,0 @@
|
|||
// Helper file to make coverage work for all dart files\n
|
||||
// ignore_for_file: unused_import
|
||||
import 'package:mucke/injection_container.dart';
|
||||
import 'package:mucke/system/repositories/audio_repository_impl.dart';
|
||||
import 'package:mucke/system/repositories/music_data_repository_impl.dart';
|
||||
import 'package:mucke/system/audio/audio_manager_contract.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher_contract.dart';
|
||||
import 'package:mucke/system/audio/audio_manager.dart';
|
||||
import 'package:mucke/system/datasources/moor_database.dart';
|
||||
import 'package:mucke/system/audio/queue_generator.dart';
|
||||
import 'package:mucke/system/datasources/music_data_source_contract.dart';
|
||||
import 'package:mucke/system/models/artist_model.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
import 'package:mucke/system/models/playback_state_model.dart';
|
||||
import 'package:mucke/main.dart';
|
||||
import 'package:mucke/presentation/state/music_data_store.dart';
|
||||
import 'package:mucke/presentation/state/navigation_store.dart';
|
||||
import 'package:mucke/presentation/state/audio_store.dart';
|
||||
import 'package:mucke/presentation/widgets/next_indicator.dart';
|
||||
import 'package:mucke/presentation/widgets/previous_button.dart';
|
||||
import 'package:mucke/presentation/widgets/play_pause_button.dart';
|
||||
import 'package:mucke/presentation/widgets/album_art.dart';
|
||||
import 'package:mucke/presentation/widgets/shuffle_button.dart';
|
||||
import 'package:mucke/presentation/widgets/injection_widget.dart';
|
||||
import 'package:mucke/presentation/widgets/next_song.dart';
|
||||
import 'package:mucke/presentation/widgets/queue_card.dart';
|
||||
import 'package:mucke/presentation/widgets/playback_control.dart';
|
||||
import 'package:mucke/presentation/widgets/album_art_list_tile.dart';
|
||||
import 'package:mucke/presentation/widgets/navbar.dart';
|
||||
import 'package:mucke/presentation/widgets/time_progress_indicator.dart';
|
||||
import 'package:mucke/presentation/widgets/next_button.dart';
|
||||
import 'package:mucke/presentation/widgets/currently_playing_bar.dart';
|
||||
import 'package:mucke/presentation/theming.dart';
|
||||
import 'package:mucke/presentation/utils.dart';
|
||||
import 'package:mucke/presentation/pages/library_page.dart';
|
||||
import 'package:mucke/presentation/pages/settings_page.dart';
|
||||
import 'package:mucke/presentation/pages/library_tab_container.dart';
|
||||
import 'package:mucke/presentation/pages/songs_page.dart';
|
||||
import 'package:mucke/presentation/pages/queue_page.dart';
|
||||
import 'package:mucke/presentation/pages/home_page.dart';
|
||||
import 'package:mucke/presentation/pages/albums_page.dart';
|
||||
import 'package:mucke/presentation/pages/album_details_page.dart';
|
||||
import 'package:mucke/presentation/pages/currently_playing.dart';
|
||||
import 'package:mucke/presentation/pages/artists_page.dart';
|
||||
import 'package:mucke/domain/repositories/audio_repository.dart';
|
||||
import 'package:mucke/domain/repositories/music_data_repository.dart';
|
||||
import 'package:mucke/domain/entities/shuffle_mode.dart';
|
||||
import 'package:mucke/domain/entities/album.dart';
|
||||
import 'package:mucke/domain/entities/artist.dart';
|
||||
import 'package:mucke/domain/entities/song.dart';
|
||||
import 'package:mucke/domain/entities/playback_state.dart';
|
||||
void main(){}
|
|
@ -1,176 +0,0 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:meta/meta.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mucke/core/error/failures.dart';
|
||||
import 'package:mucke/domain/entities/artist.dart';
|
||||
import 'package:mucke/domain/repositories/music_data_repository.dart';
|
||||
import 'package:mucke/presentation/state/music_data_store.dart';
|
||||
|
||||
class MockMusicDataRepository extends Mock implements MusicDataRepository {}
|
||||
|
||||
class MockInitMusicDataStore extends MusicDataStore {
|
||||
MockInitMusicDataStore({@required MusicDataRepository musicDataRepository})
|
||||
: super(musicDataRepository: musicDataRepository);
|
||||
|
||||
int fetchArtistsCalled = 0;
|
||||
int fetchAlbumsCalled = 0;
|
||||
int fetchSongsCalled = 0;
|
||||
|
||||
@override
|
||||
Future<void> fetchArtists() async {
|
||||
fetchArtistsCalled++;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> fetchAlbums() async {
|
||||
fetchAlbumsCalled++;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> fetchSongs() async {
|
||||
fetchSongsCalled++;
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('init', () {
|
||||
MockMusicDataRepository mockMusicDataRepository;
|
||||
|
||||
setUp(() {
|
||||
mockMusicDataRepository = MockMusicDataRepository();
|
||||
});
|
||||
|
||||
test(
|
||||
'should fetch artists, albums and songs from the database',
|
||||
() async {
|
||||
// arrange
|
||||
final MockInitMusicDataStore mockInitMusicDataStore =
|
||||
MockInitMusicDataStore(
|
||||
musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
mockInitMusicDataStore.init();
|
||||
|
||||
// assert
|
||||
expect(mockInitMusicDataStore.fetchArtistsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchAlbumsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchSongsCalled, 1);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should only fetch data once',
|
||||
() async {
|
||||
// arrange
|
||||
final MockInitMusicDataStore mockInitMusicDataStore =
|
||||
MockInitMusicDataStore(
|
||||
musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
mockInitMusicDataStore.init();
|
||||
mockInitMusicDataStore.init();
|
||||
|
||||
// assert
|
||||
expect(mockInitMusicDataStore.fetchArtistsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchAlbumsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchSongsCalled, 1);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('updateDatabase', () {
|
||||
|
||||
MockMusicDataRepository mockMusicDataRepository;
|
||||
|
||||
setUp(() {
|
||||
mockMusicDataRepository = MockMusicDataRepository();
|
||||
});
|
||||
|
||||
test(
|
||||
'should trigger update',
|
||||
() async {
|
||||
// arrange
|
||||
final MockInitMusicDataStore mockInitMusicDataStore =
|
||||
MockInitMusicDataStore(
|
||||
musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
await mockInitMusicDataStore.updateDatabase();
|
||||
|
||||
// assert
|
||||
verify(mockMusicDataRepository.updateDatabase());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should fetch artists, albums and songs into store',
|
||||
() async {
|
||||
// arrange
|
||||
final MockInitMusicDataStore mockInitMusicDataStore =
|
||||
MockInitMusicDataStore(
|
||||
musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
await mockInitMusicDataStore.updateDatabase();
|
||||
|
||||
// assert
|
||||
expect(mockInitMusicDataStore.fetchArtistsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchAlbumsCalled, 1);
|
||||
expect(mockInitMusicDataStore.fetchSongsCalled, 1);
|
||||
},
|
||||
);
|
||||
|
||||
});
|
||||
|
||||
group('fetchArtists', () {
|
||||
MockMusicDataRepository mockMusicDataRepository;
|
||||
const List<Artist> artists = [
|
||||
Artist(name: 'AC/DC'),
|
||||
Artist(name: 'Amon Amarth'),
|
||||
];
|
||||
|
||||
const Either<Failure, List<Artist>> success =
|
||||
Right<Failure, List<Artist>>(artists);
|
||||
|
||||
final Either<Failure, List<Artist>> failure = Left(GenericFailure());
|
||||
|
||||
setUp(() {
|
||||
mockMusicDataRepository = MockMusicDataRepository();
|
||||
});
|
||||
|
||||
test(
|
||||
'should store a list of artists on success',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataRepository.getArtists())
|
||||
.thenAnswer((_) => Future.value(success));
|
||||
|
||||
final musicDataStore = MusicDataStore(musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
await musicDataStore.fetchArtists();
|
||||
|
||||
// assert
|
||||
expect(musicDataStore.artists.toList(), artists);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should store an empty list of artists on failure',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataRepository.getArtists())
|
||||
.thenAnswer((_) => Future.value(failure));
|
||||
|
||||
final musicDataStore = MusicDataStore(musicDataRepository: mockMusicDataRepository);
|
||||
|
||||
// act
|
||||
await musicDataStore.fetchArtists();
|
||||
|
||||
// assert
|
||||
expect(musicDataStore.artists.toList(), []);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockFlutterAudioQuery extends Mock implements FlutterAudioQuery {}
|
||||
|
||||
class MockAlbumInfo extends Mock implements AlbumInfo {}
|
||||
|
||||
class MockSongInfo extends Mock implements SongInfo {}
|
||||
|
||||
void main() {
|
||||
LocalMusicFetcherImpl localMusicFetcher;
|
||||
MockFlutterAudioQuery mockFlutterAudioQuery;
|
||||
|
||||
setUp(() {
|
||||
mockFlutterAudioQuery = MockFlutterAudioQuery();
|
||||
localMusicFetcher = LocalMusicFetcherImpl(mockFlutterAudioQuery);
|
||||
});
|
||||
|
||||
group('getAlbums', () {
|
||||
MockAlbumInfo mockAlbumInfo;
|
||||
|
||||
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());
|
||||
when(mockAlbumInfo.lastYear).thenReturn(LAST_YEAR_1.toString());
|
||||
when(mockAlbumInfo.numberOfSongs).thenReturn(NUM_SONGS_1.toString());
|
||||
});
|
||||
|
||||
test(
|
||||
'should fetch list of albums from FlutterAudioQuery',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockFlutterAudioQuery.getAlbums())
|
||||
.thenAnswer((_) async => <AlbumInfo>[mockAlbumInfo]);
|
||||
// act
|
||||
await localMusicFetcher.getAlbums();
|
||||
// assert
|
||||
verify(mockFlutterAudioQuery.getAlbums());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should return albums as List<AlbumModel>',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockFlutterAudioQuery.getAlbums())
|
||||
.thenAnswer((_) async => <AlbumInfo>[mockAlbumInfo]);
|
||||
|
||||
final List<AlbumModel> expected = <AlbumModel>[
|
||||
AlbumModel.fromAlbumInfo(mockAlbumInfo),
|
||||
];
|
||||
// act
|
||||
final List<AlbumModel> result = await localMusicFetcher.getAlbums();
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('getSongs', () {
|
||||
MockSongInfo mockSongInfo;
|
||||
|
||||
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());
|
||||
when(mockSongInfo.albumArtwork).thenReturn(ALBUM_ART_PATH_3);
|
||||
});
|
||||
|
||||
test(
|
||||
'should fetch list of songs from FlutterAudioQuery',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockFlutterAudioQuery.getSongs())
|
||||
.thenAnswer((_) async => <SongInfo>[mockSongInfo]);
|
||||
// act
|
||||
await localMusicFetcher.getSongs();
|
||||
// assert
|
||||
verify(mockFlutterAudioQuery.getSongs());
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should return songs as List<SongModel>',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockFlutterAudioQuery.getSongs())
|
||||
.thenAnswer((_) async => <SongInfo>[mockSongInfo]);
|
||||
|
||||
final List<SongModel> expected = <SongModel>[
|
||||
SongModel.fromSongInfo(mockSongInfo),
|
||||
];
|
||||
// act
|
||||
final List<SongModel> result = await localMusicFetcher.getSongs();
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,67 +0,0 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:moor/ffi.dart';
|
||||
import 'package:mucke/system/datasources/moor_database.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
void main() {
|
||||
MoorDatabase moorMusicDataSource;
|
||||
AlbumModel albumModel;
|
||||
SongModel songModel;
|
||||
|
||||
setUp(() {
|
||||
moorMusicDataSource =
|
||||
MoorDatabase.withQueryExecutor(VmDatabase.memory());
|
||||
|
||||
albumModel = const AlbumModel(
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
songModel = const SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
);
|
||||
});
|
||||
|
||||
tearDown(() async {
|
||||
await moorMusicDataSource.close();
|
||||
});
|
||||
|
||||
group('insertAlbum and getAlbums', () {
|
||||
test(
|
||||
'should return the album that was inserted',
|
||||
() async {
|
||||
// act
|
||||
moorMusicDataSource.insertAlbum(albumModel);
|
||||
// assert
|
||||
final List<AlbumModel> albums = await moorMusicDataSource.getAlbums();
|
||||
expect(albums.first, albumModel);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('insertSong and getSongs', () {
|
||||
test(
|
||||
'should return the song that was inserted',
|
||||
() async {
|
||||
// act
|
||||
moorMusicDataSource.insertSong(songModel);
|
||||
// assert
|
||||
final List<SongModel> songs = await moorMusicDataSource.getSongs();
|
||||
expect(songs.first, songModel);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mucke/system/datasources/music_data_source_contract.dart';
|
||||
import 'package:mucke/system/audio/queue_generator.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockMusicDataSource extends Mock implements MusicDataSource {}
|
||||
|
||||
void main() {
|
||||
QueueGenerator queueManager;
|
||||
MusicDataSource musicDataSource;
|
||||
List<MediaItem> mediaItems;
|
||||
|
||||
group('generatePlusPermutation', () {
|
||||
|
||||
setUp(() {
|
||||
musicDataSource = MockMusicDataSource();
|
||||
queueManager = QueueGenerator(musicDataSource);
|
||||
});
|
||||
|
||||
test(
|
||||
'should exclude blocked songs',
|
||||
() async {
|
||||
// arrange
|
||||
|
||||
// act
|
||||
|
||||
// assert
|
||||
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,165 +0,0 @@
|
|||
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:mucke/domain/entities/album.dart';
|
||||
import 'package:mucke/system/datasources/moor_database.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockAlbumInfo extends Mock implements AlbumInfo {}
|
||||
|
||||
void main() {
|
||||
const tAlbumModel = AlbumModel(
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
test(
|
||||
'should be subclass of Album entity',
|
||||
() async {
|
||||
// assert
|
||||
expect(tAlbumModel, isA<Album>());
|
||||
},
|
||||
);
|
||||
|
||||
group('toAlbumsCompanion', () {
|
||||
test(
|
||||
'should return valid AlbumsCompanion',
|
||||
() async {
|
||||
// arrange
|
||||
const expected = AlbumsCompanion(
|
||||
artist: Value(ARTIST_1),
|
||||
title: Value(ALBUM_TITLE_1),
|
||||
albumArtPath: Value(ALBUM_ART_PATH_1),
|
||||
year: Value(YEAR_1),
|
||||
);
|
||||
|
||||
const albumModel = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = albumModel.toAlbumsCompanion();
|
||||
// assert
|
||||
expect(result.artist.value, expected.artist.value);
|
||||
expect(result.title.value, expected.title.value);
|
||||
expect(result.albumArtPath.value, expected.albumArtPath.value);
|
||||
expect(result.year.value, expected.year.value);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('fromMoorAlbum', () {
|
||||
test(
|
||||
'should create valid AlbumModel',
|
||||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
const expected = AlbumModel(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromMoor(moorAlbum);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should create valid AlbumModel without albumArtPath',
|
||||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
|
||||
const expected = AlbumModel(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
year: YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromMoor(moorAlbum);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should create valid AlbumModel without year',
|
||||
() async {
|
||||
// arrange
|
||||
final moorAlbum = MoorAlbum(
|
||||
id: ID_1,
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
);
|
||||
|
||||
const expected = AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromMoor(moorAlbum);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('fromAlbumInfo', () {
|
||||
MockAlbumInfo mockAlbumInfo;
|
||||
|
||||
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);
|
||||
when(mockAlbumInfo.firstYear).thenReturn(FIRST_YEAR_1.toString());
|
||||
when(mockAlbumInfo.lastYear).thenReturn(LAST_YEAR_1.toString());
|
||||
when(mockAlbumInfo.numberOfSongs).thenReturn(NUM_SONGS_1.toString());
|
||||
});
|
||||
|
||||
test(
|
||||
'should create AlbumModel from AlbumInfo',
|
||||
() async {
|
||||
// arrange
|
||||
const expected = AlbumModel(
|
||||
id: ID_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
artist: ARTIST_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: FIRST_YEAR_1,
|
||||
);
|
||||
// act
|
||||
final result = AlbumModel.fromAlbumInfo(mockAlbumInfo);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,311 +0,0 @@
|
|||
import 'package:audio_service/audio_service.dart';
|
||||
import 'package:flutter_audio_query/flutter_audio_query.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:moor/moor.dart';
|
||||
import 'package:mucke/domain/entities/song.dart';
|
||||
import 'package:mucke/system/datasources/moor_database.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockSongInfo extends Mock implements SongInfo {}
|
||||
|
||||
void main() {
|
||||
const tSongModel = SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
);
|
||||
|
||||
test(
|
||||
'should be subclass of Song entity',
|
||||
() async {
|
||||
// assert
|
||||
expect(tSongModel, isA<Song>());
|
||||
},
|
||||
);
|
||||
|
||||
group('toSongsCompanion', () {
|
||||
test(
|
||||
'should return valid SongsCompanion',
|
||||
() async {
|
||||
// arrange
|
||||
const expected = SongsCompanion(
|
||||
albumTitle: Value(ALBUM_TITLE_3),
|
||||
albumId: Value(ALBUM_ID_3),
|
||||
artist: Value(ARTIST_3),
|
||||
title: Value(SONG_TITLE_3),
|
||||
path: Value(PATH_3),
|
||||
duration: Value(DURATION_3),
|
||||
blocked: Value(BLOCKED_3),
|
||||
albumArtPath: Value(ALBUM_ART_PATH_3),
|
||||
trackNumber: Value(TRACKNUMBER_3),
|
||||
);
|
||||
|
||||
const songModel = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = songModel.toSongsCompanion();
|
||||
// assert
|
||||
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);
|
||||
expect(result.albumArtPath.value, expected.albumArtPath.value);
|
||||
expect(result.trackNumber.value, expected.trackNumber.value);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('toMediaItem', () {
|
||||
test(
|
||||
'should return valid MediaItem',
|
||||
() async {
|
||||
// arrange
|
||||
final expected = MediaItem(
|
||||
id: PATH_3,
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
artist: ARTIST_3,
|
||||
duration: const Duration(milliseconds: DURATION_3),
|
||||
artUri: 'file://$ALBUM_ART_PATH_3',
|
||||
extras: {
|
||||
'albumId': ALBUM_ID_3,
|
||||
'blocked': BLOCKED_3.toString(),
|
||||
'discNumber': null,
|
||||
'trackNumber': TRACKNUMBER_3,
|
||||
});
|
||||
|
||||
const songModel = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = songModel.toMediaItem();
|
||||
// assert
|
||||
expect(result.album, expected.album);
|
||||
expect(result.artist, expected.artist);
|
||||
expect(result.title, expected.title);
|
||||
expect(result.id, expected.id);
|
||||
expect(result.duration, expected.duration);
|
||||
expect(result.artUri, expected.artUri);
|
||||
expect(result.extras, expected.extras);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('fromMoorSong', () {
|
||||
test(
|
||||
'should create valid SongModel',
|
||||
() async {
|
||||
// arrange
|
||||
final moorSong = MoorSong(
|
||||
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,
|
||||
blocked: BLOCKED_3,
|
||||
);
|
||||
|
||||
const expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = SongModel.fromMoor(moorSong);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
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);
|
||||
when(mockSongInfo.filePath).thenReturn(PATH_3);
|
||||
when(mockSongInfo.duration).thenReturn(DURATION_3.toString());
|
||||
when(mockSongInfo.track).thenReturn(TRACKNUMBER_3.toString());
|
||||
});
|
||||
|
||||
test(
|
||||
'should create SongModel from SongInfo',
|
||||
() async {
|
||||
// arrange
|
||||
const expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: false,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
// act
|
||||
final result = SongModel.fromSongInfo(mockSongInfo);
|
||||
// assert
|
||||
expect(result, expected);
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('fromMediaItem', () {
|
||||
test(
|
||||
'should create valid SongModel from MediaItem',
|
||||
() async {
|
||||
// arrange
|
||||
const 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,
|
||||
'blocked': BLOCKED_3,
|
||||
},
|
||||
);
|
||||
|
||||
const expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_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 = const SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
);
|
||||
});
|
||||
|
||||
test(
|
||||
'should create SongModel with same values',
|
||||
() async {
|
||||
// arrange
|
||||
const expected = SongModel(
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_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
|
||||
const expected = SongModel(
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_3,
|
||||
title: SONG_TITLE_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_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);
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mucke/system/audio/audio_manager_contract.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
import 'package:mucke/system/repositories/audio_repository_impl.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockAudioManager extends Mock implements AudioManager {}
|
||||
|
||||
void main() {
|
||||
AudioRepositoryImpl repository;
|
||||
MockAudioManager mockAudioManager;
|
||||
|
||||
const int tIndex = 0;
|
||||
final List<SongModel> tSongList = setupSongList();
|
||||
|
||||
setUp(() {
|
||||
mockAudioManager = MockAudioManager();
|
||||
repository = AudioRepositoryImpl(mockAudioManager);
|
||||
});
|
||||
|
||||
group('playSong', () {
|
||||
test(
|
||||
'should forward index and song list to AudioManager',
|
||||
() async {
|
||||
// act
|
||||
await repository.playSong(tIndex, tSongList);
|
||||
// assert
|
||||
verify(mockAudioManager.playSong(tIndex, tSongList));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
List<SongModel> setupSongList() => [
|
||||
const SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
),
|
||||
const SongModel(
|
||||
title: SONG_TITLE_4,
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_4,
|
||||
path: PATH_4,
|
||||
duration: DURATION_4,
|
||||
blocked: BLOCKED_4,
|
||||
trackNumber: TRACKNUMBER_4,
|
||||
albumArtPath: ALBUM_ART_PATH_4,
|
||||
),
|
||||
];
|
|
@ -1,145 +0,0 @@
|
|||
import 'package:dartz/dartz.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mockito/mockito.dart';
|
||||
import 'package:mucke/system/datasources/local_music_fetcher_contract.dart';
|
||||
import 'package:mucke/system/datasources/music_data_source_contract.dart';
|
||||
import 'package:mucke/system/models/album_model.dart';
|
||||
import 'package:mucke/system/models/song_model.dart';
|
||||
import 'package:mucke/system/repositories/music_data_repository_impl.dart';
|
||||
|
||||
import '../../test_constants.dart';
|
||||
|
||||
class MockLocalMusicFetcher extends Mock implements LocalMusicFetcher {}
|
||||
|
||||
class MockMusicDataSource extends Mock implements MusicDataSource {}
|
||||
|
||||
void main() {
|
||||
MusicDataRepositoryImpl repository;
|
||||
MockLocalMusicFetcher mockLocalMusicFetcher;
|
||||
MockMusicDataSource mockMusicDataSource;
|
||||
|
||||
List<AlbumModel> tAlbumList;
|
||||
List<AlbumModel> tEmptyAlbumList;
|
||||
|
||||
List<SongModel> tSongList;
|
||||
List<SongModel> tEmptySongList;
|
||||
|
||||
setUp(() {
|
||||
mockLocalMusicFetcher = MockLocalMusicFetcher();
|
||||
mockMusicDataSource = MockMusicDataSource();
|
||||
|
||||
repository = MusicDataRepositoryImpl(
|
||||
localMusicFetcher: mockLocalMusicFetcher,
|
||||
musicDataSource: mockMusicDataSource,
|
||||
);
|
||||
|
||||
tAlbumList = setupAlbumList();
|
||||
tEmptyAlbumList = [];
|
||||
|
||||
tSongList = setupSongList();
|
||||
tEmptySongList = [];
|
||||
});
|
||||
|
||||
group('getAlbums', () {
|
||||
test(
|
||||
'should get albums from MusicDataSource',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataSource.getAlbums())
|
||||
.thenAnswer((_) async => tAlbumList);
|
||||
// act
|
||||
final result = await repository.getAlbums();
|
||||
// assert
|
||||
verify(mockMusicDataSource.getAlbums());
|
||||
expect(result, Right(tAlbumList));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should return empty list when MusicDataSource does not return albums',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataSource.getAlbums())
|
||||
.thenAnswer((_) async => tEmptyAlbumList);
|
||||
// act
|
||||
final result = await repository.getAlbums();
|
||||
// assert
|
||||
verify(mockMusicDataSource.getAlbums());
|
||||
expect(result, Right(tEmptyAlbumList));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('getSongs', () {
|
||||
test(
|
||||
'should get songs from MusicDataSource',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataSource.getSongs()).thenAnswer((_) async => tSongList);
|
||||
// act
|
||||
final result = await repository.getSongs();
|
||||
// assert
|
||||
verify(mockMusicDataSource.getSongs());
|
||||
expect(result, Right(tSongList));
|
||||
},
|
||||
);
|
||||
|
||||
test(
|
||||
'should get songs from MusicDataSource',
|
||||
() async {
|
||||
// arrange
|
||||
when(mockMusicDataSource.getSongs())
|
||||
.thenAnswer((_) async => tEmptySongList);
|
||||
// act
|
||||
final result = await repository.getSongs();
|
||||
// assert
|
||||
verify(mockMusicDataSource.getSongs());
|
||||
expect(result, Right(tEmptySongList));
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
group('updateDatabase', () {
|
||||
// TODO: testing
|
||||
});
|
||||
}
|
||||
|
||||
List<AlbumModel> setupAlbumList() => [
|
||||
const AlbumModel(
|
||||
artist: ARTIST_1,
|
||||
title: ALBUM_TITLE_1,
|
||||
albumArtPath: ALBUM_ART_PATH_1,
|
||||
year: YEAR_1,
|
||||
),
|
||||
const AlbumModel(
|
||||
artist: ARTIST_2,
|
||||
title: ALBUM_TITLE_2,
|
||||
albumArtPath: ALBUM_ART_PATH_2,
|
||||
year: YEAR_2,
|
||||
),
|
||||
];
|
||||
|
||||
List<SongModel> setupSongList() => [
|
||||
const SongModel(
|
||||
title: SONG_TITLE_3,
|
||||
album: ALBUM_TITLE_3,
|
||||
albumId: ALBUM_ID_3,
|
||||
artist: ARTIST_3,
|
||||
path: PATH_3,
|
||||
duration: DURATION_3,
|
||||
blocked: BLOCKED_3,
|
||||
trackNumber: TRACKNUMBER_3,
|
||||
albumArtPath: ALBUM_ART_PATH_3,
|
||||
),
|
||||
const SongModel(
|
||||
title: SONG_TITLE_4,
|
||||
album: ALBUM_TITLE_4,
|
||||
albumId: ALBUM_ID_4,
|
||||
artist: ARTIST_4,
|
||||
path: PATH_4,
|
||||
duration: DURATION_4,
|
||||
blocked: BLOCKED_4,
|
||||
trackNumber: TRACKNUMBER_4,
|
||||
albumArtPath: ALBUM_ART_PATH_4,
|
||||
),
|
||||
];
|
Loading…
Add table
Reference in a new issue