From ee89fe0d62a55e1f1ad595db313895964cad44fe Mon Sep 17 00:00:00 2001 From: Abestanis Date: Sun, 14 Jul 2024 20:35:59 +0200 Subject: [PATCH] Add a test for the select/deselect all functionality --- test/routes/selection_route_test.dart | 69 +++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/test/routes/selection_route_test.dart b/test/routes/selection_route_test.dart index e7cf74505..6d03445de 100644 --- a/test/routes/selection_route_test.dart +++ b/test/routes/selection_route_test.dart @@ -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); + }); + }); + } + }); }