Skip to content

Commit

Permalink
Add a test for the select/deselect all functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Abestanis committed Jul 14, 2024
1 parent 2e89bf8 commit ee89fe0
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/routes/selection_route_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -262,4 +262,73 @@ void main() {
});
});
});

group('common selection actions on all tabs', () {
final album0 = albumWith(id: 0);
final album1 = albumWith(id: 1);
final album2 = albumWith(id: 2);
final artist0 = artistWith(id: 0);
final artist1 = artistWith(id: 1);
final artist2 = artistWith(id: 2);
final song0 = songWith(id: 0, title: 'Song 0', albumId: album0.id, artistId: artist0.id);
final song1 = songWith(id: 1, title: 'Song 1', albumId: album1.id, artistId: artist1.id);
final song2 = songWith(id: 2, title: 'Song 2', albumId: album2.id, artistId: artist2.id);
final playlist0 = playlistWith(id: 0, songIds: [song0.id]);
final playlist1 = playlistWith(id: 1, songIds: [song1.id]);
final playlist2 = playlistWith(id: 2, songIds: [song2.id]);

for (var tabAndContentType in [
('tracks', ContentType.song),
('album', ContentType.album),
('playlists', ContentType.playlist),
('artists', ContentType.artist),
]) {
var tabName = tabAndContentType.$1;
var contentType = tabAndContentType.$2;
testWidgets('allows selecting all and deselecting all on the $tabName tab', (WidgetTester tester) async {
await setUpAppTest(() {
FakeSweyerPluginPlatform.instance.songs = [song0, song1, song2];
FakeSweyerPluginPlatform.instance.albums = [album0, album1, album2];
FakeSweyerPluginPlatform.instance.playlists = [playlist0, playlist1, playlist2];
FakeSweyerPluginPlatform.instance.artists = [artist0, artist1, artist2];
});
await tester.runAppTest(() async {
// Select tab
if (contentType != ContentType.song) {
await tester.tap(find.byIcon(contentType.icon).first);
await tester.pumpAndSettle();
}

// Select first content
await tester.longPress(find.byType(ContentTile).first);
await tester.pumpAndSettle();

var selectionController = ContentControl.instance.selectionNotifier.value!;
expect(selectionController.inSelection, true);
expect(selectionController.data.length, 1);
expect(find.descendant(of: find.byType(SelectionCounter), matching: find.text('1')).hitTestable(),
findsOneWidget);

// Select all
await tester.tap(find.byType(SelectAllSelectionAction).last);
await tester.pumpAndSettle();

int numElements = ContentControl.instance.getContent(contentType).length;
expect(selectionController.inSelection, true);
expect(selectionController.data.length, numElements);
expect(find.descendant(of: find.byType(SelectionCounter), matching: find.text('$numElements')).hitTestable(),
findsOneWidget);

// Deselect all
await tester.tap(find.byType(SelectAllSelectionAction).last);
await tester.pumpAndSettle();

expect(selectionController.inSelection, false);
expect(selectionController.data.length, 0);
expect(find.byType(SelectAllSelectionAction).hitTestable(), findsNothing);
expect(find.byType(SelectionCounter).hitTestable(), findsNothing);
});
});
}
});
}

0 comments on commit ee89fe0

Please sign in to comment.