Skip to content

Commit

Permalink
Add unit test album list filter screen
Browse files Browse the repository at this point in the history
  • Loading branch information
up2code committed May 8, 2024
1 parent 76f2c3c commit 89043d3
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AlbumsFilterScreen extends StatelessWidget {
return ListView(
children: [
DropdownAlbumType(
value: state.discTypes ?? '',
value: state.discTypes ?? 'Unknown',
onChanged: (value) =>
onAlbumTypesChanged?.call(value) ??
ref
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:vocadb_app/src/features/albums/presentation/albums_list/albums_list_filter_screen.dart';
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_sort.dart';
import 'package:vocadb_app/src/features/albums/presentation/widgets/dropdown_album_type.dart';

class AlbumsListFilterScreenRobot {
final WidgetTester tester;

AlbumsListFilterScreenRobot(this.tester);

Future<void> pumpAlbumsListFilterScreen({
Function(String?)? onAlbumsTypesChanged,
Function(String?)? onSortChanged,
}) async {
await tester.pumpWidget(
ProviderScope(
child: MaterialApp(
home: AlbumsFilterScreen(
onAlbumTypesChanged: onAlbumsTypesChanged,
onSortChanged: onSortChanged,
),
),
),
);
}

Future<void> selectAlbumTypes(String value) async {
final albumTypeDropdownBtnFinder =
find.byKey(DropdownAlbumType.dropdownKey);
expect(albumTypeDropdownBtnFinder, findsOneWidget);

await tester.tap(albumTypeDropdownBtnFinder);
await tester.pump();

final selectedFinder = find.text(value).last;
expect(selectedFinder, findsOneWidget);
await tester.tap(selectedFinder);
await tester.pump();
}

Future<void> selectSort(String value) async {
final albumSortDropdownBtnFinder =
find.byKey(DropdownAlbumSort.dropdownKey);
expect(albumSortDropdownBtnFinder, findsOneWidget);

await tester.tap(albumSortDropdownBtnFinder);
await tester.pump();

final selectedFinder = find.text(value).last;
expect(selectedFinder, findsOneWidget);
await tester.tap(selectedFinder);
await tester.pump();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import 'package:flutter_test/flutter_test.dart';

import 'albums_list_filter_screen_robot.dart';

void main() {
group('albums filter screen', () {
testWidgets('change album type', (tester) async {
String? selectedValue;
final r = AlbumsListFilterScreenRobot(tester);

await r.pumpAlbumsListFilterScreen(
onAlbumsTypesChanged: (value) => selectedValue = value,
);

await r.selectAlbumTypes('E.P.');
expect(selectedValue, 'EP');
});

testWidgets('change album sort', (tester) async {
String? selectedValue;
final r = AlbumsListFilterScreenRobot(tester);

await r.pumpAlbumsListFilterScreen(
onAlbumsTypesChanged: (value) => selectedValue = value,
);

await r.selectSort('Addition date');
expect(selectedValue, 'AdditionDate');
});
});
}

0 comments on commit 89043d3

Please sign in to comment.