2023-11-16 15:07:33 +01:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
2024-01-09 16:32:53 +01:00
|
|
|
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', () {
|
2024-01-10 23:50:43 +01:00
|
|
|
late List<MovieData> movies;
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
movies = [
|
|
|
|
MovieData()
|
|
|
|
..setNewDetails(
|
|
|
|
labels: [(text: 'The Shawshank Redemption', language: 'en')],
|
|
|
|
releaseDates: [
|
|
|
|
DateWithPrecisionAndCountry(
|
|
|
|
DateTime(1994, 9, 22), DatePrecision.day, 'US')
|
|
|
|
],
|
|
|
|
),
|
|
|
|
MovieData()
|
|
|
|
..setNewDetails(
|
|
|
|
labels: [(text: 'The Godfather', language: 'en')],
|
|
|
|
releaseDates: [
|
|
|
|
DateWithPrecisionAndCountry(
|
|
|
|
DateTime(1972, 3, 24), DatePrecision.day, 'US')
|
|
|
|
],
|
|
|
|
)
|
2023-11-16 15:07:33 +01:00
|
|
|
];
|
2024-01-10 23:50:43 +01:00
|
|
|
});
|
2023-11-16 15:07:33 +01:00
|
|
|
|
2024-01-10 23:50:43 +01:00
|
|
|
testWidgets('should render a list of movies', (WidgetTester tester) async {
|
2023-11-16 15:07:33 +01:00
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MovieList(movies),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
2024-01-09 16:32:53 +01:00
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
2023-11-16 15:07:33 +01:00
|
|
|
expect(find.byType(MovieItem), findsNWidgets(movies.length));
|
|
|
|
});
|
2024-01-09 21:52:32 +01:00
|
|
|
|
|
|
|
testWidgets("should filter the list of movies",
|
|
|
|
(WidgetTester tester) async {
|
|
|
|
await tester.pumpWidget(
|
|
|
|
MaterialApp(
|
|
|
|
home: Scaffold(
|
|
|
|
body: MovieList(
|
|
|
|
movies,
|
2024-01-10 23:50:43 +01:00
|
|
|
filter: (movie) => movie.title?.contains('Godfather') == true,
|
2024-01-09 21:52:32 +01:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
|
|
|
|
expect(find.byType(MovieItem), findsOneWidget);
|
|
|
|
});
|
2023-11-16 15:07:33 +01:00
|
|
|
});
|
|
|
|
}
|