unit test for MusicDataStore
This commit is contained in:
parent
c6149363d8
commit
6c8ff844f3
2 changed files with 45 additions and 0 deletions
|
@ -58,6 +58,7 @@ abstract class _MusicDataStore with Store {
|
|||
isUpdatingDatabase = true;
|
||||
await _musicDataRepository.updateDatabase();
|
||||
await Future.wait([
|
||||
fetchArtists(),
|
||||
fetchAlbums(),
|
||||
fetchSongs(),
|
||||
]);
|
||||
|
|
|
@ -79,6 +79,50 @@ void main() {
|
|||
);
|
||||
});
|
||||
|
||||
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 = [
|
||||
|
|
Loading…
Add table
Reference in a new issue