release_schedule/test/view/movie_list_test.dart

69 lines
1.8 KiB
Dart
Raw Normal View History

2023-11-16 15:07:33 +01:00
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:release_schedule/model/dates.dart';
2023-11-16 15:07:33 +01:00
import 'package:release_schedule/model/movie.dart';
import 'package:release_schedule/view/movie_item.dart';
import 'package:release_schedule/view/movie_list.dart';
void main() {
group('MovieList', () {
testWidgets('should render a list of movies', (WidgetTester tester) async {
final movies = [
MovieData(
'The Shawshank Redemption',
DateWithPrecisionAndCountry(
DateTime(1994, 9, 22), DatePrecision.day, 'US'),
),
MovieData(
'The Godfather',
DateWithPrecisionAndCountry(
DateTime(1972, 3, 24), DatePrecision.day, 'US'),
),
];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieList(movies),
),
),
);
await tester.pumpAndSettle();
2023-11-16 15:07:33 +01:00
expect(find.byType(MovieItem), findsNWidgets(movies.length));
});
testWidgets("should filter the list of movies",
(WidgetTester tester) async {
final movies = [
MovieData(
'The Shawshank Redemption',
DateWithPrecisionAndCountry(
DateTime(1994, 9, 22), DatePrecision.day, 'US'),
),
MovieData(
'The Godfather',
DateWithPrecisionAndCountry(
DateTime(1972, 3, 24), DatePrecision.day, 'US'),
),
];
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: MovieList(
movies,
filter: (movie) => movie.title.contains('Godfather'),
),
),
),
);
await tester.pumpAndSettle();
expect(find.byType(MovieItem), findsOneWidget);
});
2023-11-16 15:07:33 +01:00
});
}